Show Posts
Pages: [1] 2 3 ... 6
1  Forum 2005-2010 (read only) / Troubleshooting / Re: serail read problem -> Arduiono NT -> TLC5940 on: October 11, 2008, 01:07:46 pm
What exactly are you trying to do with the TLC library?  The serial example wasn't really meant for full control of the TLC5940.  Have you used Firmata before?  I think I could get the TLC Library talking with Firmata.
2  Forum 2005-2010 (read only) / Troubleshooting / Re: error: 'byte' does not name a type on: January 26, 2009, 05:32:49 am
above the #include, try throwing in:
#define byte uint8_t

or just change all the byte's to uint8_t
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with mode 14 fast pwm required. on: January 04, 2009, 03:26:51 pm
First, the idiom for setting up control registers is to use the constants that avr-libc defines, eg
TCCR1A =  _BV(COM1B0)      // toggle OC1B on compare match
      | _BV(WGM10)
      | _BV(WGM11);
TCCR1B =  _BV(WGM12)
      | _BV(WGM13);      // Fast PWM mode, OCR1A as TOP
(_BV(x) is defined as (1 << (x)))

Second, since we are just generating a square wave, I would toggle on compare match instead of setting OCR1A/B to 50% of the top value.  Since we are changing top, lets use OCR1A as top because it is double buffered.

I would avoid floats entirely, so here's how to convert for toggle on compare match:
65Hz = F_CPU / ((top + 1) * 2 * prescale value)

solving for top we have
top = (F_CPU / (65Hz * 2 * prescale)) - 1
top = (16,000,000 / (65Hz * 2 * prescale = 1)) - 1 = 123075

