10 Low Power Design
This section provides detailed instructions on enabling low power modes, specifically Sleep/Standby and Deep Sleep/Backup modes, in the design.
10.1 Low Power Design on PIC32-BZ6 Devices
The PIC32-BZ6 examples and protocol stacks include support for Sleep and Deep Sleep Low Power modes within the Harmony framework for the PIC32-BZ6 devices. In this context, Sleep and Deep Sleep modes are equivalent to Standby and Backup modes, respectively. For consistency, this online reference guide refers to Sleep mode as Standby and Deep Sleep mode as Backup.
The following are the differences between Sleep and Deep Sleep Low Power mode:
- Sleep Low Power Mode:
- Application layer calls Bluetooth® Low Energy stack to enable advertising. The Bluetooth Low Energy stack continues sending and receiving advertising Tx and Rx periodically until the application layer disables it.
- The system continues to operate between Active mode and Sleep mode periodically based on the advertising Tx and Rx.
- The application layer can have peripherals running in Sleep/Standby Low Power mode.
- Deep Sleep Low Power Mode:
- Application layer calls Bluetooth Low Energy stack to enable Deep Sleep Advertisement. The Bluetooth Low Energy stack backs up advertisement parameters and data into backup SRAM and perform one time advertising event.
- After entering Deep Sleep Low Power mode, the system wakes up from reset, resulting in loss of all parameters. Backup SRAM (retained in Deep Sleep Low Power mode) stores the advertisement parameters for recovery after reset.
- Application layer puts the system into Deep Sleep Low Power mode and controls the wake-up time based on RTC timer (which runs in Deep Sleep Low Power mode).
- Once the system wakes up from Deep Sleep Low Power mode, the application layer triggers advertisement again by recovering the advertisement and data parameters stored in backup SRAM.
Low-power design of a system involves optimizing power both in hardware and software. To name a few:
- System Design:
- MLDO vs Buck mode (DC/DC), operating in the Buck mode yields to power consumption savings.
- Board design must allow measurement of the current consumed by the PIC32-BZ6 device alone, as multiple components can be present in the system.
- Ensure to verify device errata, with special attention to issues that affect device power consumption.
- Lower system clock speed from 64 MHz to 48 MHz; some applications can operate with a lower system clock speed of 48 MHz.
- Hardware Design:
- Configuring the transmitter
power at 0 dBm with Buck mode on at 64 MHz, the PIC32-BZ6 device draws 22.72 mA.
- At +12 dBm transmitter (Buck mode at 64 MHz) current consumption is 42.82 mA.
- At +4 dBm transmitter (Buck mode at 64 MHz) current consumption is 24.98 mA.
- At power up, all GPIO’s are inputs. Ensure to configure the unused GPIOs as input and pull down configuration.
- Configuring the transmitter
power at 0 dBm with Buck mode on at 64 MHz, the PIC32-BZ6 device draws 22.72 mA.
- For more details on software design, refer to the Low Power BLE Application Design from Related Links.
10.2 Low Power BLE Application Design
When developing a wireless Bluetooth® application, the advertisement and connection intervals managed by the BLE stack play a key role in determining when the device enters and exits sleep modes. The BLE stack supports two types of Low-power or Sleep modes:
- Sleep
- Deep Sleep
Sleep and Deep Sleep modes are equivalent to Standby and Backup modes, and these terms may be used interchangeably throughout this online reference guide.
The following table lists the various functionality/modules of the device that are available in the Low-power modes supported by the BLE stack.
Function | Sleep | Deep Sleep |
---|---|---|
Legacy ADV | Available | Available |
Extended ADV (coded PHY) | Available | Not supported |
BLE connection | Available | The device can begin advertising while in the Deep Sleep Low-power mode and, after establishing a BLE connection, transition to the Sleep low power mode. |
Peripherals | Available(1) | Limited wake-up sources are available |
Device wakes up from reset after exiting the Sleep mode | No | Yes |
System RAM | Available | Not retained |
Backup RAM | Not used by application or BLE stack | Available and used by application and BLE stack |
Timer used to manage sleep and wake-up times | Wireless subsystem manages time intervals based on ADV/connection intervals setup by API calls to BLE stack library | RTC |
ADV intervals recommended | No minimum/maximum ADV interval | Minimum ADV interval = 500 ms for power consumption savings |
Note:
|
10.2.1 Sleep/Standby Low Power Mode
Application Sleep Duration Control
The BLE stack enables the system to enter Low Power mode when there is no ongoing data transmission or reception, or during the BLE advertisement or connection intervals. The system sleep is managed automatically by the stack and cannot be directly controlled through a parameter or API call.
Device Operation in Sleep Low Power Mode
While the system is in the Sleep mode, it disables the system PLL clock and the stops system tick. The user must adjust the FreeRTOS timer to account for the duration spent in Low Power mode. The RTC timer can continue running during low power modes and corrects the FreeRTOS timer offset.
Factors such as BLE activity intervals, external interrupts (for example, GPIO), or peripheral interrupts determine the total time the system spends in Sleep mode. Peripherals permitted to operate in Standby or Sleep Low Power mode can continue functioning during the Sleep mode. In Deep Sleep or Backup mode, only specific peripherals, such as the RTC and INT0, can remain active.
Enabling Sleep/Standby Low Power Mode
Application Example | Description | Reference |
---|---|---|
BLE Sleep Mode Legacy Advertisements | Implements Sleep Low Power mode with periodic BLE legacy advertisements. | See BLE Legacy Advertisements from Related Links. |
BLE Extended Advertisements | Implements Sleep Low Power with periodic BLE extended (coded PHY) advertisements. | See BLE Extended Advertisements from Related Links. |
BLE Sensor | Implements sleep low power mode in a BLE connection oriented application and data exchange using Microchip transparent UART service. This application also has peripherals that are enabled to run in Standby/Sleep Low Power mode. | See BLE Sensor from Related Links. |
BLE Custom Service | Implements Sleep Low Power in a BLE connection oriented application and data exchange using custom service. This application does not have peripherals continuing to run in Standby/Sleep Low Power mode | See BLE Custom Service from Related Links. |
Generating Sleep Mode Code with MPLAB Code Configurator
- The user must enable the
system Sleep Mode in BLE stack H3 component configuration. After enabling
this, the system requests to enable dependent components like RTC (timer
source during sleep).
Figure 10-1. Enable Sleep Mode - Upon enabling Sleep mode, the
system automatically sets the FreeRTOS related settings.
- In the “RTOS
Configuration” drop-down menu, perfrom the following steps:
- Set the “Tick Mode” to Tickless_Idle. This allows the system to suppress periodic tick interrupts when idle, reducing power consumption.
- Set the “Expected idle time before sleep” to 5 (ms).
Figure 10-2. FreeRTOS Settings - Enabling Tick
Hook.
- Find the option labeled “Tick Hook.”
- Check the Use Tick Hook. This allows the user to add custom code that executes during each tick interrupt.
Figure 10-3. Tick Hook - RTC peripheral
library will be added and configured.Note: RTC counter must not be reset (
RTC_Timer32CounterSet()
) arbitrarily when the system is running.
- In the “RTOS
Configuration” drop-down menu, perfrom the following steps:
- The user must manually set
the RTC clock source, the following are the four options:
- FRC (±1% offset)
- LPRC (with larger offset, < ±5%)
- POSC – Candidate of the clock source (better clock accuracy)
- SOSC – Candidate of the clock source (better clock accuracy)
Note: Select POSC/SOSC as the RTC clock source, as other clock sources can impact BLE connection stability.Figure 10-4. Clock Configuration - Manually setting RTC clock
source – POSC.
- Choose “POSC” in “Clock Configuration”.
- The user must configure as illustrated in the following figure.
Figure 10-5. Manually Setting RTC Clock Source – POSC - Manually Setting RTC clock
source – SOSC, by turning on SOSC and then choose SOSC as illustrated in the
following figure.
Figure 10-6. Manually Setting RTC Clock Source – SOSC Note: The users can only select one clock source POSC or SOSC, steps mention how to choose either. - All unused pins in the
application needs to be set to Input mode and the pull-down must be
enabled for these pins.
- The user can configure this through pin configuration in Harmony3 Configurator. For more details, see the following figure.
Figure 10-7. Pin Settings - For more details on code generation, refer to the MPLAB Code Configurator (MCC) Code Generation from Related Links.
Sleep-Related Code Implementation Locations
Implementation | Location |
---|---|
BT Sleep Mode | BLE stack library |
System Sleep Mode | device_sleep.c |
Execute BT/System Sleep | app_idle_task.c |
RTC Based Tickless Idle Mode | app_idle_task.c |
User Code for Sleep/Standby Low Power Mode Entry
- In order for the system to
enter Sleep mode, the system needs to request Bluetooth® wireless subsystem to sleep. This is accomplished by
calling the
BT_SYS_EnterSleepMode()
API for BLE.Figure 10-8. BT_SYS_EnterSleepMode()
API - The API to call to ensure
subsystem is sleeping (inactive) or ready for system to enter Sleep mode is
the
BT_SYS_AllowSystemSleep
API.Figure 10-9. BT_SYS_AllowSystemSleep
API - If the expected sleep time is
greater than 5 ms, the system is allowed to enter Sleep mode by checking for
two conditions:
- Bluetooth subsystem is inactive.
eTaskConfirmSleepModeStatus()
returnseNoTasksWaitingTimeout
. For more information, refer to the eTaskConfirmSleepModeStatus in Reference Documentation from Related Links.
Note: The user can also add their own condition to be checked before system goes to sleep, for example, do not enter system sleep if data transmission over UART is active.Pseudo code in RTC based Tickless Idle Mode: ``` if ((BT_SYS_AllowSystemSleep()) && ( eTaskConfirmSleepModeStatus() != eAbortSleep ) && (user_condition)) { //Enter System Sleep Mode DEVICE_EnterSleepMode (); //RTC Based Tickless Idle Mode } ```
- When both the conditions as
mentioned in point 3 are met, enter RTC based Tickless Idle mode (stops the
system tick, uses the RTC timer to set the sleep time, disables
interrupts).
- The system enters Sleep mode after setting the RTC based Tickless
Idle mode by calling
Device_EnterSleepMode()
API and then the system executes the Wait for Interrupt (WFI) instruction.Figure 10-10. RTC Based Tickless Idle Mode Entry Sequence
- The system enters Sleep mode after setting the RTC based Tickless
Idle mode by calling
Exiting Sleep Mode
- RTC timeout
- BLE event
- GPIO interrupt
- Calling
DEVICE_ExitSleepMode()
API to begin the wake-up process. - After exiting the Sleep mode, interrupts must be re-enabled to allow execution of the interrupt service routines.
- Interrupts are initially
disabled because the system tick needs to be compensated (as required by
Tickless IDLE mode in FreeRTOS).
Figure 10-11. Exiting Sleep Mode Flow Chart

