Features:light-sleep and deep-sleep under sdkV0.9.5

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Features:light-sleep and deep-sleep under sdkV0.9.5

Postby costaud » Mon Feb 02, 2015 3:52 am

Update on 150203:
update tools to disable RF during flash booting.
esp_iot_sdk_tools_update_150203.zip
(5 KiB) Downloaded 512 times


-----------------------------------------------------------------

We make some improvement for the sleep mode under sdkv0.9.5,especially for light-sleep and deep sleep.

1.light-sleep: we fixed some bugs in the previous version so that the light sleep current performs much better in station mode.
Functioning:
Light-sleep works in station mode and already connected to a AP.In light-sleep mode , the chip would shut down the rf module as well as the cpu for sometime(tens or hundreds of milliseconds).It depends, the lower system will judge whether the chip is idle and can be set into light-sleep mode automatically. Two kinds of factors would decide the light-sleep schedule.a)whether the system task is idle in the following period.b)the AP beacon interval. As a station device , the beacon is totally decided by the AP and esp8266 chip would be self-adaptive to match the beacon so that it can keep the connection alive,receive the wifi packets and stay a low power mode.
APIs:
a)bool wifi_set_sleep_type(LIGHT_SLEEP_T) : To enable the light-sleep function, not get into light-sleep mode directly, but just enable the function and let the system decide when it can sleep.
b).void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state) : (parm i is the gpio number) To enable the wake-up-by-gpio function.In this situation, interrupt mode can just be set to GPIO_PIN_INTR_LOLEVEL, GPIO_PIN_INTR_HILEVEL.That means for gpio,only level interrupt can wake up the chip.Since the cpu will shut down , so the chip would not response to the uart or spi data, we can wake it up via gpio first.
Sometimes the current ranges because the chip has to response to the AP's management packets to obey the protocol.
We tested the working current of light-sleep under dtim3,the average current should be 1.5mA(the max sample points is 512,so the current is (1.682*512+0.5*88)/600=1.5mA):
pad_v2_182_26M_2_DTIM3.png
pad_v2_182_26M_2_DTIM3.png (37.69 KiB) Viewed 12357 times


2.deep-sleep: We add some wake-up-mode options for deep-sleep.
Application and Usage:
In some power-sensitive situation, like battery powered system, we can still reduce the power consumption during the wake-up procedure. For example , for a sensor device , we don't need to connect to ap and send data every time. We can just read the sensor data and save to the rtc memory and upload them once we get a dozen of data.So that we don't need the rf module enabled( only power on the cpu part) until we want to upload data.
APIs:
bool system_deep_sleep_set_option(uint8 option): Call this API before deep-sleep to set the following wake-up mode.
option==0: disable rf calibration for a certain number of times , according to the 108th byte of esp_init_data_default.bin.
For example , if the 108th byte is set to 8, the chip will only do these rf operation once out of every 8 wake-up procedures.
The power consumption is 44.77mA * 280ms(Note that X-axis is scaled)
dsleep_disable_rfcal_2ms_26m_qio_f40m__003.png
dsleep_disable_rfcal_2ms_26m_qio_f40m__003.png (29.56 KiB) Viewed 12357 times

option==1: do rf calibration during wake-up.Power consumption is larger.
70mA * 440ms(Note that X-axis is scaled)
dsleep_normal_rfcal_2ms_26m_qio_f40m__004.png
dsleep_normal_rfcal_2ms_26m_qio_f40m__004.png (29.49 KiB) Viewed 12357 times

option==2: not do rf calibration during wake-up.
option==4: disable rf when the chip wake up. This provides a better current performance.
The power consumption is 23mA * 250ms(Note that X-axis is scaled):
dsleep_close_rf_2ms_26m_qio_f40m__001.png
dsleep_close_rf_2ms_26m_qio_f40m__001.png (29.79 KiB) Viewed 12357 times


Moreover,we can still find some ways to reduce the wake-up current by the following steps.
esp_iot_sdk_tools_update_150203.zip
(5 KiB) Downloaded 512 times

Step1:
Add this function before getting into deep-sleep to set the next wake-up mode.
deep_sleep_set_option(uint8 option)
option == 4; disable rf during next wake-up
option == 1; normal mode
The sample code:

Code: Select all

//Sample code with RTC memory:
//===============================================
#define DATA_NUM 5
#define RTC_CNT_ADDR 120
#define DSLEEP_TIME 5000000
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());
    uint32 rtc_cnt;
    system_rtc_mem_read(RTC_CNT_ADDR, &rtc_cnt, 4);
    os_printf(" rtc_cnt : %d \n\r",rtc_cnt);
    if(rtc_cnt>=DATA_NUM){
        rtc_cnt = 0;
        system_rtc_mem_write(RTC_CNT_ADDR,&rtc_cnt, 4);
        deep_sleep_set_option(1); // normal mode for next wake-up to upload data
        //read sensor data and record in rtc memory
        system_deep_sleep(DSLEEP_TIME);
    }else if(rtc_cnt==0){
        rtc_cnt+=1;
        system_rtc_mem_write(RTC_CNT_ADDR,&rtc_cnt, 4);
        deep_sleep_set_option(4);
        //normal mode, add upload-data function and deepsleep
    }else{
        rtc_cnt+=1;
        system_rtc_mem_write(RTC_CNT_ADDR,&rtc_cnt, 4);
        deep_sleep_set_option(4); //disable rf for the next wake-up
        //read sensor data and record in rtc memory
        system_deep_sleep(DSLEEP_TIME);
    }
}
//===============================================

Step2:
Replace the "Makefile" in the sdk root path(esp_iot_sdk_v0.9.5/Makefile ) with the attached Makefile.
Add the "add_disable_rf_cmd.py" to esp_iot_sdk_v0.9.5/tools
Step3:
Compile...gen_misc.sh
The script would generate a binary file named eagle.flash_disable_rf.bin or user1.xxx.old_disable_rf.bin(for upgrade version).
The final power consumption is 14.7mA * 250ms(Note that X-axis is scaled):
sensor_v095_addcmd_004.png
sensor_v095_addcmd_004.png (30.86 KiB) Viewed 12357 times

We will release a sample sensor application later.

alonewolfx2
Posts: 12
Joined: Sun Oct 26, 2014 6:14 am

Re: Features:light-sleep and deep-sleep under sdkV0.9.5

Postby alonewolfx2 » Tue Feb 03, 2015 3:52 am

how can we set dtim in at example? can you share some code?

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Re: Features:light-sleep and deep-sleep under sdkV0.9.5

Postby costaud » Thu Feb 05, 2015 1:54 pm

alonewolfx2 wrote:how can we set dtim in at example? can you share some code?


In station mode , the dtim mode is determined by the router.

In softap mode , we haven't provided the api yet, we will arrange to provide it in the next sdk.

tve
Posts: 123
Joined: Sun Feb 15, 2015 4:33 pm

Re: Features:light-sleep and deep-sleep under sdkV0.9.5

Postby tve » Mon Jun 29, 2015 1:16 am

Do I understand correctly that the esp8266 can only wake up from light-sleep using the timer or a gpio input change? Does this mean, for example, that it cannot wake up from an incoming character on the UART? Is the UART powered-down during light sleep?

Who is online

Users browsing this forum: No registered users and 3 guests