LowPowerLab Forum

Hardware support => Low Power Techniques => Topic started by: gregcope on June 11, 2016, 08:05:31 AM

Title: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: gregcope on June 11, 2016, 08:05:31 AM
Hi,

I am planning on sleeping 8sec twice, and then doing a sensor check.

Every hour, give or take a few minutes, I want to check another sensor.

I understand Milis() is not updated when asleep, so are there any simple patterns for this?

Do I need to manually track time with milis() when awake, and just add the sleep amount on to get now?

Any example code?
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: Felix on June 13, 2016, 08:18:47 AM
You can adjust base on the amount of time you sleep.
You can count the # of 8s sleep cycles and figure out when you got to 1hour etc.
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: gregcope on June 13, 2016, 09:26:39 AM
You can adjust base on the amount of time you sleep.
You can count the # of 8s sleep cycles and figure out when you got to 1hour etc.

I am doing the latter.

In the former, and you talking about running a different variable, that gets updated from millis() and sleep periods?
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: Felix on June 13, 2016, 10:43:37 AM
I have multiple examples where millis is still used while sleeping the MCU, one such example is the mailbox notifier where I do try to update the time passed.
If you sleep for 8s then add 8000 to your millis counter.
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: gregcope on June 13, 2016, 10:49:20 AM
Thanks

Missed that in the mailbox notifier.  Will look again.
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: Felix on June 13, 2016, 10:51:42 AM
Yeah, it's basically just a matter of keeping track of the time you sleep.
If you just need to wake every 1 hour, sleep for 450 cycles, then send your messages, repeat, etc, no need to mess with millis() at all.
Title: Re: resetting Millis() ~ need to do something every hour 1 hour approx
Post by: gregcope on June 13, 2016, 11:12:33 AM
Just doing counts of cycles is fine for most things

But at certain points I go an do things that may take variable time (like GPS fix or send an SMS) and hence it can get a bit out of whack.

I could get that back by either accurate millis measuring or not hard coding the count cycles and rejigging those as required.

Will check your millis example