Re: TLC5940 Arduino Lib

438 views
Skip to first unread message

Alex Leone

unread,
Dec 11, 2014, 6:47:50 PM12/11/14
to Patrick Gunderson, tlc5940arduino
+cc: tlc5940arduino mailing list.

Off the top of my head, I don't know of any beaglebone libraries specifically for the tlc5940.  I did see this post, http://derekmolloy.ie/driving-led-arrays-using-the-tlc5940/ but I don't see any code on that page.

Here's roughly what I would do to port the library:

- PWM output for BLANK, set at 1000Hz, duty cycle as small as possible, eg 0.01%.  The outputs are off while BLANK is high, so you want the BLANK pulse to be as small as possible.
- PWM output for GSCLK, set at 1000*4906 = 4.096MHz, duty cycle set at 50%.
- use SPI pins to shift data in with SIN/SCLK.  If it's a pain to use SPI pins, you can use any GPIO pins but it will be slower to shift data out.
- use a GPIO to pulse XLAT after shifting data out.

More technical details:

The tlc5940 is essentially a 16 output PWM chip.  To set each output, you shift data in with SIN/SCLK, and latch with XLAT, as if the chip was a big shift register.  Each output value is 12 bits, so a value of 0 - 4095, which determines the output's duty cycle. For example, 1024 means the output is on 25% of the time, 2048 means the output is on 50% of the time, etc.  You shift in all 16 output values, so 192 bits total, and then latch with XLAT.

The tlc5940 doesn't have an internal oscillator, so the PWM frequency is set with GSCLK and BLANK.  For example, if you want to update the output values 1000 times a second, then pulse BLANK every 1 millisecond.  The 4096 output values correspond to each pulse of GSCLK between the blanks, so GSCLK should be pulsed 4096 times between each BLANK pulse.

Note that if you pulse XLAT in the middle of a PWM period, then the new output values will take effect immediately, which can lead to flicker.  To get around this, the Arduino library actually uses another PWM output for XLAT, and turns on that output after shifting data in for exactly one pulse, so that the XLAT is within the BLANK pulse, and the output values get switched at the end of the PWM period.  This is what the tlc5940 datasheet recommends (they have pictures, a bit easier to understand than all this text!).

Hopefully this helps!

 - Alex



On Thu, Dec 11, 2014 at 10:34 AM, Patrick Gunderson <pat...@toolofna.com> wrote:
Hey alex. Thanks for writing and putting this arduino lib out there for the TLC5940. To your knowledge does anything similar exist for beaglebone?

I’ve been reading through the lib with the notion of porting it, but there are some low level things going on that I don’t really understand.
PATRICK GUNDERSON
 

Reply all
Reply to author
Forward
0 new messages