24 Channel LED control with PWM, TLC5947 SPI

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

User avatar
Jay Dee
Posts: 356
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 136 times
Contact:

24 Channel LED control with PWM, TLC5947 SPI

Postby Jay Dee » Sat Dec 24, 2011 3:58 pm

Bit of a Christmas information donation. :-)
I was looking at an easy way to PWM control lots of LEDs, I have tried a few of the chips in Texas TLC range and settled on the TLC5947. Under £3 from Farnell.

Stuff I Like.
> Uses SPI ( so I can use it on the same bus as the CAN board)
> Minimal commands and setup required to get the chip working (using the Flowcode SPI macro).
> 24 outputs @ 30mA max ( not a huge current but hey cant have everything )
> Pull to ground outputs (Current Sink)
> LED supply voltages can be up to 30V.
> Best Bit!! An Internal Oscillator deals with the clocking out of the GreyScale (PWM) data to the Outputs. Basically, the chip will continuously hold the outputs at whatever PWM you set then at. With other chips in the TLC series you had to constantly clock the 'GreyScale' data out and trigger for each cycle. But with the TLC5947 and its Internal Oscillator your program is not tied up with any of this and can go off and run other parts of your program. You only need to deal with the Chip each time you want to change the PWM settings of the outputs. Beautiful!
> Easy to cascade multiple TLC5947 chips.
> PWM control of 24 channels is ideal when using arrays of 8 RGB LEDs

Stuff that is a Pain.
> No 'Chip Select' pin, however the Chip can still be used on a multi device SPI bus.
> The chip is a HTSSOP package, i.e. you have to solder the heat slug (in the base of the chip package) to your board, I found it a bit tricky but not impossible. If you have trouble with this, on my dev board I simply drilled through the board (beforehand!) and soldered from the other side of the board to pick up the heatslug. Bit of a bodge but it works.
> Package is a surface mount, with 0.65mm pitch legs. But you can buy breakout boards for this package/pitch from Farnell.
> You need to ensure proper heat sinking when running all 24 outputs near max current and moderate voltage levels.

Other Chips in the TLC range offer higher drive currents but lower number of outputs and require a more complex sequence of control commands, it is not much harder but its just a load more to setup and so your flowcode will become more complex. I've had them working but preffer the simplicity of the TLC5947 and love the fact it has an internal oscillator.

Each channel's PWM level is set by a 12 bit value.
So for all 24 channels; 24 x 12 bits = 288 bits.

Basic Sequence

Enable SPI Macro
Pull 'Blank' pin High. This stops rubbish being output to the LEDs until you have got the right values in the outputs Latch Register.
Use the SPI Macro 36 times ( since it will only send out blocks of 8 bits) and Clock out 36 bytes of data. ( 36 x 8 = 288 bits )
Toggle the XLAT pin (Hi-Lo)to move the data from the TLC's Shift Register to its Latch Register.
Pull the 'Blank' pin low to enable the outputs, the chip will now PWM all of the outputs at the required settings.
To change any of the output PWM levels, simply send the next set of 288 bits when ever you want and toggle the XLAT pin.

NOTE: I like to keep my variables as Bytes where possible and for most applications I only need 256 PWM levels, rather than the full 4096 available with the TLC chips. As such my flow code attached uses a byte array 'Ch_PWM[24]' to hold 24 individual 8 bit values for setting the PWM levels. The 'TLCsend' macro takes this 8 bit data and effectively stuffs 4 zeros on the end of each value transmitted, thus making them 12 bits in length.
It does make the 'TLCsend' macro a bit more complex but the rest of the program can be dead simple as each channels PWM can be set by a single byte.

NOTE: The TLC5947 does not have a Chip Select or Enable pin, thus is will see all data clocked onto the SPI bus, for example SPI data to/from the CAN board. However this is not a problem since it will only act on the 288 bits of data preceding the XLAT pin going high.

NOTE: when toggling pins Hi-Lo (i.e. the Blank and XLAT pins), you should not need a delay between the commands, thus it is happening as fast as the PIC can execute the code. I have measured the pulse on my system and it exceeds the minimum as required by the TLC chips. But if you experience problems keep the 1 uS delay in between the state changes.
TLC5947_SPI_Test_Routine.fcf
(14.07 KiB) Downloaded 435 times


As I said, working with the small chip size can be a pain but the functionality of the chip is great. Possible E-block candidate? ;-)
Have fun,
John.
These users thanked the author Jay Dee for the post (total 3):
DavidA (Thu Dec 29, 2011 11:35 am) • Mathy (Tue Jan 28, 2014 10:17 am) • medelec35 (Tue Jan 28, 2014 2:04 pm)
Rating: 15.79%
 

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: 24 Channel LED control with PWM, TLC5947 SPI

Postby Mathy » Tue Jan 28, 2014 10:20 am

Hello,
This chip is very interesting !!
Your post too, thank you for the tuto and the example.

I need 5 of these chip and so I need to use the daisy chain function.
Do you know how it works to send value to the 5 chips ?
I am not familiar with this kind of chip.

Thank you for your help :)