Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › Interrupt, timer, frequency

Page Index Toggle Pages: 1
Interrupt, timer, frequency (Read 13962 times)
06/11/08 at 12:23:42

julienb   Offline
Junior Member
wiring AND arduino owner
France

Posts: 81
**
 
Hello,

Does it exist a version of MsTimer2for Wiring  ?
Or another library or code to use the board interrupt to trigger an action every N milliseconds.

Could someone help me?
 

IP Logged
 
Reply #1 - 06/11/08 at 19:50:50

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
This example shows how to do something every 3500 milliseconds:
     

long previousTime = 0;

void setup()
{
 previousTime = millis(); // just initialize the time counter.
}

void loop()
{
 if((millis() - previousTime) >= 3500 ) {  // if 3500 milliseconds have passed since started counting
   previousTime = 0; // reset the time counter

   // insert here the code you want to execute every 3500 ms

 }
}
 
IP Logged
 
Reply #2 - 06/11/08 at 20:17:46

julienb   Offline
Junior Member
wiring AND arduino owner
France

Posts: 81
**
 
hi barragan,
Is  this method similar to interrupt service routine ?

I read carefully that: http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/ but I probably didn't understand well all.
however, millis() is timer0 based.
I guess the method used by the mstimer2 library is more efficient in the case we have to handle things very constantly.

I guess that this lib could be adaptated for wiring board.
could it be interesting ?
I'd like to do that but I saw wiring.h and another *.h included in the mstimer2.cpp & mstimer2.h .. so I don't really know what to do.
it should involved the studies of differences between atmega128 and atmega168...

so...
 

IP Logged
 
Reply #3 - 06/11/08 at 21:46:36

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Yes it will behave as you expect, you just insert there the code you want to do every certain time. This will work for you in the mean time, it will be good to have a Timer library in the future but it will take some time to prepare it.
 
IP Logged
 
Reply #4 - 06/16/08 at 14:13:19

rux   Offline
YaBB Newbies
wired emotions
nyc

Posts: 12
*
 
Hi!

I've actually been using arduino's metro library for this with success.
http://www.arduino.cc/playground/Code/Metro

.r
 

.rux
IP Logged
 
Reply #5 - 06/16/08 at 14:15:56

julienb   Offline
Junior Member
wiring AND arduino owner
France

Posts: 81
**
 
What do you do with this library?
 

IP Logged
 
Reply #6 - 06/16/08 at 14:22:30

rux   Offline
YaBB Newbies
wired emotions
nyc

Posts: 12
*
 
it's basically a metronome. every x time u get a trigger. one thing u can actually do is also build a counter for it , instead of using millis using the intervals defined by u.

.r
 

.rux
IP Logged
 
Reply #7 - 06/16/08 at 14:31:33

julienb   Offline
Junior Member
wiring AND arduino owner
France

Posts: 81
**
 
ok.
the only things that makes me running into the ISR is the things I read about performance.
But I'm not especially in love with ISR ..  Tongue

Ok for the lib you use.
I read on the Arduino website.

thanks
 

IP Logged
 
Page Index Toggle Pages: 1