Pages: [1]   Go Down
Author Topic: Timer Interrupts  (Read 800 times)
0 Members and 1 Guest are viewing this topic.
Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 209
Posts: 13025
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Processor?  Clock speed?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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().
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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". 
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 4389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Singapore
Offline Offline
Newbie
*
Karma: 4
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-cool
Logged

Pages: [1]   Go Up
Jump to: