Page 1 of 1

Sleep timer inaccuracy

Posted: Tue Jul 11, 2017 1:53 pm
by kostyan5
I'm seeing weird behavior from the deep sleep timer.

Setup:
1. Using pretty much the exact same circuit as Sparkfun's ESP32 Thing (https://www.sparkfun.com/products/13907), except we have Rev 1 of silicon.
2. ESP-IDF as of June 12, 2017
3. Wake up, perform wifi scan, record data (including current RTC time and reset cause) to flash, go to sleep for 5 minutes.

Code: Select all

esp_deep_sleep_enable_timer_wakeup(300 * 1000000);
4. Repeat 2 for a while
5. Download contents of flash and compare time difference between successive wake ups.

Results:
1. Sleep period seems to be very inaccurate and at times all over the place (see attached chart).
2. Reset cause for all but a handful wake ups was 5 (deep sleep).
3. At some point, sleep time seems to drop to close to 0 for a significant amount of time, then at sleeps for about 10 hours, starts jumping wildly, and then resettles at 10 minutes for some reason.
Screen Shot 2017-07-11 at 9.52.21 AM.png
Screen Shot 2017-07-11 at 9.52.21 AM.png (154.18 KiB) Viewed 11219 times
I posted about this issue back in April with Rev 0 (see here for reference: https://esp32.com/viewtopic.php?f=2&t=1758)

Re: Sleep timer inaccuracy

Posted: Tue Jul 11, 2017 5:19 pm
by WiFive
Sparkfun thing has 32khz crystal, do you?

Re: Sleep timer inaccuracy

Posted: Tue Jul 11, 2017 5:21 pm
by kostyan5
We do. We're also ran this with RTC clock set to internal.

Re: Sleep timer inaccuracy

Posted: Tue Jul 11, 2017 5:24 pm
by WiFive
So with rtc source set to 32khz external or 150khz internal you get this same type of result? Can you post code?

Re: Sleep timer inaccuracy

Posted: Tue Jul 11, 2017 5:44 pm
by ESP_igrr
Can you record sleep time or wakeup time using an external clock? I would like to understand whether the sleep time actually varies like this, or the sleep time is correct but you are getting incorrect values from gettimeofday.

It would be help if you post the code. I have fixed some inaccuracies related to gettimeofday a few weeks ago, and my tests did not show such behavior after the fix. I can try running your code to see if I can reproduce this issue.

Re: Sleep timer inaccuracy

Posted: Thu Jul 13, 2017 2:03 pm
by kostyan5
The issue seems to be most prominent when device is in motion. When I had the device sitting on my desk overnight, they timestamps were all within 5 seconds of expected 5 mins. But when I took the device with me on my skateboard ride, the wake ups would occur at random intervals between 0 and 5 mins. Not sure what would be the best way to measure wake up times externally while on the move.

I was running with internal RC for RTC source. I'm trying external 32KHz next.

Re: Sleep timer inaccuracy

Posted: Mon Jul 17, 2017 4:26 pm
by kostyan5
Running with external 32kHz didn't seem to help.

Re: Sleep timer inaccuracy

Posted: Mon Jul 17, 2017 9:17 pm
by WiFive
One simple thing you can do is record the total time of your mobile test and compare the number of recorded wakeups to the number of expected wakeups. What kind of enclosure do you use when mobile? Are you able to reproduce the erratic results in the lab by adding vibration or some other mechanical stimuli?

Re: Sleep timer inaccuracy

Posted: Mon Jul 24, 2017 9:39 pm
by kostyan5
I believe one of the recent commits (RTC overflow) fixed the timing issue.