Go Down

Topic: Troubles programming DUE (Read 282 times) previous topic - next topic


Sep 16, 2016, 09:23 am Last Edit: Sep 16, 2016, 01:27 pm by Joaqks

I have a programm in Arduino Mega that works perfectly. Now, I want to use the same code in Arduino DUE, but there are some things that I know I have to change. Specific, there are two of them:

1) I need 6 pwm ouputs at 32 KHz. I have read some libraries for that but all of them only changes the frequency in 4 pins (real pwm outputs). I thing that I have to change the configuration of the Timers, but I don't know how to do that in DUE.

2) I need a periodic routine, so I need to programm a Timer for do something each certain time.

3) I need to use functions like delay() and micros(), so I can't change Timer0.

Thanks to all!


The Due has a special timer called SysTick that runs separately from the peripherals that are actually called timers. The delay functions on the Due use SysTick and the on-processor tick counter. I do not believe that Timer0 is used for delay() at all. But, it most likely still used for TimerCounter PWM or something.

Periodic routines are no problem. Get the DueTimer library: https://github.com/ivanseidel/DueTimer/releases

The Due has 8 PWM outputs by default - 4 true PWM and 4 TC PWM. You can look at the Arduino core files, I believe in wiring_analog.cpp to see how they did it.


Thanks for your time.

Using the code in this post (http://forum.arduino.cc/index.php?topic=367154.0) I think that I can obtain 6 PWM outputs, for example in pins 6, 7, 8, 9, 29 and 34. Each in one channel, and all at 32 KHz.

Using the library DueTimer, I can obtain a interrupt using, for example, Timer1.

Now the question is: Will the delay() and micros() functions work fine?  Until now, I was using Arduino UNO and pro mini, and when I modified the PWM frequency this functions don't work well. I have been reading the Due datasheet and looks like I am not going to have problems, but I am not sure...


Go Up