Problem using Timer1 and Tlc5940 libraries together

Status
Not open for further replies.

jcnesci

New member
Hi,
Paul answered my question on Github but I'll repost here for posterity. Feel free to add comments if you've dealt with this before, too:

// ---------------------------------------------------
MY QUESTION:
// ---------------------------------------------------


I am simply trying to use the Tlc5940 library with the TimerOne library in the same Arduino sketch (Teensy 3.2, Teensyduino installed on OSX).

My Arduino sketch is as simple as:
Code:
#include "TimerOne.h"
#include "Tlc5940.h"

void setup() {}
void loop() {}

The error seems to be about multiple ftm1_isr definitions.
Code:
/var/folders/31/mc3khzyn4p76dfvl53dqbc5m0000gn/T/arduino_build_830505/libraries/Tlc5940/Tlc5940.cpp.o: In function `ftm1_isr':
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Tlc5940/Tlc5940.cpp:76: multiple definition of `ftm1_isr'
/var/folders/31/mc3khzyn4p76dfvl53dqbc5m0000gn/T/arduino_build_830505/libraries/TimerOne/TimerOne.cpp.o:/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/TimerOne/TimerOne.cpp:35: first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: Disabling relaxation: it will not work with multiple definitions
collect2: error: ld returned 1 exit status
Error compiling for board Teensy 3.2 / 3.1.

I realize Tlc5940 uses timer1, though I'm not savvy enough to understand how.
Is there a way to use timer1 thru the Tlc library instead of including it as its own library?
Or any other solution, of course, is welcome.

// ---------------------------------------------------
PAUL'S ANSWER:
// ---------------------------------------------------


Use Timer3 or IntervalTimer instead.
 
Basically, Paul is right. Although updated to be compatible with modern 32bit Teensy processors, these TimerOne and TimerThree libraries are rather historic relicts to deal with the limited timer resources of old fashioned 8bit AVR based processors.

In the Teensy variants of both libraries which you want to include, TLC5940 and TimerOne, the timing tasks are mapped to the same Teensy internal hardware flextimer FTM1 which leads to conflicts. That's why Paul recommended using the TimerThree library which maps to flextimer FTM2.

But basically, there is no need for an additional TimerWhatever library at all. You didn't write what you intended to do with the TimerOne library...
- If it's about launching interrupts at precisely defined time intervals, the IntervalTimer object is a more efficient and contemporary solution allocating dynamically one of the 4 internal dedicated interrupt timers without including additional libraries.
- And if it was about outputting PWM signals directly to Teensy pins, the analogWrite() function will do it in an easier way for all PWM capable pins of the Teensy 3.2, out of pins 3 and 4 which are linked to FTM1 monopolized by the TLC5940 library. Thus, pins 5,6,9,10,20,21,22,23,25 and 32 could be used for that purpose, without additional libraries, too.

That should explain why the TimerOne and TimerThree libraries are more or less obsolete when using modern Teensy 3.x processors. :)
 
Last edited:
- If it's about launching interrupts at precisely defined time intervals, the IntervalTimer object is a more efficient and contemporary solution allocating dynamically one of the 4 internal dedicated interrupt timers without including additional libraries.

I was indeed wanting to launch interrupts, so this was perfect in leading me to use IntervalTimer, finally.
Thanks a lot, really helpful breakdown of the nitty-gritty!
 
Status
Not open for further replies.
Back
Top