Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

programming a byte on one pin

Status
Not open for further replies.
This is totally untested but should head you in the right way It's just a start ok.


Code:
Device = 18F2420
Clock = 8
Config MCLRE = Off

Include "shift.bas"
Include "utils.bas"
Include "convert.bas"

Dim SDI As PORTB.1
Dim CLK As PORTB.2
Dim OE As PORTB.3
Dim LE as portb.4

Dim DataPin As SDI  
Dim ClockPin As CLK
Dim ResetPin As OE 
Dim index as byte 
dim X as byte


const data(8)as Byte =(%00000001, %00000010, %000000100 ,%00001000, %00010000, %00100000, %01000000,%00111110)

sub StartScan()
    LE = 0
    ResetPin = 1
    Shift.Out(LSB_FIRST, X, 8)
    ResetPin = 0
    LE = 1
end sub
Shift.SetOutput(DataPin)
Shift.SetClock(ClockPin)
output(ResetPin)
output(LE)
    
 For index = 0 to bound (data)
      X = (data(index))
      StartScan
 Next
 
 End
 
Last edited:
It is kind of a head banging ordeal. Cant figure it out lot's of great help but don't look like it sinks in.

After all the Idea here was to make a turn signal for a bike that runs on battery But the part count goes up

Your going to need a small engine with a generator to keep the battery's charged.

Oh forget the engine over kill just ride the bike and let the tire turn the generator.
 
Last edited:
Have gremlins or ?

BEFORE I wired the TLC5916 into my matrix circuit I wired up a test circuit using the schematic on the app note SLVA346.
It wored as hoped.
THEN I wired the TLC5916 onto my matrix board. Using this code it worked to a point. I had a colume w/5 rows on, then it blinked and two colums w/ 5 rows on, blink then 3 colums w/ 5 rows on etc.
I then proceeded to try the suggestion of SPI then SHIFT.bas.
After rewriting code as per Swordfish Reference Manual I am back to square one.
Decided to retrace my steps and use the PIC to clock the TLC5916 as per the app note. Now I have a roadblock as to WHY it does not tuirn on any leds.
Re checking and found a couple of issues that I have resolved. Have yet to get back to it.
BUT I might have the solution why it does not work at this point, the clock I have set for clocking the TLC5916 may be too slow??
After rechecking my connections I plan to investigate this.
Here is the code that used the TLC5916 but it was not enabling the correct LEDs. I was/am hoping to find out why all of a sudden the circuit quit working then I can progress. I might add that when this code was working the LEDs were blindly bright with 25 leds lit up all equal brightness. My test matrix circuit only has 5 rows and 5 colums connected at present.
Hopefully this clears up why I am trying to test w/ a 555 again. It worked before so it should work again. If not then process of elimination.
Welcome back Pommie.
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 10/26/2012                                                     *
*  Version : 1.0                                                            *
*  Notes   : needs better definition of when pulse train is received                                                               *
*          :                                                                *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Config MCLRE = Off


'*********************************************************************
'Includes
//Include "InternalOscillator.bas"

Include "utils.bas"
Include "convert.bas"
Dim led1 As PORTC.6    // data
Dim led2 As PORTC.7
dim  Latch_E as portb.0
dim Out_E as  portc.3
dim row1 as portb.3

Dim x As Byte
const data(5) as byte = (%00000001,%00000011,%00000100,%00001000,%00000000  )

// set ports as outputs
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000       


SetAllDigital
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//wait until sig = 1 to exicute more code
 

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//needs better definition of when pulse train is received
// using a very slow 555 to experiment with
// a frequency counter would be better?
//----------------------------------------------------------


While 1=1     
   For x = 0 To 7  // time to get sample  // get 100us seconds sample
       
       PORTC.bits(7) = data(x)    // clock  8 pulses clk up
       out_E = 1            // yellow led
       
       latch_e = 0
       PORTC.bits(6) =  1    // sdi in
       DelayMS(100)
       PORTC.bits(7) = 0    //clock dwn
       delayms(100)
      Next
       latch_e = 1
       
       out_E = 0
       PORTC.bits(6) =  0
       row1 = 1 
     delayms(1000)
     row1=0
   Wend
 
The don't have to be fast all it takes is
bit clock bit clock
if you have the LE an OE pins wrong you'll get no display

And the code you posted is to do what ?
 
Last edited:
MrDEB, I say this as somebody who has and can make chips like this work. You should look at this as the best advice you will get.

You need to strip everything out of the program except the code needed to turn on one output at a time. This is absolutely essential to using this chip. Once you understand how to control this chip, you can build from there. There is that word again. Understand. You need make the chip work first. Output(0) on. Output(1) on. Output(3) on. All the way to output(7). Then, just to be certain you understand what you're doing, turn on output(0) and then output(0) and output(1) and then output(0) and output(1) and output(2) and so on.

