程序员人生 网站导航

学习NodeMCU的低功耗休眠

栏目:综合技术时间:2015-07-30 14:11:01

大多数IOT利用是电池供电的,在电池电量1定的情况下(体积、环境等限制),耗电量决定了产品的寿命,决定了产品是不是实用。本文主要目的是学习关于NodeMCU的休眠机制。

NodeMCUAPI


https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#nodedsleep


node.dsleep()

Description

Enter deep sleep mode, wake up when timed out.

Syntax

node.dsleep(us, option)

Note: This function can only be used in thecondition that esp8266 PIN32(RST) and PIN8(XPD_DCDC aka GPIO16) areconnected together. Using sleep(0) will set no wake up timer, connecta GPIO to pin RST, the chip will wake up by a falling-edge on pinRST.
option=0, init data byte 108 is valuable;
option>0,init data byte 108 is valueless.
More details as follows:
0,RF_CAL or not after deep-sleep wake up, depends on init data byte108.
1, RF_CAL after deep-sleep wake up, there will belargecurrent.
2, no RF_CAL after deep-sleep wake up, there will only besmall current.
4, disable RF after deep-sleep wake up, just likemodem sleep, there will be the smallest current.

Parameters

  • us: number(Integer) or nil,sleep time in micro second. If us = 0, it will sleep forever. If us= nil, will not set sleep time.

  • option: number(Integer) or nil.If option = nil, it will use last alive setting as default option.

Returns

  • nil

Example

--do nothing node.dsleep() --sleep μs node.dsleep(1000000) --set sleep option, then sleep μs node.dsleep(1000000, 4) --set sleep option only node.dsleep(nil,4)


NodeMCU源代码

https://github.com/nodemcu/nodemcu-firmware/blob/fa7cf87832fc9905df98f9435c149d40f314dee8/app/modules/node.c


static int node_deepsleep( lua_State* L)

{

s32 us, option;

//us = luaL_checkinteger( L, 1 );

// Set deleep option, skip if nil

if ( lua_isnumber(L, 2) )

{

option = lua_tointeger(L, 2);

if ( option < 0 || option >4)

return luaL_error( L, "wrongarg range" );

else

deep_sleep_set_option( option);

}

// Set deleep time, skip if nil

if ( lua_isnumber(L, 1) )

{

us = lua_tointeger(L, 1);

// if ( us <= 0 )

if ( us < 0 )

return luaL_error( L, "wrongarg range" );

else

system_deep_sleep( us );

}

return 0;

}


https://github.com/nodemcu/nodemcu-firmware/blob/84a9ab35a8eb9b4ae2229bba7b2626c2a285818d/include/user_interface.h


bool system_deep_sleep_set_option(uint8option);

void system_deep_sleep(uint32time_in_us);


ESP8266 Specifications

http://www.seeedstudio.com/document/pdf/ESP8266%20Specifications%28Chinese%29.pdf

10电源管理


芯片可以调成以下状态:



  • 关闭(OFF):CHIP_PD管脚处于低功率状态。RTC失效。所有寄存器被清空。

  • 深度 睡眠( DEEP_SLEEP ) : RTC开着,芯片的其他部份都是关着的。RTC内部recovery memory 可保存基本的WiFi连接信息。

  • 睡眠(SLEEP):只有RTC在运行。晶体振荡器停止。任何部位唤醒(MAC、主机、RTC计时器、外部中Sleep)将使唤醒全部芯片。

  • 唤醒(WAKEUP):在这类状态下,系统从睡眠状态下转为起动(PWR)状态。晶体振荡器和PLL均转为使能状态。

  • 开启状态(ON):高速时钟可以运行,并发送至各个被时钟控制寄存器使能的模块。各个模块,包括CPU在内,履行较低电平的时钟门控。系统运作时,可以通过WAITI指令关闭CPU内部时钟。



The following data are based on a 3.3V power supply, ambienttemperature 25C and use the internal regulator measured. [1] Allmeasurements are made in the absence of the SAW filter, the antennainterface is completed. [2] all transmit data based on 90% dutycycle, continuous transmission mode in the measured.

Mode

Min

Typical

Max

Units

802.11b, CCK 1Mbps, POUT=+19.5dBm

 

215

 

mA

802.11b, CCK 11Mbps, POUT=+18.5dBm

 

197

 

mA

802.11g, OFDM 54Mbps, POUT=+16dBm

 

145

 

mA

802.11n, MCS7, POUT =+14dBm

 

135

 

mA

802.11b, packet size of 1024 bytes, ⑻0dBm

 

60

 

mA

802.11b, packet size of 1024 bytes, ⑺0dBm

 

60

 

mA

802.11b, packet size of 1024 bytes, ⑹5dBm

 

62

 

mA

Standby

 

0.9

 

uA

Deep sleep

 

10

 

mA

Saving mode DTIM 1

 

1.2

 

mA

Saving mode DTIM 3

 

0.86

 

mA

Shutdown

 

0.5

 

uA


https://nurdspace.nl/ESP8266#Technical_Overview


其他资源

Low Power ESP8266

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