28X2 and TLC5940 shift register - I have been beaten

handyandy

New Member
Hello All - well after a week i still have not been able to get my picaxe talking to a 5940 shift register.

I have seen other posting for other Shift registers but none of the code seams to work on the 5940.


My long term goal is to build an RGB LED cube starting with a 4x4x4. And the 5940 seamed to me to be a good choice (may be not) as it can control the brightness of individual LED with a GS register.

I have the 8 outputs connected to led on the SR pins 1 to 7

I have a resistor 2K on the Iref to ground which should control the current to the LED to 20ma

SIN on the SR connected to pin C.7
SCLK on the SR connected to pin C.0
XLAT on the SR connected to pin C.1
Blank on the Sr connected to pin C.2
VCC to 5V
IREF to GND via 2K Res
GND on SR to GND

and thats it

First thing have i connected the pins correctly and have i connected enough of them?

As for the code i am not sure what i am doing i have used many from this forumn but have not managed to get any of the LED to light

what i would like to be able to do is just to control which of the 10 leds would turn on or a combination of them


I have several books Picaxe projects for the evil genius and one by David Lincoln, but i still cant get my head around the correct connection or code.

I have seen plenty aboout the 74xx595 but could not convert that code



I have seen this code posetd and a friend has said that i should find a way to use it something to do with scratchpad memory ( still searching all about that)
I think this is a way to shift out the binary number head in memory to active the LEDs connect to pins 0 to 7 say of pins 1 to 8 ( well 8 of them)

dsp:
ptr=1
hserout c.7,($F2) '$F2 a command 242 not sure what this is about
for b0=1 to 8
hserout c.7,(@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc) '@ptrinc to do with scratch pad
next b0
return


I feel like throughing my development board out of the window at the moment.

If somebody is able to point me in the right direction that would be great, as its raining out side and i would hate to get my development board wet.

I have two other 5940 which i would like to dasiy chain up once i have learned to walk with this one

Thanks for now

Andy
 
Last edited:

gbrusseau

Senior Member
Handyandy, I have built several LED projects with the TLC5940. Don't have time right now to look over you connections and code. Will get back to you soon.
 

gbrusseau

Senior Member
At first glance, you have the SIN pin (serial input) on the LTC5940 (SR) going to the hserin pin (serial input) on the PICAXE 28X2. The SR SIN pin should go to the hserout C.6 (serial out) on the 28X2. Needs to be output to input. Not input to input. Before using the HSERIN or HSEROUT commands, you first need to set up the serial port on the 28X2 with the HSERSETUP command. None of this is useful in this case however because the SR has a SPI type input port that requires data and timed clocking of the data into the SR.

You should use the HSPISETUP command to configure the 28X2 SPI ports and the HSPIOUT command to shift data out to the SR. the 28X2 pins are used as follows:
hspi sdo pin (C.5) = serial out data connected to the SR pin26 SIN
hspi sck pin (C.3) = serial out clock connected to the SR pin25 SCLK
You also need to ground the SR pin27 VPRG and pin19 DCPRG.
Also need to provide timed GSCLK and BLANK signals to the SR so the SR can control LED brightness. Without the GSCLK and BLANK the SR will not function. There are 4096 GSCLK pulses for every BLANK pulse.

This may all sound a little daunting at first, but it really isn't. Out of time again. Will get back to you with some sample code and how to easily provide the GSCLK and BLANK signals. I have attached a very useful .pdf flow chart for the SR you should review.
 

Attachments

Last edited:

westaust55

Moderator
Welcome to the PICAXE forum.

You should not be using the HSEROUT command to control the TLC5940 chips.
The Hardware SEROUT command is for RS-232 like serial communications and involves a start bit 8 data bits, no parity and a stop bit, so 10 bits transmitted per data byte.

The TLC5940 only expects 8 data bits to be sent which are synchronise with the clock pulses sent from the PICAXE chip.
You need the Hardware SPI (serial peripheral Interface) comms and may do well to consider the simpler and slower SHIFTOUT command to first get the control sorted and then progress to the HSPISETUP and HSPIOUT commands.
The simpler command allow you to define the data, clock pins and it is easy enough to define any other pins needed for handshaking and send pulses where/if necessary.
 

handyandy

New Member
Hi gentlemen

Thanks for the very quick replies and the welcome. The flow chart look great and helps to explain where i have been going wrong. I will print it off when i get home and see if i can get things talking to one another.

Gbrusseau if you are able to post any code, that would be most helpful
 

gbrusseau

Senior Member
I agree westaust55, the simpler SHIFTOUT command is a better choice to get thing working first.

The TLC5940 controls 16 LEDs and each LED can be dimmed independently in 4096 steps. That means each LEDs register is 12 bits wide (from 0 to 4095). Doing the math, thats 16LEDs x 12bits = 192 bits (24 8bit bytes) to load up all the LED registers. Once all the data has been shifted into the 16 registers, you need to pulse the SRs XLAT signal. The XLAT pulse, parallel loads the data into the SRs output registers, and the LEDs light up to the brightness that corresponds to the value in each LED 12bit register.

Don't forget to ground the SRs pin27 VPRG, and pin19 DCPRG and make sure you are using common anode LEDs and all the common anode pins on all of the LEDs are connected to the same + voltage rail. The voltage on the common anode pins of the LEDs can be as high as +17 volts, but don't get confused. The PICAXEs and the TLC5940s +5 volt Vcc supply voltage is seperate from the LED common anode voltage. For simplicity whoever, there is no reason you can't use the same +5 volt power supply for the PICAXE and TLC5940 Vcc and for the LED common anode + voltage.

I order for the SR to function, you need a GSCLK and BLANK signal generator for the SR. First you will need a PICAXE 08M2, an 8 pin MPU, though any PICAXE running at 32mhz will do. I chose the 08M2 because its cheap and a tiny 8 pin IC chip and will run at 32mhz.
Port 1 on the 08M2 is BLANK
Port 2 on the 08M2 is GSCLK

What follows is the code for the PICAXE 08M2:

'******************************************************
'* PICAXE 08M2 - TLC5940 Program *
'* Generates the GSCLK and BLANK *
'******************************************************
'* A free running oscillator for the TLC5940 *
'* grayscale clock - GSCLK *
'* and blank - BLANK *
'* *
'* Every 4096 GSCLK pulses (about every 4ms) *
'* BLANK is pulsed to reset the TLC5940 *
'* grayscale counter. *
'* Note:GSCLK doesn't need to be exactly 4096 pulses *
'* between BLANK pulses. *
'******************************************************
high 1 'Set BLANK high at startup
setfreq M32 'Set PICAXE 8M2 to 32mhz
low 2 'Set GSCLK low at startup

OSC: 'Start free running GSCLK oscillator
pwmout 2,off
high 1
pauseus 250 'BLANK pulse width
low 1
pwmout 2,6,10
pauseus 2540 'Time period between BLANK pulses
goto OSC
 
Last edited:

handyandy

New Member
Thanks again for the input. I have no chip 08M2 but a 28x2 how would i connect that. from the above is there only two wires between the pic and the SR?
 

gbrusseau

Senior Member
According to the PICAXE manual 2 "Basic Commands", you can use ports B.0, B.5, C.1, or C.2 with the PWMOUT command on the PICAXE 28X2 chip.. Maybe using the C.2 port for the GSCLK (PWMOUT) and C.1 for the BLANK. Using only 2 pins from this second 28X2 is a major overkill, but will get you working until you can order a couple PICAXE 08M2 chips. The second 28X2 GSCLK generator chip will have just 2 wires used.
C.1 pin wired to SRs BLANK pin
C.2 pin wired to SRs GSCLK pin

The SR likes to have the XLAT pin pulsed during a BLANK pulse. This prevents a possible quick single flicker of the LEDs when the SR output registers are parallel loaded with the XLAT pulse. For now however, don't worry about that. Later on you will want to wire the second 28X2 chips C.1 BLANK pin to an unused input pin on the main 28X2 chip. When the main 28X2 chip is ready to pulse XLAT, the program should test this input pin for the BLANK signal a then issue the XLAT pulse. The BLANK pulse is wide enough to fit the XLAT pulse within the BLANK pulse width. While the BLANK signal is active high, the LEDs are turned off and the SR LED output pins are in an open high impedance state.

*****PICAXE 28X2 code*****
high C.1
setfreq EM32
low C.2

OSC:
pwmout C.2,off
high C.1
pauseus 250
low C.1
pwmout C.2,6,10
pauseus 2540
goto OSC
 
Last edited:

gbrusseau

Senior Member
Here it is 8:00AM on the west coast of the US and I'm bored. Even though I provided handyman with a flow chart for programming and controling the SR, I thought he might like to know a little about the internal workings of the SR because the SR isn't really an SR.

First the TLC5940 serially shifts in 192 bits into the serial in/serial out shift register. That’s 16 LEDs times each LEDs 12 bit data register = 192 bits. With the XLAT pin pulsed, the data is parallel loaded into a second 192 bit wide register for buffering and safe keeping, because now you can start shifting in another 192 bits while the second register holds the first 192 bits. Then there’s a third 192 bit wide counter/comparator register. Its counted up with each GSCLK pulse then compares the value of the second register to itself. When there’s a match, the TLC turns off the corresponding LED and it stays off until the third register is reset with the BLANK pulse. After each BLANK pulse the TLC turns on all the LEDs and waits for the comparators to tell it to turn each of the corresponding the LED off. Then the process starts all over again. The end results is that the TLC provides a pwm output to the LEDs who’s pulse width is determined by how long it takes the third register to count up and match the second register and the duration is based on the time between BLANK pulses. I’ve been told that the TLC makes a good 16 channel servo controller.

You can stop reading if you want to now because I’m going to very briefly touch on the error registers and the internal EPROM registers. Most people don’t care about all that stuff. I suspect the TLC has an internal MPU that controls this part of the TLC. You can read error registers and tell if an LED is shorted or burned out and which one it is. I don’t know about you, but when I’m buying hundreds of LEDs, I buy the cheapest I can find and that means not all of them are going to the same. With small LED arrays, you won’t really notice that some of the LEDs are brighter than others, but with large arrays you will. When the TLC is in program mode you can adjust the brightness of each LED so that they’re all the same brightness . Then store that information in the onboard EPROM. Each time the TLC is powered up, it loads that info someplace into someplace near the preset condition of the counter/comparator registers or something like that. Thus each LED is adjust for brightness at power up. This can be useful for centering servos maybe. Handyman, I hope this helps when writing code for the TLC.
 
Last edited:

handyandy

New Member
still stuck

I think I will have to draw a circuit diagram of what I have connected and what I am trying to do. I have missed something along the way. Still thanks for the support do far. I will draw it out and up load as jpeg file. On mobile connection now hence short reply.
 

gbrusseau

Senior Member
With the second 28X2 GSCLK/BLANK generator chip, you must have an external 3 pin resonator component connected to the 28X2 or the SETFREQ EM32 command won't work. When you bought the 28X2 it may have included the 3 pin resonator. Remember, you must use common anode type LEDs.

Answer yourself this question. Why would the LEDs flicker with the XLAT pulse if you don't pulse the XLAT pin during a BLANK pulse period? If you can answer that, your well on your way to becoming a TLC expert. By the time you reach your goal, you will be a PICAXE and TLC expert.
 
Last edited:
Top