interrupts in arduino due

am writing code for position control of bldc motor using arduino due . I use two interrupts in my code one is external edge interrupt and another is timer interrupt . individually both the interrupts are working fine but when I assemble the code then the code is not running, there is no error message during compilation . I think there is problem in timer interrupt or in interrupt service routine , I spend lot of time to resolve the problem but am still at the same point . I posted the code below , help me out , thanks in advance.

arduino_fourm.ino (1.87 KB)

Some thoughts:

Splite your project into several sub projects and use simple debug methods:

  • Trigger an interrupt from an external pulse and blink an LED to check that it works
  • Trigger an interrupt from a timer counter at a 1 Hz frequency and blink an LED to check that it works

Don’t use magic numbers because it makes your code very difficult to debug, use header files and Sam3x datasheet. Inside the TC Handler, read TC status register if you want the interrupt to fire again.

There is a confusion with Timer counter names: Timer counter 0 channel 0 is TC0 for the Handler, Timer counter 0 channel 1 is TC1 for the Handler, Timer counter 0 channel 2 is TC2 for the Handler, … and so on.

Here is an example sketch to trigger an interrupt at a 3 KHz frequency thru Timer Counter 0 Channel 0:

void setup() {

  /*************  Timer Counter 0 Channel 0 to generate 3 KHz interrupts ************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID27;                      // Timer Counter 0 channel 0 IS TC0. TC0 power ON

  TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  // MCK/2, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC;      // UP mode with automatic trigger on RC Compare

  TC0->TC_CHANNEL[0].TC_RC = 14;  //Frequency = (Mck/2)/TC_RC  Hz

  TC0->TC_CHANNEL[0].TC_IER = TC_IER_CPCS;  // Interrupt on RC compare

  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable
  NVIC_EnableIRQ(TC0_IRQn);  // Enable interrupts


void loop() {


void TC0_Handler(void) {

  uint32_t status = TC0->TC_CHANNEL[0].TC_SR;  // Clear status register to fire again

  /*     your code   */

And post your code between code tags </>.