Go Down

Topic: Timer Interrupts (Read 846 times) previous topic - next topic

baum

How can I trigger a timer interrupt to, say, go off every 10 seconds? I know I can make and external interrupt on pins 2+3, but can I do software interrupts like this? Or will I need a 555 timer in astable mode?

Coding Badly

Processor?  Clock speed?

retrolefty


How can I trigger a timer interrupt to, say, go off every 10 seconds? I know I can make and external interrupt on pins 2+3, but can I do software interrupts like this? Or will I need a 555 timer in astable mode?


Use http://www.arduino.cc/playground/Main/MsTimer2

Lefty

baum

Quote
Processor?  Clock speed?


I just want to have an interrupt triggered every x seconds, which will then run a specified function, just like in attachIntterupt().

baum

Sorry lefty... I posted while you posted.

Thanks for that! It's exactly what I had in mind. So it has a min. resolution of 1 ms?

Hauge

Dont know about timer2 resolution, but if you dont think you are able to program your own timed event interrupt then you can "cheat" by manually change the code in MsTimer2.cpp  to fit your needs with a suitable program like "source editor". 

floresta

Quote
...change the code in MsTimer2.cpp  to fit your needs ...
Not exactly.  That's a good idea for short delays but for his needs he will have to use the interrupt to update a software counter and use that counter to determine when to run his specified function.  I think he already figured this out.

Don

retrolefty

Quote
Thanks for that! It's exactly what I had in mind. So it has a min. resolution of 1 ms?


Yep, the time variable is a long, so max timed interrupt is like 55 days or so. I used it my 5x5x5 led cube to generate 2msec interrupts. Worked great.

Lefty


dania25

I find aikoevents to be a really simple way of making things happen at regular intervals- regardless of how long those particular events take or how long the rest of your program takes to loop.  I was using before a messy code filled with millis() and interrupts to determine how long each event/iteration took, then adding times together to do one simple thing- which is repeat a task reliably at the same interval.  It was impossible to get accuracy- and not to mention made the code a mess. 

Simple=good  8)

Go Up