Go Down

Topic: Problem with multiple tlc5940 (Read 9481 times) previous topic - next topic

quizz_kid

Nearest that i can tell, about a million ways. seriously there are a lot of ways to control leds.


I understand that, but I´d need a simple and cheap solution... Any specific ideas?



Grumpy, by device you mean chip or LED? And which code are you talking about, something in the library? And whitch one is the input wire?

Once again you have to excuse my lack of knowledge in this field.

quizz_kid

Ok, I checked both chips separately. They have the same issues, same as before, which is this:

When I use my fading code for 11 LEDs, everything works fine

When I change the code to a 12-13 LED setup, the first 11 starts simultaneously, while the 12 and 13 starts with a 1 sec delay.

As I then add more LEDs to the code, some LEDs starts to flicker, individually, and it seems sort of randomly.

Grumpy_Mike

Quote
As I then add more LEDs to the code,

Post what gives you trouble.

Hippynerd


Nearest that i can tell, about a million ways. seriously there are a lot of ways to control leds.


I understand that, but I´d need a simple and cheap solution... Any specific ideas?



Grumpy, by device you mean chip or LED? And which code are you talking about, something in the library? And whitch one is the input wire?

Once again you have to excuse my lack of knowledge in this field.


At this point, fixing what you have is probably the quickest easiest solution.

If you had kept it simple just using multiplexing or  charlieplexing, you would have something working by now, but that may not be as nice as you would have liked. I just checked, and you have been at this since the end of november!
https://sites.google.com/site/rgbledcubes

quizz_kid