Only when you understand how to control the chip can you build on this for your application.

The trouble with the code you keep recycling here (a fancy way to say copy&paste(tm)) is that you don't have a clue what it's doing. I can't follow what it's doing. But you think it " sort of works" because random LEDs come on.

When you have a chip like this, you have to proceed one step at a time, and the first step is mastering the chip. Sure, you found an app note for using a 555 to turn on ALL of the outputs AT THE SAME TIME. That has absolutely nothing to do with your application. Please focus on controlling the chip to do what you need it to do. Maybe if you do that, you'll have something working before flying bicycles come out.

My comments may sound harsh, but what you're doing (still) doesn't work, so maybe it's time for a new approach. Let me rephrase that. It IS time for a new approach. In case you haven't noticed, you have burnt out almost everyone who is willing to help you. Add my name to the list. When you have working code to do what I've outlined above, written by yourself, maybe I'll be back. No demonstrated understanding of the chip, no more help from me.
 
These chips are not that hard to use It's all in the data sheet. Mrdeb said he maybe clocking to fast he turning the chip off to fast

If you read page 4 of the datasheet by default if you clocking data the chip is in the off state your code is holding the chip in the off state.


This chip is not any harder to drive then a 595 shift register and The code I posted will load the chip with data.

And Jon is right you don't understand how this chip works the 555 is just a way to use the chip by it's self.

That will not let you scan this chip with the pins you want on.
 
MrDeb are you using a crystal on intosc if not using a crystal your code will not run my code was using a crystal

Here it scanning 8 leds just for testing and dang it worked out the box.
[video=youtube_share;SYAY99gPQSU]http://youtu.be/SYAY99gPQSU[/video]
 
It that with the current sink chip Burt?

You are right that it's pretty easy to use. It's not like some of the I2C chips where you have to write to a bunch of registers before anything works.
 
Nop its a shift register
The Chip MrDeb is using is almost the same as a 74HC595 The code I posted will scan it He could use it too with just the clock and data and pull the EN LN up and down with a resistor
 
Last edited:
Oh, yeah, it should work almost exactly the same.

If MrDEB will start with just getting the chip to work, he has a chance.
 
Well if he started with this code
Code:
Device = 18F2420
Clock =8
Config OSC = INTIO67
Include "intio8.bas"
Include "shift.bas"
Include "utils.bas"
Include "convert.bas"

Dim SDI As PORTB.0
Dim CLK As PORTB.1
Dim OE As PORTB.3
Dim LE As PORTB.4

Dim DataPin As SDI  
Dim ClockPin As CLK
Dim ResetPin As OE 
Dim index As Byte 
Dim X As Byte


Const data(8)As Byte =(%10000001, %010000010 ,%00100100, %00011000, %00011000, %00100100, %01000010, %10000001)

Sub StartScan()
    LE = 0
    ResetPin = 1
    Shift.Out(MSB_FIRST, X, 8)
    ResetPin = 0
    LE = 1
End Sub
Shift.SetOutput(DataPin)
Shift.SetClock(ClockPin)
ADCON1 = $07 
Output(ResetPin)
Output (LE)
While true     
 For index = 0 To Bound (data)
      DelayMS(40)
      X = (data(index))
      StartScan
      DelayMS(40)
 Next
 Wend
 End
And add his row data he would be good to go but this is as much as I'm doing
You need to change the const data it's set to do the night rider.
But it would be good to try it as is to get the chip working with it and just a row to start.
Then go for the gold.
 
Last edited:
At this point I am trying to find out when I get back to it why the chip is not working. I have only one output on at the present. I found I inadverently inserted a jumper in the wrong port (easy mistake)
I moved the project board and jumpers got disconnected. Will hopefully get it up and running sometime this weekend.
I am at this point doing all that Jon pointed put. I think I mentioned that the 555 was just testing the matrix and driver/ sink sections.
 
MrDeb you never said what OSC your using and did you even try that code I posted.

AND
I am at this point doing all that Jon pointed put. I think I mentioned that the 555 was just testing the matrix and driver/ sink sections.

That will not work on a 5X7 matrix it's for a single row of leds one led one pin. Like I show you in the video.

Here the code with comments
Code:
Device = 18F2520      // Tells whitch  chip im using
Clock =8             // tell the complier to base on a 8 Mhz clock for delays.
Config OSC = INTIO67   // sets OSC it onboard  oscillator
Include "intio8.bas"   // set's the osscon to 8 Mhz
Include "shift.bas"    //modules use 
Include "utils.bas"
Include "convert.bas"

Dim SDI As PORTB.0
Dim CLK As PORTB.1
Dim OE As PORTB.3
Dim LE As PORTB.4

Dim DataPin As SDI     
Dim ClockPin As CLK
Dim index As Byte 
Dim X As Byte

 // data to shift out \\\
Const data(8)As Byte =(%10000001, %010000010 ,%00100100, %00011000, %00011000, %00100100, %01000010, %10000001)

Sub StartScan()
    OE = 1      // OE is high loading data
    LE = 0      //  Is low while loading data
    Shift.Out(MSB_FIRST, X, 8) //Loads shift register 
    LE = 1     // goes high to latch data
    delayus(10)
    LE = 0
    OE = 0    // OE goes low to sink power
End Sub
Shift.SetOutput(DataPin)   // pins for dats in the shift.bas
Shift.SetClock(ClockPin)    // sets clock in the shift.bas
ADCON1 = $07     // turns off ADC
Output(OE)       //sets pin to output
Output (LE)      //same as above
While true       //Loop that's forever as long as it's true
 For index = 0 To Bound (data)   //Picks byte to load
      DelayMS(40)         //  to see it happen
      X = (data(index))   //  This Loads byte into X
      StartScan     // This sends X to the TLC5916
      DelayMS(40)       // to see it happen
 Next        //Loop the const array data runs all bytes
 Wend
 End

If you go by the drawing to test place ground side of led "cathode" on the TLC5916 OUT0 to OUT7 pins

And hook the Anode to positive side of your supply.

And run the code see how that part works and add the part to set the high side of the led using your pic chip
View attachment 68549
 
Last edited:
You've stated a couple times that you're using a TAP-28 board for testing. I guess this is to curry favor for more of my help.

However, the schematic you posted suggests although you have some connections to a TAP-28 board, you're not really making very good use of it. The I2C/SPI connect has power, ground, SDI, SDO, CLK and one other port pin available. This is the logical place to connect the current sink chip. Use SDI & CLK as intended, and use the other two port pins for LE and /OE. in this way, the software or hardware shift and SPI routines are available.

For controlling the high-side driver chip, you show port pins C4, C5, D6, C7 & E0 I believe (you still haven't mastered the art of creating a ledgible schematic). This chip would be far easier to control with a contiguous group of port pins. Perhaps D6 and E0 are typos, since a 28 pin PIC doesn't make these port pins available.

Since you have plenty of port pins available, I would strongly recommend that you not disable /MCLR. This can create problems including chips that can't be re-programmed. Same comment regarding using a crystal vs the internal oscillator. You've fallen into the trap of setup problems enough times that you should think twice about this.

Finally, if you use any of the port pins used for the switches or LEDs to run the high-side driver chip, remove the solder jumpers from the TAP-28 board to prevent problems. The drawing below shows the TAP-28 connections.
 
Last edited:
I used the 18F4520 pic but I failed to reconfigure the port numeration. I took your suggestion and go with the shift.bas instead of the spi.bas.
Reason I do not utilize the I2c/ SPI port connect is I am utilizing jumper wires. Good point on the jumpers as I have seen some erratic behavior from the LEDs. Only reason I kept them connected was for CLK indication as well as SDI but no real need.
I am hoping to go with a smaller pin count pic. I am using the external oscillator set up I just didn't include it or some Vcc or GRD connections. Will reconfigure the port connections if it is beneficial as far as utilizing the SHIFT.bas.
Am I to understand that the I2C / SPI port connection is a better choice as far as the pic is concerned (SHIFT.bas would be easier to implement using this port connection?)
 
So the schematic does not reflect what you're doing? Have you learned absolutely nothing in your thousands of posts? If you expect people to help you any further, you need to post accurate information. This includes schematics and code and everything else. Post what you are using at this exact moment.

The shift module lets you define port pins, so it doesn't much matter where you connect it. If you might want to use hardware SPI for some reason, using the proper pins is required. So why not just connect it in the best possible way to leave that option rather than in some random order that limits possibilities?

A few posts ago, I outlined what you need to do to use the constant current chip. This would be the best starting point and in fact the only starting point if I'm going to have any additional input. Your "sort of working" because an LED flashes once in a while proves nothing.
 
Excuse me if I am not perfect
Am using an 8 pin sil male plug for the outputs to the high side driver. Reason why I am using jumpers for the SDI etc. Plus I do not have a 6 pin female plug to use the I2c / SPI port.
The code that "kinda works" that apparently you can't understand just turns on one colum of 5 LEDs then blinks off then two colums of 5 come on this continuse until all 5 colums have 5 leds on.
I started a new code from scratch as you suggested just to try and figure out what and how this chip operates. Using the timing diagram as a reference but have little success to date BUT I am continuing on trying to configure a working code. NO COPY N PASTE
One of the main reasons I am using a Tap -28 is I can connect the Junebug and Pickit2 to utilize the UART feature but the Junebug seems to be having issues.
My next approach may be connect several LEDs to the TLC5916 and not use the high side driver, just to simplify matters.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top