Problem with multiple tlc5940

Hi. For starter, I´m a real n00b reg arduino. I´m using two tlc5940 units for 30 LEDs... I want them to sort of "glow" individually in different duration. It works fine, but as soon as I add more than 11 LEDs in the code, the LEDs from 12> are first delayed, and then the whole "stripe" get messed up. They are sort of ramdomly switching between fading very smooth and not fading at all. I´ve connected everything exactly like this scheme: arduino - TLC 5940 PWM driver blank input and pull-up resistor - Electrical Engineering Stack Exchange

Is there something wrong with my code? Can you help me out here?

Note: The code below is for 16 LEDs, not the hole stripe of 30.

#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

void setup()
{
  Tlc.init();
}

void loop()
{
  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
    
     if (!tlc_isFading(0)){
      uint16_t duration = 4900 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(0, 50, maxValue, startMillis, endMillis );
      tlc_addFade(0, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(1)){
      uint16_t duration = 4700 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(1, 50, maxValue, startMillis, endMillis );
      tlc_addFade(1, maxValue, 50, endMillis, endMillis + duration);}
      
      if (!tlc_isFading(2)){
      uint16_t duration = 4800 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(2, 50, maxValue, startMillis, endMillis );
      tlc_addFade(2, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(3)){
      uint16_t duration = 4500 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(3, 50, maxValue, startMillis, endMillis );
      tlc_addFade(3, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(4)){
      uint16_t duration = 4100 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(4, 50, maxValue, startMillis, endMillis );
      tlc_addFade(4, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(5)){
      uint16_t duration = 4200 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(5, 50, maxValue, startMillis, endMillis );
      tlc_addFade(5, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(6)){
      uint16_t duration = 4300 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(6, 50, maxValue, startMillis, endMillis );
      tlc_addFade(6, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(7)){
      uint16_t duration = 4400 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(7, 50, maxValue, startMillis, endMillis );
      tlc_addFade(7, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(8)){
      uint16_t duration = 4600 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(8, 50, maxValue, startMillis, endMillis );
      tlc_addFade(8, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(9)){
      uint16_t duration = 5000 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(9, 50, maxValue, startMillis, endMillis );
      tlc_addFade(9, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(10)){
      uint16_t duration = 5100 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(10, 50, maxValue, startMillis, endMillis );
      tlc_addFade(10, maxValue, 50, endMillis, endMillis + duration);}
      
      
      
      
      
      
      
      
      if (!tlc_isFading(11)){
      uint16_t duration = 4700 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(11, 50, maxValue, startMillis, endMillis );
      tlc_addFade(11, maxValue, 50, endMillis, endMillis + duration);}
      
      if (!tlc_isFading(12)){
      uint16_t duration = 4800 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(12, 50, maxValue, startMillis, endMillis );
      tlc_addFade(12, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(13)){
      uint16_t duration = 4500 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(13, 50, maxValue, startMillis, endMillis );
      tlc_addFade(13, maxValue, 50, endMillis, endMillis + duration);}
      
      
       if (!tlc_isFading(14)){
      uint16_t duration = 4700 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(14, 50, maxValue, startMillis, endMillis );
      tlc_addFade(14, maxValue, 50, endMillis, endMillis + duration);}
      
      if (!tlc_isFading(15)){
      uint16_t duration = 4800 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(15, 50, maxValue, startMillis, endMillis );
      tlc_addFade(15, maxValue, 50, endMillis, endMillis + duration);}
      
       if (!tlc_isFading(16)){
      uint16_t duration = 4500 - (analogRead(0) * 2);
      int maxValue = 1000;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(16, 50, maxValue, startMillis, endMillis );
      tlc_addFade(16, maxValue, 50, endMillis, endMillis + duration);}
      
      
   
      
      
      
    
    
    
    if (channel++ == NUM_TLCS * 16) {
      channel = 0;
    }
  }
  tlc_updateFades();
}

There are no decoupling capacitors in that schematic. Add. 0.1uF ceramic capacitor across the power and ground of each chip.

thanks! going to try that

The capacitors doesnt seem to do the trick... Any other ideas?? I put the capacitors next to the tlc5940's vcc and gnd on breadboard. Also, when I try the examples>tlc5940>fades, the flow is bad, not smooth at all.

Make sure the capacitor leads are as short as possible. Make sure the wiring is as short and neat as possible. Try adding one largish cap about 47uF to the supply as well.
Basically the circuit does work but it can be layout sensitive.

I really tried to keep the wiring as short and neat as possible.

This is how it looks like.

And here´s another one, same problem on this one.

You are sure there´s not a software issue?

You are sure there´s not a software issue?

I was sort of assuming that you get the same problem on the sample code do you not?

Shorten the leads on the decoupling caps, they need to be as short as possible, you should see no wire.

I was having a problem with the 5940s, then added some 104 caps, and continued to have similar problems. I decided to re-send the sketch, and it worked fine. I dont quite understand how that fixed it, but it only took a minute to do, and since then, the problem has not re-occurred.

Grumpy_Mike:

You are sure there´s not a software issue?

I was sort of assuming that you get the same problem on the sample code do you not?

Shorten the leads on the decoupling caps, they need to be as short as possible, you should see no wire.

I'd add some more capacitors on the +5V lines near the LEDs, too. 30 LEDs switching on simultaneously at the start of every PWM cycle is a big change in current for the PSU to adapt to. I'm fond of 1uF polyesters for this - they respond a bit faster than standard electrolytics and they're not too big to add a few of them around the circuit.

Grumpy_Mike:

Yeah, I was just thinking if I might had done something wrong when editing the config file for two tlc5940's. But I´m going to try shortening those wires.

Hippynerd:

With "re-send the sketch" you mean upload I guess?

fungus:

You say "on the +5V lines near the LEDs"... Where is that exactly? Sorry, I´m a total n00b...

quizz_kid:
fungus:

You say "on the +5V lines near the LEDs"... Where is that exactly? Sorry, I´m a total n00b...

Between ground and 5V, near the LEDs (again, the +5V wires need to be as short as possible...)

Try one on either end of that row of LEDs. The idea is to try to stop the +5V line from sagging when those LEDs all switch on at the start of the PWM cycle (which can freak out the logic chips).

Like this?

Btw, here's a video of how it looks. Notice the flickering and blinking after that somewhat struggled start. Also know that the code I used for this is for 22 LEDs, but only 19 of them are switched on. So it stops at 19. Why is that?

And here´s with a 11 LEDs code. Works smoothe and nice.

quizz_kid:
Like this?

That's the general idea. I can't see what the other leg of the capacitor is connected to though (it should be GND...)

Well it doesn´t seem to work... Any other ideas?

quizz_kid:
Well it doesn´t seem to work... Any other ideas?

Maybe the "tlc_fades" demo doesn't work with multiple chips. Did you look in the header file to see if there's anything that might need adjusting?

quizz_kid:
Like this?

No between the +5V line and ground. This looks like you have it across the LEDs. Also you should be using large electrolytics here, like 47uF not 0.1uF ceramics.

Fungus, that´s not the fade demo running, it´s the code from the first post in this thread, but with a few more LEDs added.

Grumpy, sorry I´m such a noob, I´m not sure where the 5v lines are located. Maye you can point them out using this pic

The 5V line is the common line to all the LEDs. The ground line is the ground on the TLC chip.

quizz_kid:
Fungus, that´s not the fade demo running, it´s the code from the first post in this thread, but with a few more LEDs added.

It looks an awful lot like the fades demo to me (or at least, a version that somebody hacked without knowing what they were doing).

Ok, I bought some 47uF´s... Put them between 5v and gnd, but I guess I´ve put them wrong(picture below), because that didn´t change anything.

Uploaded with ImageShack.us

Help please