Author Topic: resetting Millis() ~ need to do something every hour 1 hour approx  (Read 1596 times)

gregcope

  • Full Member
  • ***
  • Posts: 172
  • Country: gb
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?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6022
  • Country: us
    • LowPowerLab
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #1 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.

gregcope

  • Full Member
  • ***
  • Posts: 172
  • Country: gb
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #2 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?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6022
  • Country: us
    • LowPowerLab
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #3 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.

gregcope

  • Full Member
  • ***
  • Posts: 172
  • Country: gb
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #4 on: June 13, 2016, 10:49:20 AM »
Thanks

Missed that in the mailbox notifier.  Will look again.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6022
  • Country: us
    • LowPowerLab
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #5 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.

gregcope

  • Full Member
  • ***
  • Posts: 172
  • Country: gb
Re: resetting Millis() ~ need to do something every hour 1 hour approx
« Reply #6 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