6

I have a need for timer interrupt (for the sake of this exercise - say I need to execute something every second)

I found code in many places on the internets that does this using ISR for 328/Uno. (or specifically for other chips) But of course that does not work on other chipsets.

Is there a portable timer library that works across many/most/all arduino boards/chipsets?

For now it is a simple project - I have no other motors or tones, etc.

In my current project I have conditional compiles for different chipsets, to set up a callback/interrupt but would rather use a library that hides this all.

Tim
  • 131
  • 1
  • 1
  • 9

1 Answers1

1

I think it would be hard, or impossible, to make such a library. Already there are problems with pin-change interrupt libraries, and Software Serial (which uses pin-change interrupts).

Plus, to have a generic "callback" might tempt people to do things which they shouldn't anyway in an ISR, like do serial printing.

Let's say you choose to use a spare timer (eg. Timer 1). You have the issue now that you won't be able to do (some) PWM output because that uses Timer 1.

The closest would be to lever off the existing millis() code and just have a test in loop to see if the time interval is up, and then call a function - however that wouldn't be an ISR.

Nick Gammon
  • 38,901
  • 13
  • 69
  • 125