Last Updated on : 2023-11-29 07:51:56download
This topic describes how power management works on Bluetooth sub-devices.
Power
Power is the rate at which work is done. The formula for power in watts is P = W/t, where W is the work done in some time t.
Electric power is the rate at which electrical energy is transferred by an electric circuit. The formula is P = U × I, where U is the voltage and I is the current.
1 kWh = 1,000W × 3,600s = 3,600,000J, indicating the energy delivered by one kilowatt of power for one hour.
Power consumption
Power loss can be interpreted in two ways:
The power required to operate the entire device, namely the input power, defined as the amount of electrical energy consumed per unit time.
The power consumption measured by input power minus output power.
Bluetooth Low Energy (LE) is interpreted in the first way.
The formula P = U × I
states that power consumption depends on voltage and current. Typically, the MCU is supplied with a constant voltage (such as 3.3V). Therefore, in Bluetooth LE, the average current is taken as the average power consumption.
The power consumption of Bluetooth LE devices can be affected by the following common factors:
Advertising interval: ranges from 20 ms to 10.24s, in units of 0.625 ms. Under the same conditions, the longer the advertising interval, the lower the power consumption.
Connection interval: ranges from 7.5 ms and 4s, in units of 1.25 ms. Under the same conditions, the longer the connection interval, the lower the power consumption.
Transmit power
Clock rate: 6 MHz, 12 MHz, 16 MHz, 24 MHz, 48 MHz, and 64 MHz are the common frequencies. Under the same conditions, the lower the clock rate, the lower the power consumption.
With a 32 kHz clock source, under the same conditions, the more accurate the external low-frequency oscillator, the lower the power consumption.
Voltage: generally ranges from 1.8V to 3.6V. Under the same conditions, the lower the voltage, the lower the power consumption.
Power supply mode: DC/DC or LDO Under the same conditions, power consumption is lower in DC/DC mode.
Length of advertising packet: Under the same conditions, the smaller the advertising packet, the lower the power consumption.
Wake-up time: Under the same conditions, the shorter the wake-up time, the lower the power consumption.
Peripherals: When measuring chip power consumption, try to exclude the impact of peripherals.
Besides the factors mentioned above, environmental factors can also affect the power consumption of Bluetooth LE devices.
Number of nearby central devices:
Measuring instrument: The base current of the instrument.
It is recommended to connect Bluetooth LE devices under test to power meters and observe the current in real time. The power meter shows the instantaneous current and the average current over a period of time.
The current waveform in the time domain visually represents the power consumption of a Bluetooth LE device, as shown below.
typedef VOID_T (*TUYA_PRE_SLEEP_CB)(VOID_T);
typedef VOID_T (*TUYA_POST_WAKEUP_CB)(VOID_T);
typedef struct {
TUYA_PRE_SLEEP_CB pre_sleep_cb;
TUYA_POST_WAKEUP_CB post_wakeup_cb;
} TUYA_SLEEP_CB_T;
pre_sleep_cb
: The handling function called before the device enters low power mode.post_wakeup_cb
: The handling function called after the device wakes up from low power mode.typedef struct {
BOOL_T flag;
UINT8_T mode;
} test_enter_sleep_t;
flag
: Indicate whether the device enters low power mode. 0x00
: Not in low power mode. 0x01
: In low power mode.mode
: Low power mode. 0x00
: Enter low power mode, without advertising. 0x01
: Enter low power mode, with advertising.API description
Register the sleep and wake-up callbacks.
OPERATE_RET tal_cpu_sleep_callback_register(TUYA_SLEEP_CB_T *sleep_cb);
Parameter description
Parameter | Description |
---|---|
sleep_cb | The sleep and wake-up callbacks: pre_sleep_cb : The application sleep callback, executed before sleep. post_wakeup_cb : The application wake-up callback, executed after wake-up. |
Data structure
typedef VOID_T (*TUYA_PRE_SLEEP_CB)(VOID_T);
typedef VOID_T (*TUYA_POST_WAKEUP_CB)(VOID_T);
typedef struct {
TUYA_PRE_SLEEP_CB pre_sleep_cb;
TUYA_POST_WAKEUP_CB post_wakeup_cb;
} TUYA_SLEEP_CB_T;
API description
Allow the device to enter sleep mode when idle.
This API only allows the device to enter low power mode. However, if a peripheral is active, the actual current of the device will not decrease as expected. The actual current of the device can be reduced only after the active peripheral is turned off.
VOID_T tal_cpu_allow_sleep(VOID_T);
API description
Force the device to wake up from sleep mode.
If a peripheral is turned off during sleep mode, it must be reinitialized when the device wakes up.
VOID_T tal_cpu_force_wakeup(VOID_T);
Register the low power handling function.
STATIC VOID_T tuya_pre_sleep_cb(VOID_T)
{
// to do
}
STATIC VOID_T tuya_post_wakeup_cb(VOID_T)
{
// to do
}
STATIC TUYA_SLEEP_CB_T tal_sleep_cb = {
.pre_sleep_cb = tuya_pre_sleep_cb,
.post_wakeup_cb = tuya_post_wakeup_cb,
};
OPERATE_RET tuya_init_last(VOID_T)
{
…………
tal_cpu_sleep_callback_register(&tal_sleep_cb);
…………
return OPRT_OK;
}
Test the low power feature.
typedef struct {
BOOL_T flag;
UINT8_T mode;
} test_enter_sleep_t;
typedef struct {
test_enter_sleep_t enter_sleep;
} test_param_t;
STATIC test_param_t test_param = {0};
STATIC TIMER_ID sg_test_enter_sleep_timer_id = NULL;
TUYA_WEAK_ATTRIBUTE VOID_T tal_sdk_test_init(VOID_T)
{
tal_sw_timer_create(tal_sdk_test_enter_sleep_handler, NULL, &sg_test_enter_sleep_timer_id);
…………
}
TUYA_WEAK_ATTRIBUTE OPERATE_RET test_group_powermanger(UINT8_T cmd, UINT8_T *cmd_data, UINT32_T cmd_data_len, UINT8_T *p_rsp_data)
{
TEST_GROUP_VARIABLE
switch (cmd) {
case TEST_CID_ENTER_SLEEP: {
test_param.enter_sleep.mode = cmd_data[0];
ret = tal_sw_timer_start(sg_test_enter_sleep_timer_id, 200, TAL_TIMER_ONCE);
TEST_RSP
} break;
default: {
} break;
}
return idx;
}
TEST_CID_ENTER_SLEEP
Instruct the device to enter low power mode through the host.
Reset the device and put it to sleep (without advertising):
The current:
Reset the device and set the advertising interval:
Enter low power mode (with advertising):
The current:
If you have any problems with host usage, see Logic Host User Guide.
If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback