Sleep Alarm Library

1. The library

Sleep alarm is a small library allowing the program to put Ansteron Board into sleep mode and wake up after a given amount of time. When Ansteron Board is in sleep mode, its power consumption is reduced by up to two third of running mode. The sleep time is in second, maximum 18 hours at 1 second step.

There is only one function to use, sleep_alarm(time);, which will make the CPU sleep for time second(s). After that amount of time, the CPU will wake up and the next command will be executed. Note that time is int, maximum value is 65535.


This example is a simple temperature logger. Ansteron board will read temperature from DS18S20 sensor and then save to internal EEPROM. Temperature values are two bytes each, high byte will be written first then the low byte. Ansteron Board will then go to sleep for 60 seconds to save power (could be battery powered) then wake up and take the next temperature sample.

Notice that the value of address variable will stay unchanged during sleep. A switch or similar component can be added to start/stop logging. Data in EEPROM can be viewed with EEPROM Editor, a tool included in Ansteron IDE. Besides, a graph of temperature data can be plotted with Ansteron Grapher, another tool of Ansteron IDE.

2. Note

The library is implemented based on Watchdog timer, a peripheral of CPU. Due to low power requirement, sleep time is not accurate. Time errors is up to 10% and varies depend on temperature and CPU voltage. A reference clock used at programming time to calibrate the value giving to sleep_alarm() function can reduce error.

I/O pins drivers will stay on when Ansteron Board is in sleep mode, most of other CPU peripherals are off.