Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> Interrupt, timer, frequency
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1213187023

Message started by julienb on 06/11/08 at 12:23:42

Title: Interrupt, timer, frequency
Post by julienb on 06/11/08 at 12:23:42
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?

Title: Re: Interrupt, timer, frequency
Post by barragan on 06/11/08 at 19:50:50
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

 }
}

Title: Re: Interrupt, timer, frequency
Post by julienb on 06/11/08 at 20:17:46
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...

Title: Re: Interrupt, timer, frequency
Post by barragan on 06/11/08 at 21:46:36
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.

Title: Re: Interrupt, timer, frequency
Post by rux on 06/16/08 at 14:13:19
Hi!

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

.r

Title: Re: Interrupt, timer, frequency
Post by julienb on 06/16/08 at 14:15:56
What do you do with this library?

Title: Re: Interrupt, timer, frequency
Post by rux on 06/16/08 at 14:22:30
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

Title: Re: Interrupt, timer, frequency
Post by julienb on 06/16/08 at 14:31:33
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 ..  :P

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

thanks

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.