Go Down

Topic: Library for TLC5940 16-channel PWM chip (Read 37728 times) previous topic - next topic

electroGUS

ACleone
Im studying your library version "mux" , and I would like to know the kind of modifications I should take into account in order to use it on a generic non-arduino board.
Any advice will be appreciated.
thank you

gravebond

Im using the TLC5940 in conjuction with an arduino to fade pairs of leds down a line in a wearables project. I have come across a bizarre problem that occurs after 12 cycles of the LED's fading. After the 12th cycle the sketch seems to crash as all the LED's power on permanently unless you hard reset the arduino. I do not know how to rectify this and have tried many things. Is the buffer becoming full? if so how do i reset it? Here is my code:

Code: [Select]

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

TLC_CHANNEL_TYPE channel;
boolean resetFades = true;
void setup (){

 /* Call Tlc.init() to setup the tlc.
    You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
 Tlc.init();
 Serial.begin(9600);
}

void loop () {
 // Tlc.clear();
  channel = 0;
 
 
 
 
    if (resetFades == true ) {
      resetFades = false;
     uint16_t duration = 900;                                               //fade length
     
     // Change these for pairs of LEDS
     
     uint32_t startMillis = millis() + 50;                                
     uint32_t endMillis = startMillis + duration;
     fadePairs(0,  startMillis, endMillis, duration, 100, 100); //Adjust Brightnesses of the Individual LED's in a pair.
     
     startMillis = millis() + 300;
     endMillis = startMillis + duration;
     fadePairs(2,  startMillis, endMillis, duration, 200, 200);
     
     startMillis = millis() + 600;
     endMillis = startMillis + duration;
     fadePairs(4,  startMillis, endMillis, duration, 300, 300);
     
     // Fade in twos
     //LED 0
     //tlc_addFade(channel, 0, maxValueB, startMillis, endMillis); //fade in
     //tlc_addFade(channel, maxValueB, 0, endMillis, endMillis + duration);// fade out
     //tlc_addFade(channel+1, 0, maxValueR, startMillis, endMillis); //fade in
     //tlc_addFade(channel+1, maxValueR, 0, endMillis, endMillis + duration);// fade out
   
   
   
   
     Serial.println("resetting");
    }
   
   
    int fadesRemaining = tlc_updateFades();
   
    if (!fadesRemaining){
      // all fades are done
      resetFades = true;
    }
   
   
    delay(25);
     Tlc.update();
     
     
     
}
//Our LED fading function
void fadePairs(TLC_CHANNEL_TYPE channel, int startMillis, int endMillis, int duration, int maxValueR, int maxValueB){
  tlc_addFade(channel, 0, maxValueB, startMillis, endMillis); //fade in
  tlc_addFade(channel, maxValueB, 0, endMillis, endMillis + duration);// fade out
  tlc_addFade(channel+1, 0, maxValueR, startMillis, endMillis); //fade in
  tlc_addFade(channel+1, maxValueR, 0, endMillis, endMillis + duration);// fade out
}



/////
any help would be appreciated . Thanks.

zomgLEDz

ok first of all, a quick THANK YOU to whomever wrote this wonderful TLC library.

and now, regarding the TLC_FADE_BUFFER_LENGTH issue -
mistergreen: i took your advice and changed the value of that variable to 64 which gave me some more tlc_addfadez, but after ~45 this would stop working. Has anyone solved this issue or worked-around it or hacked something i could use?

thanks!

zomgLEDz

hello, i take it all back. all is fine and dandy when changing buffer size.

thank you anyways.

fabr1cat3d

#259
May 18, 2010, 06:00 am Last Edit: May 18, 2010, 06:14 am by fabr1cat3d Reason: 1
Hello

I am new to arduinos and any type of programming but I've been working on a project requiring me to fade 4x16 LEDs off of one arduino (atmega 328). I've played around with the tlc fade code and everything works well unless multiple sets of LEDs are triggered simultaneously. Each "pod" of LEDs goes through two waves of fade up and a fade down after the sensor has been triggered with an exception to stop an existing wave if the sensor is triggered during a previous pulse. I have included my code which I've tried to comment to the best of my abilities. Any advice on coding or my specific problem would be much appreciated. Thanks.

PS. This code shows only two tlcs but i will ultimately be using four.

Code: [Select]
#include "Tlc5940.h"                                                     //TLC library general
#include "tlc_fades.h"                                                   //TLC library fades

int calibrationTime = 10;                                                //time in seconds for PIR to calibrate
int counter1 = 0;                                                        //counter is the variable for the specific pin on the TLC5940
int counter2 = 0;                                                        //counter is the variable for the specific pin on the TLC5940

uint16_t LEDSpeed1 = 200;                                                //time between each LED
uint16_t LEDSpeed2 = 1000;                                               //time between each LED
uint16_t duration1 = 1600;                                               //duration
uint16_t duration2 = 30000;                                              //duration
uint16_t maxValue = 1000;  
uint16_t midValue = 10;                                                   //as counter gets higher max brightness decreases

boolean isFading1 = LOW;
boolean isFading2 = LOW;

const int irInput1 = 6;                                                  //pin for PIR 1
int irState1 = 0;
const int irInput2 = 4;                                                  //pin for PIR 2
int irState2 = 0;  

const int sensorDelay = 8000;                                            //time in milliseconds after sensor is toggled high before it will take another reading
uint32_t currentTime1 = 0;                                               //time of the last PIR toggled HIGH
uint32_t currentTime2 = 0;                                               //time of the last PIR toggled HIGH

TLC_CHANNEL_TYPE channel;                                                //TLC code for defining channel

void setup()
{
 Serial.begin(9600);
 Tlc.clear();
 Tlc.init();
 pinMode(irInput1, INPUT);  
 pinMode(irInput2, INPUT);
 for(int i = 0; i < calibrationTime; i++){
   delay(1000);
 }
}

void loop()
{
 Tlc.clear();                                                            //clear pins
 isFading1 = LOW;                                                                        //set channel to zero
 isFading2 = LOW;

 //sample sensor

 if (millis()>(currentTime1+sensorDelay)){                               //confirm it has been a long enough wait for PIR to take another reading
   irState1 = digitalRead(irInput1);                                     //read PIR
 }
 if (millis()>(currentTime2+sensorDelay)){                               //confirm it has been a long enough wait for PIR to take another reading
   irState2 = digitalRead(irInput2);                                     //read PIR
 }

 // fadeout

 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
   if (irState1 == HIGH){                                                  //if pin is high stop the fades and fade all LEDs out before starting waves

     counter1 = 0;
     currentTime1 = millis();
     Tlc.clear();
     tlc_updateFades();

     for (int i = 0; i < 16; i++){                                                 //cycles through channels 0 - 15

       uint16_t stopValue = Tlc.get(i);                              //find the current channel value
       tlc_removeFades(i);                                           //take fade off of that channel
       tlc_updateFades();                                                  //update
       Tlc.set(i, stopValue);                                        //set the channel to previous stop value
       uint16_t duration = (stopValue + 1)*2;                                //set fade duration to stop value plus one so there are no zero duration fades
       uint32_t startMillis = millis();                                    //start fade at current time
       uint32_t endMillis = startMillis + (duration);                      //end fade at current time plus duration
       tlc_addFade(i, stopValue, 0, startMillis, endMillis);         //take fade from previous stop value to zero for the specified duration
       tlc_updateFades();                                                  //update
       irState1 = LOW;                                                     //reset irState1 LOW
     }
     counter1++;
   }
 }

 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
   if (irState2 == HIGH){                                                  //if pin is high stop the fades and fade all LEDs out before starting waves

     counter2 = 0;
     currentTime2 = millis();
     Tlc.clear();
     tlc_updateFades();

     for (int i = 16; i < 32; i++){                                                

       uint16_t stopValue = Tlc.get(i);                        
       tlc_removeFades(i);                                  
       tlc_updateFades();                                            
       Tlc.set(i, stopValue);                                      
       uint16_t duration = (stopValue + 1)*2;                            
       uint32_t startMillis = millis();                                    
       uint32_t endMillis = startMillis + (duration);                    
       tlc_addFade(i, stopValue, 0, startMillis, endMillis);        
       tlc_updateFades();                                                
       irState2 = LOW;                                                  
     }
     counter2++;
   }
 }
 // i s F a d i n g
 for (int i = 0; i < 16; i++){

   if (tlc_isFading(i) == 1){
     isFading1 = HIGH;
     break;
   }
 }
 for (int i = 16; i < 32; i++){

   if (tlc_isFading(i) == 1){
     isFading2 = HIGH;
     break;
   }
 }
 // w a v e 1

 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
   if ((counter1 == 1)&&(irState1 == LOW)&&(isFading1 == LOW)){    
     Tlc.clear();
     for (int i = 0; i < 16; i++){                                                //from channel 0 - 15
       uint32_t startMillis1 = millis() + ((LEDSpeed1*(i+1)));               //start time is a function of LEDspeed constant, channel and how many waves have occured
       uint32_t endMillis1 = startMillis1 + (duration1);                       //end time is start time plus duration
       tlc_addFade(i, 0, maxValue, startMillis1, endMillis1);                         //add Fade up
       tlc_addFade(i, maxValue, midValue, endMillis1, endMillis1 + (duration1*4));    //add fade down
       tlc_addFade(i, midValue, (maxValue*.5), endMillis1 + (duration1*4), (endMillis1 + (duration1*4))+duration1);                         //add Fade up
       tlc_addFade(i, (maxValue*.5), 0, (endMillis1 + (duration1*4))+duration1, (endMillis1 + (duration1*4))+duration1 + (duration2));    //add fade down
       tlc_updateFades();                                                     //update
       irState1 = LOW;                                                        //set IRstate low
     }
     Tlc.clear();
     tlc_updateFades();
     counter1++;
   }
 }
 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
   if ((counter2 == 1)&&(irState2 == LOW)&&(isFading2 == LOW)){    
     // Tlc.clear();
     for (int i = 16; i < 32; i++){                                                

       uint32_t startMillis1 = millis() + ((LEDSpeed1*(i-15)));              
       uint32_t endMillis1 = startMillis1 + (duration1);                      
       tlc_addFade(i, 0, maxValue, startMillis1, endMillis1);                        
       tlc_addFade(i, maxValue, midValue, endMillis1, endMillis1 + (duration1*4));    
       tlc_addFade(i, midValue, (maxValue*.5), endMillis1 + (duration1*4), (endMillis1 + (duration1*4))+duration1);                        
       tlc_addFade(i, (maxValue*.5), 0, (endMillis1 + (duration1*4))+duration1, (endMillis1 + (duration1*4))+duration1 + (duration2));  
       tlc_updateFades();                                                    
       irState2 = LOW;                                                        
     }
     Tlc.clear();
     tlc_updateFades();
     counter2++;  
   }
 }
 Tlc.clear();
 tlc_updateFades();  
}




jst1gy

Good day all and Hopefully I can be pointed into the correct direction. I tried using the search function but couldn't find exactly what I was looking for.

Currently my friend and I are trying to build a dancing light bar.  We have a RGB LED Strip, some TLC5940NT's and are slowly building this.  We got the TLC Chip via this tutorial to dance standard LED Lights.  However, we wish to move to highscale and do not wish to blow the Arduino.  I am wondering how we can push 12V via the diagram in the tutorial for these chips without hurting the arduino.

We wish to learn as much as we can on our own.  However, we are both Programmers trying to learn all of this.  

DustMonkey

Quote
Good day all and Hopefully I can be pointed into the correct direction. I tried using the search function but couldn't find exactly what I was looking for.

Currently my friend and I are trying to build a dancing light bar.  We have a RGB LED Strip, some TLC5940NT's and are slowly building this.  We got the TLC Chip via this tutorial to dance standard LED Lights.  However, we wish to move to highscale and do not wish to blow the Arduino.  I am wondering how we can push 12V via the diagram in the tutorial for these chips without hurting the arduino.

We wish to learn as much as we can on our own.  However, we are both Programmers trying to learn all of this.  


Check out this link. http://www.ti.com/litv/pdf/slva280
The transistor method is definitely less expensive but a lot more tricky, especially if you have RGB.

Although my guess is you've either fried everything or found a working solution :-P

jst1gy

not yet we kind of shelved it for now.  
thanks for the pdf we will see if we can unshelve this and continue with making light goodness :)

any help will be greatly appreciated.

4nt0n

There were some people mentioning in this thread that they were trying to control small vibrating motors with the TLC5940. Did anyone had any results? I am trying to do the same with some of those that are 2,3 V and 85 mA. I need to hook up 16 of those. Although I can control their intensity-speed when I try to use the fade functions they don't seem to respond.
any ideas??

laxman


FruityFred

Hello all,

Does someone know if it's possible to use 21 daisy-chained TLC5940 (just daisy-chain, not multiplexing) with an Arduino? All the TLCs would be on the same PCB to avoid too long wires... In the datasheet, TI says that the limit is 40, but what in real life?

Thank you for your answers!

Jesusismybrother

hey a new one here :D
i wished i get only the half of that informations.
i just recieved the tlc5940 and tried the first examples.
they also worked but i do not really understand how the code works, maybe someone could helf my explain the commandos. :s
After understanding them i want to controle RGBs (like more or less everybody else ;) )but thats shouldn't be your probleme.
i do not have any sample code because everything i tried didnt worked.
So i think i first should start understand the basics of that IC and thats where i nead YOUR help :)
loooking forward
max

PS: sorry for my english

narutoxela

#267
Nov 27, 2010, 11:28 pm Last Edit: Nov 27, 2010, 11:29 pm by narutoxela Reason: 1
hi acleone   :)    i was wondering if with the TLC5940Mux library, can i add more that 8 rows?? if so can you tell how?? plz?? (obviously im a noob so...)

because i want to have like 50 rows...

Go Up