Pages: [1] 2   Go Down
Author Topic: Waking Arduino once per minute on timer based int  (Read 3336 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi - I am fairly new and am struggling to figure out for a battery powered application how to sleep the Arduino but wake it say once per minute to do some work, then sleep again.  I dont want to use external interrupt as that would require more circuitry and 555 timer or similar and would use valuable battery power.

I think I need to use the timers and prescalers, and that I need to use a timer based interrupt to trigger which will wake the chip up again, but how?

Surely someone must have done this?

Hope someone can help with this!

Cheers...Sean
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use an RTC, and take advantage of the programmable square wave output.
Logged

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

OK - do you have a suggested RTC chip that can generate a suitable square wave?

I dont need exactly 1 minute intervals - timing is not critical, but battery life is so any way to wake the arduino regularly without consuming much power is what I need.

Thanks in advance!

Using the timers and interrupts within the arduino the slowest trigger I could find was about 60 times per second!
Logged

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

Have you looked at this...

http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/

- Brian
« Last Edit: April 28, 2009, 11:19:02 pm by bcook » Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking of DS1678:
http://www.maxim-ic.com/appnotes.cfm/an_pk/3643

Logged

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

Thanks florinc - I will check out the datasheet.

I just noticed though that Timer1 is 16 bit though rather than 8 bits, so if I can use that like the Timer2 interrupt presumably it will overflow much slower, maybe any seconds or more?

Spent a couple of hours reading the Mega168 datasheet and cant figure out how to do it though...arghhh!

Anyone a master of the timers, overflows, sleep and interrupts?
Logged

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

Brian - having perfected a low power 555 timer circuit to wake my device every minute, and convinced myself thats the way to go, I just studied the Nightingale program you posted above and it works!  It only gets me a max of 8 second sleep but I can easily link 8 or so toigether to get close to a minute, without the need for extra electronics.

Thanks for the suggestion.  My only concern is that I dont fully understand how it works, but more time on the datasheet will no doubt help!
Logged

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

Bear in mind that...

  • The watchdog timer is not terribly accurate.  My current test board (based on the AT90USB162) is slow by about 7½%.  I believe the watchdog timer can be off by ±10%.
  • The Nightingale example uses SLEEP_MODE_PWR_DOWN.  In this mode, with this processor, all the timers are shutoff and remain off after the processor wakes.

The documentation for this processor is a bit sparse on the watchdog details.  I plan to spend some this week researching (especially SLEEP_MODE_PWR_DOWN).  If you're interested, I'd be happy to publish details when I have them.
« Last Edit: May 05, 2009, 08:11:56 pm by bcook » Logged

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

Coding Badley - definitely - anything you can find would be of interest for sure, and vice versa.  I'm using Arduino pro mini.
Like I said above what I really want is to wake the chip from sleep periodically (say once per minute).  Power consumption is critical as I need several years life from 2 x AA, so it needs to be as efficient as possible.  
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A back of the napkin calculation on this requirement (2 AA (unchanged, I assume) batteries for several years) results in a max current of less than 100uA, doesn't it? Also, assuming that the batteries don't deplete by themselves, this is a pretty tough requirement. (I used 8760 hours in a year, 2000mAh per battery).

Logged

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

Yep - but the chip is only taking 50uA in sleep mode, and thats the Arduino pro mini which has an annoying tiny red LED that I need to desolder!

Providing I can keep the sleep to 99.9% and only awaken do process quickly then sleep I should be ok.

But I guess you can see why I really want the chip to sleep for a minute or more rather then the 8 seconds that I have managed so far...

My current solution is to sleep for 8 secs, then wake and add a counter.  If gthe counter reaches 8 then zero it and do processing, else sleep.  It gives me 64 seconds which I can live with, but it does mean that I am waking up much more often than I want which ultimately wastes power.
Logged

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

With the right settings, the watchdog can be set to fire after 112 seconds (almost two minutes).  

Do you need help getting that to work?

- Brian
Logged

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

Brian - definitely - that would be a great help.

How do I do it?  I have the Nightingale program working and giving me 8 seconds sleep.  How can this be made longer?  I've search everywhere on this but got to the conclusion that 8 seconds is the limit?
Logged

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

First, some things I've discovered...

  • The watchdog timer is very inaccurate.  My test processor is typically long by about 11%.
  • The watchdog timer is affected by temperature.  The clock runs a bit faster when the processor is cooler.
  • Shorter delays run longer.  Note: I cannot fathom why this one is true.  I suspect there's a bug in my measurement code.
  • There's some "jitter".  I've seen differences of as much as 0.2% between successive tests.
  • There's some "drift".  I've seen differences of 1% over the course of a day.
  • A high pin driving an LED slows the clock by about 0.02%.


Now for your question...

Quote
How do I do it?

You have to set the "Watchdog Timer Clock Divider".  I've put code here...

http://arduino.pastebin.com/m10fedf12

...that should help.  The code should let you set the time-out to any valid value.


Some notes about the code...

  • I currently only have an AT90USB82 processor for testing.  I have no idea if the code works with other processors.
  • I tried to follow the datasheet to the letter but it's a bit contradictory and a bit vague.  I could easily have gotten something wrong.  Test the code thorougly and use it at your own peril.
  • The "WatchdogTimeoutInfo" array and its type definitions "TrdWatchdogTimeoutInfo" and "TrdSleepDuration" are not used; you can remove them.
  • Before running the code, change "PIN_LED_ONBOARD" to a pin with an LED connected.  I believe Arduino compatible boards have an onboard LED on pin 13.


Good luck,
Brian
« Last Edit: May 10, 2009, 03:10:17 pm by bcook » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Brian,
Your code is great, but unfortunately the ATMega168 and ATMega328 (which I believe come with the Arduino Duemilanove, which I have on order) do not have watchdog clock dividers, unlike the AT90USB82 that you are using.

This means that the maximum time between watchdog interrupts for the Arduino Duemilanove is 8 seconds... Bummer!

Looks like the best I can do is what r55boy suggested... waking it up every 8 seconds to increment a counter then putting it back to sleep again... On every n wake ups execute the main code.
Logged

Pages: [1] 2   Go Up
Jump to: