Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Maxim Yachnyy
#16970 Hello everyone.

I'm writing my own firmware for esp8266, so it will be main an only one CPU in my device. I need to realize a realtime clock. When my device is powered off, it is still working on a small battery. When I see power disapperance I'm writing current time in RTC block of memory and then calling system_deep_sleep with a fixed sleeping time, for example 10 seconds. When theese 10 second pass my device wakes up, but if the power is still off my sleeping cycle repeates.
The problem is: system_deep_sleep makes my system to sleep not 10 seconds but 10 seconds plus some time that is taken by system_deep_sleep function to prepare system for deep sleep. I don't know the amount of this time. But this small amount of time introduces some error in my realtime calculation. The more cycles sleep-wake I have, the more error I get.
This problem could be solved, if I could read the value of RTC register after system wake up, but loader or system startup resets it.

Maybe amyone have some ideas how to save time correctly during deep sleep?
User avatar
By Makuna
#17000 What accuracy are you looking for out of your RTC?

Most uControllers are not accurate to be used for RTC of 1second a day error due to many reasons. Temperature changes effect the crystal and thus the clock; so powering down that little cpu heater can effect the crystal. Often the circuit and crystal weren't "designed" to be highly stable in the first place. Further, most of the sleep features were designed for power saving not cycle accuracy. WDT are notoriously inaccurate.
User avatar
By Maxim Yachnyy
#17014
eriksl wrote:IIRC there is a timer that remains ticking even in deep sleep. Are you sure you need the deep sleep? ;-)

The only timer that is ticking in deep sleep is RTC. But it is reset while system is starting after deep sleep, so I can't read it's value after sleep to obtain real sleep time. And yes, I need deep sleep.