Flaky Atmega328p + 6xTLC5940 setup

Hi all,

I've done a lot of searching and researching (ha, puns) regarding my problem and hope that the community can help me and point out what I'm doing wrong/stupidly. :slight_smile:

I'm using, as the subject says, 6 TLC5940s daisy chained from a stand-alone atmega328p (with arduino bootloader and using the arduino IDE/TLC5940 library). When I run the BasicUse sketch, all seems good, but I find if I turn on more than a few LEDs simultaneously the setup does one of: lock-up, get flakey (twitchy, reset like behaviour) or starts flashing LEDs very rapidly.

Some notes on my setup:

  • Circuit is faithfully based on: http://tlc5940arduino.googlecode.com/svn/wiki/images/breadboard-arduino-tlc5940.png

  • The atmega328p has a 20Mhz crystal on it and additions from the multiple TLC5940 diagram in "Demystifying the TLC5940" - not the pinouts, but the additional components (diodes, resistors, capacitors and the aforementioned crystal).

  • I was afraid that my amp draw might be too much and am currently (ha, another pun) using an ATX power supply (20A max at 5V) rather than the 1200mA @ 5V switching supply I used originally - no change.

  • If I do Tlc.setAll(4095) (or even 1024 for that matter) the LEDs all turn on and flicker rapidly until the whole thing goes dark.

I did a quick and dirty random lighting sketch along these lines:

#include "Tlc5940.h"

void setup()
{
  Tlc.init();
  randomSeed(analogRead(0));
}

void loop()
{
  Tlc.clear();
  for (int i=0; i<32; i++)
  {
    Tlc.set(random(0,95),random(2047,4095));
  }
  Tlc.update();
  delay(500);
}

...the setup will work at first, but generally drifts into unstable land as described above.

Other things I've thought about and need guidance on:

  • Looking at tlc_config.h, I have set the NUM_TLCS to 6 but I'm concerned about TLC_PWM_PERIOD (default 8192) and TLC_GSCLK_PERIOD (default 3) as they seem to be set for a microcontroller clock of 16Mhz. Should I change this? Could this be part of my issue? More often than not, when things get flaky, I see the results coming from the latter TLC5940s in the chain.

  • I'm using and arduino uno to program the atmega328p using this shield: Standalone AVR ISP Programmer Shield Kit - includes blank chip! : ID 462 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits ...and setting the board as an arduino uno, should I be setting it to something different (as I'm using a stand alone chip at 20MHz)? For details on the settings, see: http://www.smacula.co.uk/2011/10/adjusting-tlc5940-libraries-to-run.html

  • I read one posting that talked about putting a capacitor across GSCLK/SCLK to cut down on noise, but that strikes me a little odd, no?

  • The length of wire from the board to the LEDs is about 18" right now - but that doesn't seem too long to me, based on reading what other people have done (read: many feet long).

Any thoughts or guidance would be appreciated, I'm building a disco dance floor for my wife's 40th birthday party (this Saturday) and while I could hook up something that regularly resets the boards, I'd rather do things right.

Thanks in advance.

My guess is that the LEDs are either sucking away all your power causing a temporary board reset OR dumping that much power into GND is temporarily raising GND causing the TLC chips to read bad values on the IO lines. See effluvia of a scattered mind: TLC5940, TLC5941 and Arduino. You need a bunch of various sized caps to do "decoupling" in a big way. Try 1000uF, 100uF and a ceramic at a couple of uF (I didn't really bother to figure out whether all of these are needed...)

20mhz chips is not an issue; the TLCs can handle clocks up to 30mhz and the fastest a 20mhz chip can clock an IO line is < 10mhz.

Cheers!
Andrew

The decoupling caps you need are 0.1uF ceramic. On each chip as close to the power supply pins as possible. The best is to solder a surface mount cap directly across the two pins.
A photo of your setup would help define other problems of layout or construction.

My direct experience with the 5941 chip is that the datasheet recommended .1uF is not enough. I believe it has to do with fluctuations in the shared GND when the chip turns on its 80mA LEDs and so suddenly dumps a lot of power on the GND plane. But this is mostly guesswork because my scope is limited to 100Mhz.

Hey guys, thanks for the replies - responses in-line.

Grumpy_Mike:
The decoupling caps you need are 0.1uF ceramic. On each chip as close to the power supply pins as possible. The best is to solder a surface mount cap directly across the two pins.
A photo of your setup would help define other problems of layout or construction.

I do have those, actually. As per this diagram.

NB: I'm using the pin-outs from atmega, as per the examples in with the arduino TLC5940 library.

AndrewStone:
My direct experience with the 5941 chip is that the datasheet recommended .1uF is not enough. I believe it has to do with fluctuations in the shared GND when the chip turns on its 80mA LEDs and so suddenly dumps a lot of power on the GND plane. But this is mostly guesswork because my scope is limited to 100Mhz.

I'm only drawing 18mA per channel - I'm using a 2.2K ohm IREF resistor - or are you talking of an aggregate load? Do you think I still need beefier caps?

Here's a picture of a board, without all the wiring yet, beyond the ground/vcc wiring.

I added 100uF caps in parallel with the existing caps - and the boards work flawlessly now.

Grumpy_Mike gets another notch in his "it's always a decoupling problem" belt and AndrewStone gets props for the 100uF suggestion. :slight_smile: