Go Down

Topic: Arduino Due Timers Help (Read 494 times) previous topic - next topic


Hello, I own an Arduino Uno and I'm considering to get an Arduino Due. I'm going to use its many timers to drive a dot-matrix printer head in order to make some music, like MIDIDesaster has made, but with a simpler hardware. The problem is: in the datasheet of SAM3X8E, only six channels of the Timer Counters are mapped to physical pins of the processor. I read in the other topic about Due's timers that using some code, you could address the unmapped timers, but I'm not really sure.

Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

Code: [Select]

volatile boolean l;

//TC1 ch 0
void TC3_Handler()
        TC_GetStatus(TC1, 0);
        digitalWrite(13, l = !l);

void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above
        TC_SetRA(tc, channel, rc/2); //50% high, 50% low
        TC_SetRC(tc, channel, rc);
        TC_Start(tc, channel);

void setup(){
        startTimer(TC1, 0, TC3_IRQn, 4); //TC1 channel 0, the IRQ for that channel and the desired frequency

void loop(){

Here is the table of parameters:
ISR/IRQTC        ChannelDue pins
TC0TC002, 13
TC1TC0160, 61
TC3TC10none  <- this line in the example above
TC6TC204, 5
TC7TC213, 10
TC8TC2211, 12

I need to generate independent frequencies (5Hz - 2Khz) and duty cycles from at least 8 channels from the SAM3X8E in order to drive the printer's pins and I need to be sure if the processor will be able to do this.

Go Up