DUE Timer not working if started within an ISR


I would appreciate hep with this pesky problem.

I am using Ivan Seidel's DUE Timer library and made a couple of successful sketches. My Timer checks on the value of a variable, and if > 0, does stuff. The Timer is started within an ISR and then stopped at the end of its handler.

I have already used "volatile" to declare that variable.

The Timer however NEVER starts. The statement to start the Timer within the ISR is just ignored.

I even tried just running the timer all the time. When I did that, the program stalls once the interrupt fires and the variable is changed within the ISR.

Any help is appreciated.

These are the drawbacks of using libraries if you don't really know what's going on inside….

A Timer Counter doesn't take a variable, maybe a library function takes a variable.

Try to understand how Timer Counters work by using there registers and you won't have anymore issues with timers.

How about posting your code.


Thank you, here is the code that gives problems. The Timer never starts.

#include <DueTimer.h>

#define interruptPin 2

volatile int preTriggerCount = 0;         //volatile because used in ISR

unsigned long interruptTime[50];

void setup()
  attachInterrupt(digitalPinToInterrupt(interruptPin), maintPreTrig, FALLING);
  preTriggerCount = 0;


void loop()


void maintPreTrig()
  //Executed upon receipt of interrupt from micro

  preTriggerCount = preTriggerCount + 1 ;

  interruptTime[preTriggerCount] = millis();



 void checkPreTriggers()
//Called to clear old preTriggers
  while (preTriggerCount > 0)
    for (int i = 1; i <= 10; i++)

      if (((millis() - interruptTime[i]) > (checkPreTrigTimer * 1000)) && (preTriggerCount >= 1))
        preTriggerCount = preTriggerCount - 1;

Your code doesn't compile.

A few thoughts:

  • interruptPin seems to receive a switch(?), a press on this switch should trigger maintPreTrig() on a falling edge, therefore interruptPin should be declared as input_pullup somewhere ?

  • Are you sure preTriggerCount will never exceed 50 ?

Thank you @ard_newbie.

Sorry, my code is too long so I just attached a snippet.

1) interruptPin is set to LOW by another Arduino. This for sure is working.

2) Yes, preTriggerCount is set to 0 if > 10

I am almost sure the problem occurs due to interrupt conflicts but I know very little about this stuff ...

I understand that:

you need to start a timer from inside a function triggered by an attachinterrupt, right ?

This timer will trigger an interrupt after a period. Inside this interrupt, you will stop this timer, right ?