Grumpy, here is when they start to flicker some, with 14 LEDs:
Code: [Select]
#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 = 4000 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(0, 28, maxValue, startMillis, endMillis );
     tlc_addFade(0, maxValue, 28, endMillis, endMillis + duration);}
   
    if (!tlc_isFading(1)){
     uint16_t duration = 4200 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(1, 28, maxValue, startMillis, endMillis );
     tlc_addFade(1, maxValue, 28, endMillis, endMillis + duration);}
   
    if (!tlc_isFading(2)){
     uint16_t duration = 4400 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(2, 28, maxValue, startMillis, endMillis );
     tlc_addFade(2, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(3)){
     uint16_t duration = 4600 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(3, 28, maxValue, startMillis, endMillis );
     tlc_addFade(3, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(4)){
     uint16_t duration = 4800 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(4, 28, maxValue, startMillis, endMillis );
     tlc_addFade(4, maxValue, 28, endMillis, endMillis + duration);}
 
    if (!tlc_isFading(5)){
     uint16_t duration = 5000 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(5, 28, maxValue, startMillis, endMillis );
     tlc_addFade(5, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(6)){
     uint16_t duration = 3000 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(6, 28, maxValue, startMillis, endMillis );
     tlc_addFade(6, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(7)){
     uint16_t duration = 3200 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(7, 28, maxValue, startMillis, endMillis );
     tlc_addFade(7, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(8)){
     uint16_t duration = 3400 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(8, 28, maxValue, startMillis, endMillis );
     tlc_addFade(8, maxValue, 28, endMillis, endMillis + duration);}
   
    if (!tlc_isFading(9)){
     uint16_t duration = 3600 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(9, 28, maxValue, startMillis, endMillis );
     tlc_addFade(9, maxValue, 28, endMillis, endMillis + duration);}
   
    if (!tlc_isFading(10)){
     uint16_t duration = 3800 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(10, 28, maxValue, startMillis, endMillis );
     tlc_addFade(10, maxValue, 28, endMillis, endMillis + duration);}
     
    if (!tlc_isFading(11)){
     uint16_t duration = 5200 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(11, 28, maxValue, startMillis, endMillis );
     tlc_addFade(11, maxValue, 28, endMillis, endMillis + duration);}
     
      if (!tlc_isFading(12)){
     uint16_t duration = 3350 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(12, 28, maxValue, startMillis, endMillis );
     tlc_addFade(12, maxValue, 28, endMillis, endMillis + duration);}
     
      if (!tlc_isFading(13)){
     uint16_t duration = 3750 - (analogRead(0) * 2);
     int maxValue = 400;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(13, 28, maxValue, startMillis, endMillis );
     tlc_addFade(13, maxValue, 28, endMillis, endMillis + duration);}
     
       
   
   
   if (channel++ == NUM_TLCS * 16) {
     channel = 0;
   }
 }
 tlc_updateFades();
}


Hippynerd:

Yeah, but quick and easy doesn´t seem to be the right words in this situation =(

Hippynerd

Assuming that things will do what you want once you over come this one hurdle, it seems like a huge waste of time to not see it through, and it looks like you are close to getting it going.

I dont really know enough about what and how and where this is being used to give any specific advice, but in general when things are complicated and beyond control, you need to simplify things until you get things in order.

You could control 30 LEDs with multiplexing or charliplexing, but it will come at some cost, usually speed and brightness, which may or may not be a problem. It will also mean more complex wiring, but less complex circuitry.

If you have a second set of LEDs, you could experiment with multiplexing while you are working this out.

I understand that you must be frustrated, I have a cube that is very similar, and its been put on the back burner because its been difficult. I will return to it again, after I finish some documentation.
https://sites.google.com/site/rgbledcubes

quizz_kid

Yes, it´s all very frustrating indeed. It´s nice to hear I´m getting closer though, because I can´t really see any improvements here, exept the exclusions so far.

The idea is to have 30 LEDs "breathing"(fading) smoothly in different durations. Kind of like the organic diode pulse effect you´ll get when you turn on you Macbook. I´m going to use it for some different projects later, that´s IF I can get to work of course.

But I´m up for trying other alternatives, and I´ve got another set of LEDs for experimenting. Never done any multiplexing though, so I´d need some help there I guess.

Thanks for helping me out here, also good luck with your own frustrating project.

Grumpy_Mike

Thanks for posting the code.
Can you post a link to the tlc_fades.h libary you used because I can find lots of them on line and I don't know which one you used.

The code is very wrong in many places. The problem is that a lot of the things that are wrong with it are obscuring seeing what the problem in what you see is.
When you declare a variable, that is put a variable type followed by the variable name the computer creates a variable of that name. So you have this line
Code: [Select]
int maxValue = 400;
many times in the loop. Each one creates a new instance of the variable with the same name and it would seem the same value.
You do this with many variables thought the code.
You do the same with
Code: [Select]
uint32_t startMillis = millis();
but what is worst you want this variable to persist through many loops.

So just one section of the code:-
Code: [Select]
if (!tlc_isFading(13)){
      uint16_t duration = 3750 - (analogRead(0) * 2);
      int maxValue = 400;
      uint32_t startMillis = millis();
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(13, 28, maxValue, startMillis, endMillis );
      tlc_addFade(13, maxValue, 28, endMillis, endMillis + duration);}


could be rewritten:-
Code: [Select]
if (!tlc_isFading(13)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(13, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(13, 400, 28, endMillis, endMillis + duration);}

with
Code: [Select]
analogValue = analogRead(0);
done at the start of the loop and analogValue defined outside of any function to make it a global variable.

While that might not solve your problem you need to clean up the code at least so far before you can have a chance of writing it correctly.
So make those changes, see what you get and post the resulting code and say what it does.

Hippynerd

Heres an arduino tutorial that pretty well explains multiplexing, charlieplexing is the same thing, only it adds complexity, so learn multiplexing first, then charlieplexing if you want to know more.

http://arduino.cc/en/Tutorial/RowColumnScanning

The above example uses an 8x8 matrix, but since you are using sinle LEDs you can make the matrix whatever size you like, 5x6 will do 30 LEDs and require only 11 microcontroller pins and you will also want 5 or 6 resistors. 

The other thing you will need to understand is called PWM, Pulse Width Modulation. its how you make the LEDs "breath" (Im assuming you mean increase and decrease in brightness). The arduino has several PWM pins that you can use, or software PWM to do this, the TLC chip, has this built in, so its nice for your uses.

Heres a tutorial on PWM and fading:
http://arduino.cc/en/Tutorial/Fading
https://sites.google.com/site/rgbledcubes

quizz_kid


could be rewritten:-
Code: [Select]
if (!tlc_isFading(13)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(13, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(13, 400, 28, endMillis, endMillis + duration);}

with
Code: [Select]
analogValue = analogRead(0);
done at the start of the loop and analogValue defined outside of any function to make it a global variable.


I get some error messages, so where exactly do I put the analogValue = analogRead(0); into the 4-LED code below for example?

Code: [Select]
#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(1)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(1, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(1, 400, 28, endMillis, endMillis + duration);}
     
      if (!tlc_isFading(2)){
      duration = 2500 - (analogValue * 2);
      tlc_addFade(2, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(2, 400, 28, endMillis, endMillis + duration);}
     
      if (!tlc_isFading(3)){
      duration = 3400 - (analogValue * 2);
      tlc_addFade(3, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(3, 400, 28, endMillis, endMillis + duration);}
     
      if (!tlc_isFading(4)){
      duration = 3000 - (analogValue * 2);
      tlc_addFade(4, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(4, 400, 28, endMillis, endMillis + duration);}
     
     
       
   
   
    if (channel++ == NUM_TLCS * 16) {
      channel = 0;
    }
  }
  tlc_updateFades();
}




Hippynerd, I´m going to look into that, thanks

Grumpy_Mike

#40
Feb 24, 2013, 05:30 pm Last Edit: Feb 24, 2013, 05:34 pm by Grumpy_Mike Reason: 1
Code: [Select]
#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;
int analogValue;
int duration;
int maxValue = 400;

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

void loop() {
analogValue = analogRead(0);

 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
     
    if (!tlc_isFading(1)){
     duration = 3750 - (analogValue * 2);
     tlc_addFade(1, 28, maxValue, millis(), millis()+ duration );
     tlc_addFade(1, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
     if (!tlc_isFading(2)){
     duration = 2500 - (analogValue * 2);
     tlc_addFade(2, 28, maxValue, millis(), millis()+ duration );
     tlc_addFade(2, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
     if (!tlc_isFading(3)){
     duration = 3400 - (analogValue * 2);
     tlc_addFade(3, 28, maxValue, millis(), millis()+ duration );
     tlc_addFade(3, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
     if (!tlc_isFading(4)){
     duration = 3000 - (analogValue * 2);
     tlc_addFade(4, 28, maxValue, millis(), millis()+ duration );
     tlc_addFade(4, 400, 28, millis()+ duration, millis()+ duration + duration);}
   
   if (channel++ == NUM_TLCS * 16) {
     channel = 0;
   }
 }
 tlc_updateFades();
}


Still waiting for the library link I asked about.

Quote
Hippynerd, I´m going to look into that, thanks

You want fading, charlyplexing is very poor for getting fading, it consumes a lot of the processing power.

quizz_kid

Oh, and here´s the library I used:

http://code.google.com/p/tlc5940arduino/downloads/detail?name=Tlc5940_r014_2.zip

quizz_kid

Ok, the cleaned up code have the same issues. No changes

Code: [Select]
#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;
int analogValue;
int duration;
int maxValue = 400;

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

void loop() {
analogValue = analogRead(0);

  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
       
     if (!tlc_isFading(1)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(1, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(1, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(2)){
      duration = 2500 - (analogValue * 2);
      tlc_addFade(2, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(2, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(3)){
      duration = 3400 - (analogValue * 2);
      tlc_addFade(3, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(3, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(4)){
      duration = 3000 - (analogValue * 2);
      tlc_addFade(4, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(4, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(5)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(5, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(5, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(6)){
      duration = 2500 - (analogValue * 2);
      tlc_addFade(6, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(6, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(7)){
      duration = 3400 - (analogValue * 2);
      tlc_addFade(7, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(7, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(8)){
      duration = 3000 - (analogValue * 2);
      tlc_addFade(8, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(8, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(9)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(9, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(9, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(10)){
      duration = 2500 - (analogValue * 2);
      tlc_addFade(10, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(10, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(11)){
      duration = 3400 - (analogValue * 2);
      tlc_addFade(11, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(11, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(12)){
      duration = 3000 - (analogValue * 2);
      tlc_addFade(12, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(12, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(13)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(13, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(13, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
      if (!tlc_isFading(14)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(14, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(14, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
       if (!tlc_isFading(15)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(15, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(15, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
       if (!tlc_isFading(16)){
      duration = 3750 - (analogValue * 2);
      tlc_addFade(16, 28, maxValue, millis(), millis()+ duration );
      tlc_addFade(16, 400, 28, millis()+ duration, millis()+ duration + duration);}
     
     
     
    if (channel++ == NUM_TLCS * 16) {
      channel = 0;
    }
  }
  tlc_updateFades();
}

Grumpy_Mike

I think you are running out of memory.
The library says:-
Quote
/** The default fade buffer length (24).  Uses 24*13 = 312 bytes of ram. */


When you add a fade you are not checking if there is room for the buffer. It says in the library
Quote
/** Adds a fade to the buffer.
    \param fade the fade to be copied into the buffer
    \returns 0 if the fade buffer is full, fadeBufferSize if added successfully
*/
uint8_t tlc_addFade(struct Tlc_Fade *fade)


so in place of doing simply the tlc_addFade
every time you should do:-
Code: [Select]

if( tlc_addFade( ........ ) == 0 ) Serial.print("error no room");

You need a Serial.begin(9600) in the setup function.
Then run the code and see if you get any error print outs.

quizz_kid


so in place of doing simply the tlc_addFade
every time you should do:-
Code: [Select]

if( tlc_addFade( ........ ) == 0 ) Serial.print("error no room");

You need a Serial.begin(9600) in the setup function.
Then run the code and see if you get any error print outs.



I think you´ll have to guide me again =)

Where do I put the if( tlc_addFade( ........ ) == 0 ) Serial.print("error no room"); ?

And what´s the setup function?

Sorry once again for my lack of knowledge

Go Up