My platform is the Arduino DUE. I know that the timer counts up to a certain value, then generates an interrupt. In the Arduino DUE, you can specify the timer value. In other words, you can specify the frequency of the intterupts. You can do this via the TC_SetRC(tc, channel, rc) function.

My question is how code flows in general. Obvisouly the arduino runs the setup function first. After that it jumps to loop. But when does tghe timer starts counting down? When you first jump to loop? Can you figure out how many instructions will be executed in the loop function, before a call to a timer interrupt is performed, for the given frequency you have specified?

After the interrupt is fired, all the code in the interrupt is run. Then code flow jumps back to loop()? And when the timer starts counting again? At the same time the code jumps to loop?

If you set up the timer interrupt frequnecy too high, do you run the risk of having code in you loop functin not run at all? (If, for example, you have lots of code inside the loop()).

In that case, would it be wise to put code that you would generally put inside the loop(), inside a timer interrupt?


The timers starts when it is enabled. Either explicitly or via one of The calls to timer functionality.

Once the interrupt fires, current execution is preserved and the isr execution starts. Once you exit the isr, the loop execution resumes from where it pauses

Yes, if your use fires too frequently or takes too long to execute your loop may never gets executed.

  • Thanks! I just saw that the timers never stop counting too! I add this here for reference – user1584421 Jun 22 '17 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.