ok, so a prescale value of 1 is too fine a resolution (the max for top is 0xFFFF = 65535).  Let's try a div 8 prescale:
top = (16,000,000 / (65Hz * 2 * prescale = smiley-cool) - 1 = 15383

ok, now for 2k:
top = (16,000,000 / (2000Hz * 2 * prescale = smiley-cool) - 1 = 499

ok, so top is going from 15383 to 499, and the prescale is div 8.
void setup() {
  pinMode(10, OUTPUT);

  TCCR1A = _BV(COM1B0)      // toggle OC1B on compare match
         | _BV(WGM10)
         | _BV(WGM11);
  TCCR1B = _BV(WGM12)
         | _BV(WGM13);      // Fast PWM mode, OCR1A as TOP
  OCR1B = 0;            // toggle when the counter is zero
  OCR1A = 15383;      // set top to the initial 65Hz
  TCCR1B |= _BV(CS11);      // set prescale to div 8 and start the timer

void loop() {
  for (uint16_t top = 15383; top >= 499; top--) {
    OCR1A = top;
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Killer code? on: September 03, 2008, 03:00:55 am
You can't say something like
for(int i =c; i < i+3; i++)

because i will always be less than i + 3.  Instead do something like
for(int i =c; i < c + 3; i++)
    digitalWrite(pins[i], HIGH);
    digitalWrite(pins[i], LOW);

This shouldn't kill your board though, try loading the blink example sketch, verifying it, then pressing the reset button on the Arduino right after you press the upload button (or at the same time?).
5  Forum 2005-2010 (read only) / Interfacing / Re: Arduino to MATLAB on: September 03, 2008, 03:32:30 am
If I have time before school starts up again, I'll try to get Matlab talking with Firmata.  I would also like to see a Firmata library for Labview.  If anyone else has time, please start and post your progress in the playground!
6  Forum 2005-2010 (read only) / Interfacing / Re: TLC5940.   Is there a max. length of daisy chain? on: October 28, 2008, 04:37:38 am
Looking through the library, I realized the max you can have is 10.  This isn't due to RAM usage but because I use an 8-bit (uint8_t) variable to iterate over the array (24 bytes per chip), so 11 * 24 = 264 which is greater than 255 and overflows uint8_t.  I'm cleaning up the library and I'll change this code, check the main thread in the development section for updates!

Just fyi, If you aren't using fades, you can free up a lot of ram.  The second argument of Tlc.init is how many fades you want to use at once:
Tlc.init({numchips}, 0)
(if you don't want to use fades)
7  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: July 21, 2009, 07:05:18 pm
@bensaddiction: Very weird.  I don't have a Mac to test on, but can anyone else reproduce this?  Try reinstalling Arduino and then the library.
8  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: May 29, 2009, 02:45:24 am
It's switching rows every 512us (microseconds), and an update for 3 tlc's takes ~160 us.  I'm using cheap leds from ebay, which are pretty bright.

The image:

What it looks like in the dark behind a piece of paper (the blending between pixels makes it look better when the text scrolls):

Without the paper:

9  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: May 26, 2009, 10:52:24 pm
I made myself a 8x11 rgb matrix with 3 tlcs and made a new library variant, Tlc5940Mux.  Still alpha, needs documentation, and I'll probably write some more documentation for the main library.

I multiplex 8 rows: all anodes (+) of each led in the row are connected together, and each column goes to a tlc.  All the red leds in the first column go to channel 0 of the first tlc, all the blue leds to channel 0 of the second tlc, and all green columns go to the third tlc.

There's two examples, a Matrix example that displays a diagonal line, and a Serial example that uses 0.5M baud serial (and a python program) to scroll an image ("Arduino Rocks My Socks!!!" in rainbow colors) at 60 fps.  Youtube coming soon when I get a chance to edit the video.
10  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: April 22, 2009, 03:29:08 am

You can lower the update speed by commenting out
SPSR = _BV(SPI2X); // double speed (f_osc / 2)
in Tlc5940.cpp (line ~327).  That will reduce the speed by half.  If you need to go even slower, see "SPI clock rate select" on pg 170 of the datasheet.

Where are the resistors connected?


I finally got around to replacing my horrible ascii pin-out diagram!  This is my first time using inkscape: anything I should change with my png?  (inkscape svg source)

I got the breadboard from follower.
11  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: April 20, 2009, 04:33:54 pm
The flickering you describe sounds like it's being caused by long wires.  If you have a scope, see if you're getting ringing on the control lines.  Try putting resistors in series with SCLK and XLAT and one of the tlc's.
For example,
Put a 1k between the ribbon cable SCLK and the 10th tlc's SCLK (and same with XLAT). 1k is pretty arbitrary so try other values.

The new millis rollover was introduced with 0013(?) - it's not part of the bootloader.  I updated tlc_fades again, try downloading r012 (

1.  Yes, that looks correct.  See the documentation for tlc_setDCfromProgmem.
The funny-looking
prog_uint8_t dcArray1[NUM_TLCS * 12]
gets stored in program memory, which is where your sketch goes (if you comment out the array, the sketch size would go down).
You don't have to set DCPRG high - tlc_setDCfromProgmem does this for you.

2.  Yes, it's 120 mA per channel.  You will need cooling if you try to drive that much current - see the datasheet.

Mike Mc:
No, as ReSiStAnCe pointed out, you have to set all the dot-correction at once.

Nothing looks wrong.  The pull-up resistor value doesn't matter much, so 2.2k or 4.7k will work.  If you have access to a scope, see if the tlc is generating pulses to the servo.

Sorry to have been inactive lately - I'll try to check the forums more often.
12  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: March 05, 2009, 09:16:56 pm
There was a bug with the ATmega328p, which now should be fixed: see

The multiplexing library variant should be out soon!
13  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: March 03, 2009, 12:03:17 am
I don't think you can call while(tlc_needXLAT); inside the interrupt callback, because tlc_needXLAT is set zero in the interrupt routine! (interrupts are enabled before calling the callback, so I think you might get a stack overflow because the interrupt routine will never return.)

I'm going to clone the library and add multiplexing, eg Tlc5940Mplex
1.  Tlc.set becomes Tlc.set(multiplex_channel, channel, value)
2.  No more Tlc.update(), because the library will always be updating
3.  You have to put the interrupt code into the sketch
14  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: March 02, 2009, 09:58:11 pm
The library sends all the data on an update (no other way to update).  What exactly do you mean by blink?  If you turn all the LEDs on red, do they blink green for a second?
15  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 26, 2009, 11:31:53 pm
joe: you should wait for the PWM cycle to end before you switch transistors, eg

#define RED  0
#define GREEN 1
#define BLUE 2
uint8_t color;

void loop()
  if (color == 3) {
    color = 0;

  // set everything
  if (color == RED) {
    Tlc.set(0, 1000);
  } else if (color == GREEN) {
    Tlc.set(1, 1000);
  } else {
    Tlc.set(2, 1000);
  while (tlc_needXLAT)

I haven't measured Tlc.update() in SPI mode but way back in August I measured bit-banging to be about ~260us for 1 tlc.
Pages: [1] 2 3 ... 6