Due servo library timer interrupt

I’m using the “Due” board and trying to combine the “servo” example which works ok alone, and Copperhill “CANbus with leds” example which also works ok alone.
When combined to a single file the compiler returns error "multiple definition of TC3_Handler'". I've been unable to find the exact phraseTC3_Handler’ code in the servo library.
The IDE 1.6.11 is current, the libraries are current and they all work ok, just not together.
Not being able to find the other definition of `TC3_Handler’ I don’t know what to do?
Attached is the verbos error text.

can_prob.txt (31.3 KB)

Hi there!

There is a similar issue with using the Servo library and other libraries in the same sketch. This problem is occurring because the Servo library and the other library are both trying to use Timer1 in the microcontroller chip. To test if this is an issue for you, try to upload the following sketch:

#include <Servo.h>
#include <CANBus.h> //or whatever that library is called

void setup()
{

}

void loop()
{

}

Since there is no code in either the setup or loop portions, the only way an error could occur is if the two libraries are conflicting with each other.

Does this code give you the same “TC3_Handler” error?

If so, there is another library called ServoTimer2, which uses Timer2 instead of Timer1. To use it, simply do the following:

#include <Servo.h> //Change from this...
#include <ServoTimer2.h> //....to this

Servo myServo; //Change from this...
ServoTimer2 myServo; //....to this

Please note that ServoTimer2.write() does NOT take a value in degrees(0->180), but rather a number of microseconds (0->3000). Some say it goes from 1000->2000 but my servo can take 0->3000.

Try this and let me know how it works!

Sorry for delayed responce, long weekend. :slight_smile:
Yes the useage with no code gives the same error so its definately the library declarations.
I installed the ServoTimer2 zip library and then
The switch to servotimer2 gets a scope declaration error.
So I tried to compile ‘Threeservos’ example, it also gives scope declaration errors
see ‘servo2 libs text’
I’m not much of a C programmer so precisly where to create the missing variables eludes me.
I thought the example should work straight away?
When I get the example to work I can move back to my code.

Servo2 libs.txt (13.6 KB)

Hi,
Have you tried to ask these questions in the DUE section of the forum?

Tom... :slight_smile:

When I get the example to work I can move back to my code.

You won’t, until you rewrite the ServoTimer2 library to be compatible with the Due.

All these timers and their respective Interrupt Handlers are used by Servo.h library:

TC0, chan 0 => TC0_Handler
TC0, chan 2 => TC2_Handler
TC1, chan 0 => TC3_Handler
TC1, chan 1 => TC4_Handler
TC1, chan 2 => TC5_Handler

Modify the code provided by Copperhil (that you didn’t post) to use another one.

BTW, you can include these 2 libraries together:

#include <due_can.h>
#include <Servo.h>

My take on the situation is that both programs work alone on the Due.
Thus it is not a Due problem but a software problem, programming forum.
The Servo2 example will not compile with genuino 101 either.
I will not be writeing C code for anything.

All 6 interupt timers are not being used by the servo.
Interupts not being used by program A should be available for use by program B.
The servo grabbing all of the interupts is not isolated to a Copperhill conflict.

I will not post his code as it is his not mine.
He does refer to http://forum.arduino.cc/index.php?topic=130423.0.
Tip: Anyone thinking of useing CAN bus this is the place to go.

Hi,
From your error list.

Arduino: 1.6.11 (Windows 7), Board: "Arduino Due (Programming Port)"

Have you tried a later version of the IDE, it is up to over 1.8.5 now.

Tom... :slight_smile:

In ServoTimers.h , comment this line (Timer Counter 1 channel 0 = TC3 ):
//#define _useTimer1

And TC3_Handler() will not be used by the Library.

ard_
aha!
I looked everywhere with text search for a duplicate definition of TC3_Handler and coudn't find it.
Thanks

tom
I shy away from updating my systems in the middle of a project.
You can easily get kicked back to your starting point loosing a lot of time.

bobnorway:
ard_
aha!
I looked everywhere with text search for a duplicate definition of TC3_Handler and coudn't find it.
Thanks

tom
I shy away from updating my systems in the middle of a project.
You can easily get kicked back to your starting point loosing a lot of time.

You can operate more than one version of the IDE on one PC.
With Windoz you can, I don't know with Maccas.

Each has its own directory.
Down load the zip files and try them.
Forget about self extracting exe, I always copy the zip files.
Tom...