Jump to content
43oh

TLC5940 examples


Recommended Posts

I would strongly suggest reading TLC5940 datasheet, so you understand how TLC5940 operates.

updateTLC sends all data to shift register during PWM cycle. Then when PWM cycle is done, we latch this new data to GS registers.

In short, updateTLC prepares data so we don't have any delay when PWM cycle is done.

After we latch new data, we call updateTLC to send new data right away.

 

Yes, SPI is 8 bit, but we TLC GS is 12 bit, so we send two 12 bit GS values at once and split them into three 8 bit bytes ( 2 x 12 = 3 x 8)

Link to post
Share on other sites
  • 2 weeks later...
  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

TLC5940 code examples. 1. UART to TLC 2. Chasing light, useful for your next Knight Rider project #include #define SCLK_PIN BIT5 #define MOSI_PIN BIT7 #define GSCLK_PIN BIT4 #define BLANK_PIN B

Yes, I am using 4bit data and multiplying it by 256 when sending. To be exact, since TLC requires 12bit GS data, I am sending 3 SPI bytes in each iteration with GS data for 2 LEDs and the only thing I

Here are some 2231 examples   #include <msp430g2231.h> #include "pattern.h" #define SCLK_PIN BIT5 #define MOSI_PIN BIT7 #define GSCLK_PIN BIT4 #define BLANK_PIN BIT2 #define XLAT_PIN BIT1 #

hi RobG, what is the GS pwm cycle here? and

and according to me updateTLC() should be called just after elese conditon and within the loop. becoz by executing the if or else condition, it shud put those leds element value in the buffer.and then when delay is encountered- it shud latch all data , and show the outputs.After executing ISR, it will again come back to while loop i.e. execute if or else conditon. Now new positions (according to the pattern), then it shud update in the UCB0TXBUF, and then call ISR....

becoz now what is happening--->

and when else or if condition is executed once,program control goes to delay_cycles and then interrrupt is called becoz of delay function as to calll ISR it need just a gap of 256us. From interrupt it goes to update TLC where updateTLC has no value for other leds .It has value for just two leds and it run for 8 times with no values of other "leds" array elements. Then what for, it runs for 8 times? In the interrupt, updateTLC is called , but when values in

Link to post
Share on other sites

There are two things that happen in the code from post #1 (after configuration steps.)

1. main loop with delay - this is where animation is taken care of, frame rate is set by the delay (not the prettiest solution but very clear.) 

2. timer ISR - this is where data is sent to TLC when it should be

Both are independent of each other. 

 

Animation is simple, delay - change data - delay - change data - ...

TLC part - when all 4096 GS clocks have been sent (TLC's GS PWM cycle is done,) latch previously sent data, send new data, leave ISR (GS PWM cycles is already in progress.)

 

GS PWM cycle is TLC5940's internal cycle (see datasheet) which takes 4096 GSCLK cycles.

 

As for breathing LEDs, try this (this example uses linear curve, see other examples of breathing LEDs on 43oh for better curves)

unsigned char cled;
while (1) {
        _delay_cycles(500000);
        cled = 0;
        while ( cled < 16 ) {
          leds[cled] = counter;
          cled++;
        }
        if (direction) {
            counter--;
            if (counter == 0)
                direction = 0;
        } else {
            counter++;
            if (counter == 15)
                direction = 1;
        }
    }
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...