TLC5940 and nrf24L01

350 views
Skip to first unread message

matan.h...@gmail.com

unread,
May 16, 2014, 2:18:45 PM5/16/14
to tlc5940...@googlegroups.com
Hi,

I am trying to use both TLC5940 and nrf24L01 with Arduino Mega. Unfortunately they probebly share a timer that interrupt to the TLC(but not to the nrf, as I saw).

I'm trying to find the way to use both of them, I saw that TLC5940 library use TIMER 1 and TIMER 2. can I change it to use other timers? I am use MEGA so I have 6 timer, should be enough not?

Thanks a lot.

Alex Leone

unread,
May 16, 2014, 3:38:17 PM5/16/14
to matan.h...@gmail.com, tlc5940arduino
Hi,

Yes, you should be able to edit either library to use other timers.  It should just work if you change all the TIMER1/OCR1A/CS1, etc to TIMER4/OCR4A/CS4 etc and connect the different output pins. 4 is just an example, I didn't actually look in the datasheet to see if timer4 is 16-bits.  This will only work if you are switching to the same bit-width (eg switching timer1 to a different 16-bit timer, or timer2 to a different 8-bit timer).

If you need to switch to different bit-width timers, you will have to adjust the clock prescale and the output compares, see the atmega datasheet.  Here's more info about how the library uses the timers:

  - timer2, which drives GSCLK, by default outputs a 4MHz clock signal.  You can put it on any other timer.

  - timer1, which drives BLANK and XLAT, should be (4MHz / 4096), with the blank pulse 2 cycles wide, and the XLAT pulse 1 cycle wide.

Hopefully that helps!

 - Alex





--
You received this message because you are subscribed to the Google Groups "tlc5940arduino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlc5940arduin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

matan.h...@gmail.com

unread,
May 16, 2014, 3:58:55 PM5/16/14
to tlc5940...@googlegroups.com, matan.h...@gmail.com
Hi Alex

Thanks a lot for your quick answer. I found this code:

/* Timer 1 - BLANK / XLAT */
TCCR1A = _BV(COM1B1); // non inverting, output on OC1B, BLANK
TCCR1B = _BV(WGM13); // Phase/freq correct PWM, ICR1 top
OCR4A = 1; // duty factor on OC1A, XLAT is inside BLANK
OCR4B = 2; // duty factor on BLANK (larger than OCR1A (XLAT))
ICR1 = TLC_PWM_PERIOD; // see tlc_config.h

/* Timer 2 - GSCLK */
#ifdef TLC_ATMEGA_8_H
TCCR2 = _BV(COM20) // set on BOTTOM, clear on OCR2A (non-inverting),
| _BV(WGM21); // output on OC2B, CTC mode with OCR2 top
OCR2 = TLC_GSCLK_PERIOD / 2; // see tlc_config.h
TCCR2 |= _BV(CS20); // no prescale, (start pwm output)
#else
TCCR4A = _BV(COM2B1) // set on BOTTOM, clear on OCR2A (non-inverting),
// output on OC2B
| _BV(WGM21) // Fast pwm with OCR2A top
| _BV(WGM20); // Fast pwm with OCR2A top
TCCR4B = _BV(WGM22); // Fast pwm with OCR2A top
OCR4B = 0; // duty factor (as short a pulse as possible)
OCR4A = TLC_GSCLK_PERIOD; // see tlc_config.h
TCCR4B |= _BV(CS20); // no prescale, (start pwm output)
#endif
TCCR1B |= _BV(CS10); // no prescale, (start pwm output)
update();

I want to use timer 4 and 5, both 16 bits. I guess I can use a 16 bits as 8 bits timer. don't sure what I need to write there.

Thanks a lot.

matan.h...@gmail.com

unread,
May 16, 2014, 4:06:45 PM5/16/14
to tlc5940...@googlegroups.com, matan.h...@gmail.com
Just seen I wrote for one of the changes I tried. the original code is:

/* Timer Setup */

/* Timer 1 - BLANK / XLAT */
TCCR1A = _BV(COM1B1); // non inverting, output on OC1B, BLANK
TCCR1B = _BV(WGM13); // Phase/freq correct PWM, ICR1 top
OCR1A = 1; // duty factor on OC1A, XLAT is inside BLANK
OCR1B = 2; // duty factor on BLANK (larger than OCR1A (XLAT))
ICR1 = TLC_PWM_PERIOD; // see tlc_config.h

/* Timer 2 - GSCLK */
#ifdef TLC_ATMEGA_8_H
TCCR2 = _BV(COM20) // set on BOTTOM, clear on OCR2A (non-inverting),
| _BV(WGM21); // output on OC2B, CTC mode with OCR2 top
OCR2 = TLC_GSCLK_PERIOD / 2; // see tlc_config.h
TCCR2 |= _BV(CS20); // no prescale, (start pwm output)
#else
TCCR2A = _BV(COM2B1) // set on BOTTOM, clear on OCR2A (non-inverting),
// output on OC2B
| _BV(WGM21) // Fast pwm with OCR2A top
| _BV(WGM20); // Fast pwm with OCR2A top
TCCR2B = _BV(WGM22); // Fast pwm with OCR2A top
OCR2B = 0; // duty factor (as short a pulse as possible)
OCR2A = TLC_GSCLK_PERIOD; // see tlc_config.h
TCCR2B |= _BV(CS20); // no prescale, (start pwm output)
#endif
TCCR1B |= _BV(CS10); // no prescale, (start pwm output)
update();

Thanks again.

Nirav Gadhia

unread,
Aug 5, 2015, 12:13:37 AM8/5/15
to tlc5940arduino, matan.h...@gmail.com
Dear Friend,

As you have worked on TLC with arduino. 
I am working on project which control the multiple servos by TLC5940nt PWM driver with arduino uno board.
I have written the code as per requirement of rotation but I have found that the servo is rotating almost half of its given angle.
If I have written the 90 degree to rotate the servo then it rotate just half of it means approx 45 degree.
I dont understand that why it happens so???

Plz suggest me if you have any idea regarding this.

Thank you,
Nirav
Reply all
Reply to author
Forward
0 new messages