Pages: [1]   Go Down
Author Topic: Timers in Arduino Duemilanove  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I have the Arduino Duamilanove with Atmega 328. Soon I will need to program a routine like this:

Arduino receive a "1" in a digital input.
  • Start a timer
  • Turn on some indicator leds

The signal at digital input returns to "0"
  • refresh indicator leds
Receive another "1" in the same digital input
  • Reset the timer and start counting again
  • Move a servo
  • refresh indicator leds

This last two steps of the program will be in a infinite loop but if the digital input stays "0" for a specific time (this is the main purpuse of the timer), I will need to move a servo to a "home" position, turn off the leds and try to save power at maximum.

The maxtime until gets in "power saver" will be variable and will need to be set by the user in the first cycle with a pot (probably I will need 1-10 minutes)

BUT the problem is that I never worked with the timers (just delays) but I would like to use the "hardware" timers of the atmega in order to continue refreshing the leds and doing stuff with the micro at the same time the timer still running, ¿where can I read about the use of this timers and probably power saving modes available for this chip? ¿I can achieve time counts as high as 10 minutes?

THANK YOU !!
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/forum/?id=11504

http://www.gammon.com.au/power
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

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


Nothing you've described requires the use of a dedicated hardware timer.
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check the BlinkWithoutDelay tutorial. The basic idea is to store timestamps, and just check "the time is now X, is there something I need to do?" each time through loop().
Logged

Pages: [1]   Go Up
Jump to: