Go Down

Topic: tlc5940 multiplexing code assistance (Read 1 time) previous topic - next topic

Aug 19, 2011, 05:02 pm Last Edit: Aug 19, 2011, 05:27 pm by GuyJustHere Reason: 1
I have changed up Joe's LED table code for my simple 9 RGB LED common Cathode VU meter. It works... But I have no idea how the heck to update my ledArray[] of the RGB grey-scale values so that his code will change my colors.

Ultimately I will use the arduino analog input to control it, but I can't even figure out how to knight rider this code...  WHAT THE HECK IS XLAT DOING?? (I added a bunch of info below code to answer questions about circuit)


Code: [Select]
const int ledCount= 9;     // number LED's - i have a column of 9 RGB LEDS

const byte RedPin = 5;     // digital pin to control red color
const byte GreenPin =6;    // digital pin to control green color
const byte BluePin = 7;    // digital pin to control blue color

const analogInputPin = 1; //analog input from low pass filter 0-5volts of music bass

byte Current_Color = 'R';
int power = 16;            // allow changing the greyscale power

struct led{ //this makes the ledArray pretty
  byte red;
  byte green;
  byte blue;
};

// structured array to hold the led colors
led ledArray[ledCount] = { {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} }


#include "Tlc5940.h"



void setup()
{
   // Setup pins
  pinMode(RedPin,OUTPUT);digitalWrite(RedPin,HIGH); //HIGH is off, using a PNP transistor
  pinMode(GreenPin,OUTPUT);digitalWrite(GreenPin,HIGH); //samesies
  pinMode(BluePin,OUTPUT);digitalWrite(BluePin,HIGH); //samesies
 


   // setup tlc5940
   Tlc.init(0);
   startXLATCallback(); //WHAT IS THIS???
   Tlc.update();
       
}


void loop()
{

}



// do something every 2 periods, so ~2048us
// TLC5940 multiplexing code
#define XLAT_PERIODS  2

volatile uint8_t timesCalled;

volatile void myXLATCallback()
{

  if (timesCalled != 0) timesCalled--;
  else
  {
   timesCalled = XLAT_PERIODS;
   Send_data();
   Tlc.update();
  }
  set_XLAT_interrupt(); // so this will continue to be called
}

void startXLATCallback() {
   timesCalled = XLAT_PERIODS - 1;
   tlc_onUpdateFinished = myXLATCallback;
   myXLATCallback();
}


// update the tlc5940 chip

void Send_data()
{
if(Current_Color == 'R')
{
for(int i=0; i < ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].red*power); //my leds are attached to pin 1-9 on tlc
}
Turn_off();
Tlc.update();
while(tlc_needXLAT);     //WHAT THE HECK??? whyy
Turn_on();
Current_Color = 'G';
}
else if(Current_Color =='G')
{
for(int i=0; i <ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].green*power);
}
Turn_off();
Tlc.update();
                while(tlc_needXLAT); //what is this?
Turn_on();
Current_Color = 'B'; 
}
else
{
for(int i=0; i < ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].blue*power);
}
Turn_off();
Tlc.update();
                while(tlc_needXLAT); //MEOWWW
Turn_on();
Current_Color = 'R';     
}
}


// turn on or off the respective anode transistor

void Turn_off()
{
digitalWrite(RedPin,HIGH);
digitalWrite(GreenPin,HIGH);
digitalWrite(BluePin,HIGH); 
        delayMicroseconds(10);

}

void Turn_on()
{
  switch(Current_Color){  //switch the transistors sexy volt
    case 'R':
    delayMicroseconds(10);
    digitalWrite(RedPin, LOW);
    digitalWrite(GreenPin, HIGH);
    digitalWrite(BluePin, HIGH);
    break;
   
    case 'G':
    delayMicroseconds(10); 
    digitalWrite(RedPin, HIGH);
    digitalWrite(GreenPin, LOW);
    digitalWrite(BluePin, HIGH);
    break;
   
    case 'B':
    delayMicroseconds(10);
    digitalWrite(RedPin, HIGH);
    digitalWrite(GreenPin, HIGH);
    digitalWrite(BluePin, LOW);
    break; 
  }
}


EXTRA INFO
I use arduino outputs to switch PNP transistor base to ground and send my high current supply (800mA @ 5.5 V) to the 9 LED anodes. 3 transistors are used, one for each color (R G B). So at any time, only one transistor/color is engaged...

My LEDs are in a column of 9. pin 1 on tlc5490 relates to LED 1 at the bottom of my column...etc pin 9 is LED 9 at top of my column.

I limited current to 25mA per LED.

PaulS

Code: [Select]
   startXLATCallback(); //WHAT IS THIS???
This is a function call. That's kind of obvious, isn't it?

Is there something about the function call that you don't understand?

off course I do, but I don't understand the XLAT_PERIODS portion

??
Code: [Select]

#define XLAT_PERIODS  2

volatile uint8_t timesCalled;


or ??
Code: [Select]

set_XLAT_interrupt();


or??
Code: [Select]
tlc_onUpdateFinished = myXLATCallback;

PaulS

The code is using interrupts to trigger actions. The interrupt handler sets a flag, indicating that it has been called. When that flag is true, some functions, called callbacks, are called.

Rather than the TLC library doing everything for you, it lets you create a function that it will call when there is something to be done. You need to tell it which function to call. That is what
Code: [Select]
tlc_onUpdateFinished = myXLATCallback;
is doing.

You should look through the library, to see what the number of periods is for.


#4
Aug 19, 2011, 06:09 pm Last Edit: Aug 19, 2011, 09:04 pm by GuyJustHere Reason: 1
thanks that helps with that, but I'm hoping someone can demystify the TLC library a little for me..

how to change ledArray while maintaining a proper transmission of grey scale?


After a lot of research, It seems that XLAT is the pulse that is sent at the end of each grayscale update cycle. So, I guess Joe is using this "interrupt" to trigger his color update?

I could really use any help on understanding this so I can just manually put a blink or fade function in this code?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy