Sleep timer inaccuracy

kostyan5
Posts: 32
Joined: Mon Mar 06, 2017 3:16 pm

Sleep timer inaccuracy

Postby kostyan5 » Tue Jul 11, 2017 1:53 pm

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 510 times


I posted about this issue back in April with Rev 0 (see here for reference: viewtopic.php?f=2&t=1758)

WiFive
Posts: 1033
Joined: Tue Dec 01, 2015 7:35 am

Re: Sleep timer inaccuracy

Postby WiFive » Tue Jul 11, 2017 5:19 pm

Sparkfun thing has 32khz crystal, do you?

kostyan5
Posts: 32
Joined: Mon Mar 06, 2017 3:16 pm

Re: Sleep timer inaccuracy

Postby kostyan5 » Tue Jul 11, 2017 5:21 pm

We do. We're also ran this with RTC clock set to internal.

WiFive
Posts: 1033
Joined: Tue Dec 01, 2015 7:35 am

Re: Sleep timer inaccuracy

Postby WiFive » Tue Jul 11, 2017 5:24 pm

So with rtc source set to 32khz external or 150khz internal you get this same type of result? Can you post code?

ESP_igrr
Posts: 794
Joined: Tue Dec 01, 2015 8:37 am

Re: Sleep timer inaccuracy

Postby ESP_igrr » Tue Jul 11, 2017 5:44 pm

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.

kostyan5
Posts: 32
Joined: Mon Mar 06, 2017 3:16 pm

Re: Sleep timer inaccuracy

Postby kostyan5 » Thu Jul 13, 2017 2:03 pm

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.

kostyan5
Posts: 32
Joined: Mon Mar 06, 2017 3:16 pm

Re: Sleep timer inaccuracy

Postby kostyan5 » Mon Jul 17, 2017 4:26 pm

Running with external 32kHz didn't seem to help.

WiFive
Posts: 1033
Joined: Tue Dec 01, 2015 7:35 am

Re: Sleep timer inaccuracy

Postby WiFive » Mon Jul 17, 2017 9:17 pm

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?

kostyan5
Posts: 32
Joined: Mon Mar 06, 2017 3:16 pm

Re: Sleep timer inaccuracy

Postby kostyan5 » Mon Jul 24, 2017 9:39 pm

I believe one of the recent commits (RTC overflow) fixed the timing issue.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 9 guests