10.2.2 Deep Sleep/Backup Low Power Mode
Application Control of Sleep Duration
The user application controls how long the device remains in Deep Sleep Low Power mode. When the user sets the advertisement interval and enables Deep Sleep mode in the BLE_Stack component within the MCC, the system automaticalluy generates all necessary APIs for entering and exiting Deep Sleep. The user application must enable deep sleep advertising and manage the sleep and wake-up durations according to the chosen advertisement interval.
Unlike Sleep mode, which relies on a timer within the wireless subsystem to manage
sleep and wake-up periods, the Deep Sleep mode does not have access to this timer.
Instead, the RTC timer available during Deep Sleep wakes the device through its
interrupt, configured according to the Deep Sleep advertisement interval. The user
can transition the device into Deep Sleep Low Power mode after receiving the
BLE_GAP_EVT_ADV_COMPL
event from the BLE stack.
Device Operation in Deep Sleep Low Power Mode
When the application layer initiates the BLE stack to enable deep sleep advertising, the BLE stack backs up advertising parameters and application data into backup RAM and performs a one-time advertisement event.
The application layer then puts the system in Deep Sleep mode and controls deep sleep wake-up time using the RTC timer. The user is responsible for putting the system into Deep Sleep mode and controlling the wake-up using the RTC.
Based on the RTC Timer interval, the device wakes up from Deep Sleep Low Power mode. Exiting Deep Sleep mode is similar to Power-On Reset (POR). Backup RAM saves the adv parameters through a reset; upon wake-up, the BLE stack is able to continue advertising based on the data retained in backup RAM.
Device Start-Up and Initialization Timing
The start-up and initialization code for the device differs and optimizes to enable
fast completion of initialization after a reset caused by waking up from Deep Sleep
Low Power mode. The MCC generates the DEVICE_DeepSleepIntervalCal
API to calibrate the sleep duration based on the advertising interval chosen. The
device’s start-up and initialization procedures optimize to make the device enter
Deep Sleep Low Power mode as soon as possible. The device spends approximately 10 ms
during start-up and firmware initialization. The average start-up time for the
device is 1.5 ms. The firmware initialization time for various applications can
change based on the user’s choice of peripherals and clocks to initialize.
Maintaining I/O State after Reset in Deep Sleep Mode
DEVICE_ClearDeepSleepReg()
MPLAB Code Configurator Usage for Deep Sleep Mode
- In MPLAB® X IDE, open MCC and create a new Harmony project.
- Add required components to
the Project Graph.Note: The application being developed determines whether some components are optional.
Figure 10-13. Deep Sleep Mode Project Graph - Select the BLE Stack in the Project Graph tab.
- Configure the
following settings for “BLE stack” component. The slower the
advertising interval, the less current consumption. User can select
their desired interval.
Figure 10-14. BLE Stack Configuration Options Settings
- Configure the
following settings for “BLE stack” component. The slower the
advertising interval, the less current consumption. User can select
their desired interval.
- Select “RTC” component in the
Project Graph tab.
- Configure the
following settings for “RTC” component.
Figure 10-15. RTC Component Configuration Options Settings
- Configure the
following settings for “RTC” component.
- Go to MPLAB® Code Configurator>Harmony>Clock
Configuration.
- Go to Clock Diagram in MCC.
- Set LPCLK source to POSC. From the drop-down list, select POSC.
Figure 10-16. Clock Configuration Figure 10-17. Manually Setting RTC Clock Source – POSC Figure 10-18. POSC Configuration bits Generated after Code Generation - Go to MPLAB® Code Configurator>Harmony>Clock
Configuration.
- Go to Clock Diagram in MCC.
- Set LPCLK source to
SOSC. From the drop-down list, select SOSC.
Figure 10-19. Manually Setting RTC Clock Source – SOSC Figure 10-20. SOSC Configuration bits Generated after Code Generation
- Clock Switching mechanism , if LPCLK source is set as POSC clock source using clock configuration, the FW switch to LPRC as LPCLK source as POSC clock source is unavailable in Deep Sleep Low Power Mode.
Enabling Deep Sleep/Backup Low Power Mode
Application Example | Description | Reference |
---|---|---|
BLE Deep Sleep Advertising | On reset, the device starts in Deep Sleep mode. Pressing the SW1 button on the curiosity board starts the system’s Deep Sleep Advertisements. Once a central device connects, the device switches to Sleep Low Power mode. | See BLE Deep Sleep Advertising from Related Links. |
Recommendations for Deep Sleep Advertisement Mode
Ensure to use Deep Sleep Advertisement mode when the advertisement interval is >= 500 ms.
Supported BLE Advertisement Types in Deep Sleep Mode
When using Deep Sleep mode, the system supports BLE legacy advertisement types
ADV_IND
, ADV_SCAN_IND
,
ADV_DIRECT_IND_LOW
, and ADV_NONCONN_IND
.
Retaining Application Data in Backup RAM
The user must define the variable as persistent. Persistent variables are variables that the runtime start-up code must not clear, such as during a reset. The user must initialize a persistent variable as follows. The data read/write into backup RAM must be single word (4 bytes).
uint32_t __attribute__((persistent)) backup1;
The user firmware must not assign initial values for persistent variables.
Bootloader Firmware Authentication in Deep Sleep Mode
If firmware authentication is enabled in the bootloader, it checks for Firmware Authentication upon all types of resets like POR, BOR, and more. The device skips firmware authentication only when it wakes up from Deep Sleep Low Power mode.
Recommended RTC Clock Sources for Deep Sleep Mode
The recommendation is to use SOSC or LPRC as the clock sources when using the Deep Sleep mode.