Hello,
if you need timer2 for remote control, you can move TLC5940 timer2 usage to e.g. timer5
Timer5 is free in most other applications:
Changes in TLC5940.cpp:
#if TLC_TIMER5 == 0
/* Timer 2 - GSCLK */
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)
#else
/* Timer 5 - GSCLK */
TCCR5A = _BV(COM5B1) // set on BOTTOM, clear on OCR2A (non-inverting),
// output on OC2B
| _BV(WGM51) // Fast pwm with OCR2A top
| _BV(WGM50); // Fast pwm with OCR2A top
TCCR5B = _BV(WGM52) // Fast pwm with OCR2A top
| _BV(WGM53); // Fast pwm with OCR2A top /* This line is new to get Timer 5 in same Mode like Timer2 */
OCR5B = 0; // duty factor (as short a pulse as possible)
OCR5A = TLC_GSCLK_PERIOD; // see tlc_config.h
TCCR5B |= _BV(CS50); // no prescale, (start pwm output)
#endif
Set the Port correctly:
#if TLC_TIMER5 == 0
GSCLK_DDR |= _BV(GSCLK_PIN);
#else
GSCLK2_DDR |= _BV(GSCLK2_PIN); // Pin 45 ist OCR5B
#endif
and add to Arduino_mega.h:
/** OC2B (Mega pin 9) -> GSCLK (TLC pin 18) */
#define GSCLK_PIN PH6
#define GSCLK_PORT PORTH
#define GSCLK_DDR DDRH
/** OC5B (Mega pin 45) -> GSCLK (TLC pin 18) */
#define GSCLK2_PIN PL4
#define GSCLK2_PORT PORTL
#define GSCLK2_DDR DDRL
I added a define in tlc_config.h:
#define TLC_TIMER5 1 // 0 uses Timer2 GSCLK Pin9 1 uses Timer 5 GSCLK Pin45
The old code you can find strapped with TLC_TIMER5 == 0.
I hope his helps.
Regards
Andreas