...the world's most energy friendly microcontrollers Supply Voltage Monitoring AN0018 - Application Note Introduction Battery powered devices will eventually experience power loss unless the battery is replaced or recharged on a regular basis. In many such applications it is desirable to communicate that a power failure is imminent or to save data to non-volatile memory before the battery runs out. Some equipment may also require the source voltage to be within a certain range to operate safely. This application note will demonstrate how to use the EFM32 Reset Management Unit and the Voltage Comparator to read the reset cause register and monitor the supply voltage. This application note includes: • This PDF document • Source files (zip) • Example C-code • Multiple IDE projects ...the world's most energy friendly microcontrollers 1 Reset Management Unit The Reset Management Unit (RMU) of the EFM32 monitors the reset lines and ensures reliable operation by resetting the microcontroller if the supply voltage is insufficient or if certain events occur. Such events are activation of the external reset pin, watchdog timeout, kernel lockup or a system reset request. In addition, the RMU sets the reset cause register which can be used to determine the cause of the last reset at startup. 1.1 Power-on Reset and Brown-out Detection During power up, the EFM32 is held in reset until the supply voltage exceeds the threshold voltage, VBODextthr+, which is approximately 1.8v. Below this threshold, the voltage levels are undefined and safe operation can not be guaranteed. Once the voltage level rises above VBODextthr+, the power-on reset line is released and the microcontroller is powered up. If the supply voltage falls below the threshold voltage during operation, VBODextthr-, a "brown-out" has occurred. The brown-out detector will pull the microcontroller into reset to prevent unexpected program execution and data corruption. The EFM32 features two brown-out detectors, one for the external unregulated power supply and one for the regulated 1.8v rail. Once the RMU initiates a reset, the reset cause register is written to specify the reset source. 1.2 Reading the Reset Cause Register The reset cause register indicates which reset source triggered the last reset. Because several bits can be set at once and multiple reset causes can occur simultaneously, it is important to look for the reset cause in the following order to discover the main cause of reset: 1. 2. 3. 4. 5. Power-on reset Unregulated power brown-out reset Regulated power brown-out reset External and watchdog reset Lockup and system request reset When following this list from the smallest to largest number, the first indicated reset cause will be the actual reset cause. The reset cause register needs to be cleared after it has been read, otherwise it may indicate a wrong cause of reset at the next startup. To clear the reset cause register a 1 has to be written to the RCCLR bit in RMU_CMD and the HRCCLR bit in EMU_AUXCTRL. The EFM32 software library contains functions to read and clear the reset cause register. 2013-09-16 - an0018_Rev1.07 2 www.silabs.com ...the world's most energy friendly microcontrollers 2 Voltage Comparator The voltage comparator (VCMP) provides an easy way to warn if the supply voltage reaches a critical level. While the RMU automatically initiates a reset if the voltage level is too low, the voltage comparator compares the supply voltage to an internal bandgap reference. The supply voltage can be scaled in 64 steps to trigger the comparator output on voltage levels between 1.8 and 3.8 V. By adjusting the trigger level it is possible to take action before the microcontroller enters a brown-out reset or to verify that the supply voltage is within a specified range. The voltage comparator output can be read from the VCMPOUT bit in VCMP_STATUS. VCMP can also be configured to give interrupt on either falling and/or rising edge when the supply voltage crosses the threshold voltage. The voltage comparator is fully functional in EM0 to EM3. 2.1 Warm-up When enabling the voltage comparator, the output is undefined for a period of time, which is called the warm-up time (typically 10 µs. To avoid any glitches on the output during this period, the value of INACTVAL is selected as output value instead of the actual comparator output until warm-up is complete. An edge interrupt will occur if the output level toggles in the transition from INACTVAL to the voltage comparator output value. Setting the INACTVAL bit to the expected comparator output value therefore avoids this initial interrupt. Note that the device must stay in EM0 or EM1 during the warm-up. 2.2 Low Power Reference Enabling the low power reference (LPREF) will significantly reduce the power consumption compared to active mode at the cost of accuracy. Refer to the device datasheet for typical values. To ensure that a correct reference value is set, LPREF should be disabled until comparator warm-up is complete. When LPREF is enabled it is recommended to enable the half bias bit and set the bias configuration register to one of the lowest settings. Too high bias current can cause the reference value to drift and thus trigger the comparator output at higher voltage level than intended. 2.3 Voltage threshold levels The trigger level is configured by setting the TRIGLEVEL bits in the VCMP_INPUTSEL register. VCMP can be set to trigger at any voltage level supported by the EFM32 in steps of 0.034v, according to Equation 2. (p. 3) . If the MCU supply voltage is higher than Vtrig, the comparator output is 1 and 0 otherwise. TRIGLEVEL = (Vtrig - 1.667) / 0.034 (2.) The EFM32 software library includes a function to calculate TRIGLEVEL from a given voltage. Note that during type conversion the resulting TRIGLEVEL is rounded down to the nearest integer. 2.4 Response Time Changing the trigger level can be done while VCMP is enabled, but it is necessary to wait for the new input value to propagate through the comparator before using VCMPOUT. This delay is called the comparator response time and depends on the bias current configuration. Higher bias settings will shorten the response time. The bias settings are controlled by the BIASPROG and HALFBIAS bits in VCMP_CTRL. Checking if the comparator output value has been updated can be done by re-enabling VCMP. Disabling and enabling the voltage comparator will cause a new warm-up cycle to begin. 2.5 Threshold hysteresis Small fluctuations in the supply voltage can be filtered out by enabling hysteresis on the comparator input. If enabled, the comparator will not trigger before the supply voltage level is approximately 20mV above or below the reference voltage. See Figure 2.1 (p. 4) 2013-09-16 - an0018_Rev1.07 3 www.silabs.com ...the world's most energy friendly microcontrollers Figure 2.1. Voltage Comparator Hysteresis In POS In NEG + 20m V In NEG In NEG - 20m V Tim e VCMPOUT without hysteresis VCMPOUT with hysteresis 2013-09-16 - an0018_Rev1.07 4 www.silabs.com ...the world's most energy friendly microcontrollers 3 Energy Optimization Considerations The voltage comparator consumes as little as 100nA while enabled with the lowest bias settings. Using an interrupt driven approach is simple and ensures that a critical low voltage will be detected before the MCU is forced into a brown-out reset. However, some energy sensitive applications running on battery will usually see a slowly decreasing supply voltage. Having the voltage comparator constantly enabled is therefore unnecessary. A solution is to enable the voltage comparator on regular intervals to check the output voltage level and leave the voltage comparator disabled in between. If the application features a real-time clock or similar, the voltage comparator can be sampled at specified intervals. 2013-09-16 - an0018_Rev1.07 5 www.silabs.com ...the world's most energy friendly microcontrollers 4 Software Examples The following examples shows how to read and clear the reset cause register and use the voltage comparator to monitor the supply voltage. 4.1 Example 1: Reset cause register and interrupt driven VCMP In this example the reset cause register is read and cleared immediately after startup. The voltage comparator is initialized and the MCU is entering EM1 to wait for comparator warm-up to finish. Because the warm-up period is given as a number of clock cycles, a lower energy mode can not be used as HFPERCLK is disabled below EM1. The MCU then enters EM2 waiting for the supply voltage to trigger an interrupt. This example is limited to EM2 to allow the LCD to be active. Without the LCD-part this example will also work in EM3. 4.2 Example 2: Polled supply voltage monitoring This example constantly polls the voltage comparator output to check if the supply voltage is at a certain level. In a real application, the polling interval can be increased to reduce the current consumption. The trigger level alternates between a high and low limit to determine if the supply voltage is within the allowed range. After changing the trigger level it is necessary to wait for the comparator response time to pass to ensure that the correct comparator output value is used. 2013-09-16 - an0018_Rev1.07 6 www.silabs.com ...the world's most energy friendly microcontrollers 5 Revision History 5.1 Revision 1.07 2013-09-03 New cover layout 5.2 Revision 1.06 2013-05-08 Added software projects for ARM-GCC and Atollic TrueStudio. 5.3 Revision 1.05 2012-11-12 Adapted software projects to new kit-driver and bsp structure. Added software support for Tiny and Giant Gecko STKs. 5.4 Revision 1.04 2012-04-20 Adapted software projects to new peripheral library naming and CMSIS_V3. 5.5 Revision 1.03 2011-10-21 Updated IDE project paths with new kits directory. 5.6 Revision 1.02 2011-05-18 Updated projects to align with new bsp version. 5.7 Revision 1.01 2010-11-16 Changed example folder structure, removed build and src folders. Added chip-init function. Updated register defines in code to match newest efm32lib release. 5.8 Revision 1.00 2010-09-22 Initial revision. 2013-09-16 - an0018_Rev1.07 7 www.silabs.com ...the world's most energy friendly microcontrollers A Disclaimer and Trademarks A.1 Disclaimer Silicon Laboratories intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Laboratories products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Laboratories reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Laboratories shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products must not be used within any Life Support System without the specific written consent of Silicon Laboratories. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Laboratories products are generally not intended for military applications. Silicon Laboratories products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons. A.2 Trademark Information Silicon Laboratories Inc., Silicon Laboratories, the Silicon Labs logo, Energy Micro, EFM, EFM32, EFR, logo and combinations thereof, and others are the registered trademarks or trademarks of Silicon Laboratories Inc. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders. 2013-09-16 - an0018_Rev1.07 8 www.silabs.com ...the world's most energy friendly microcontrollers B Contact Information Silicon Laboratories Inc. 400 West Cesar Chavez Austin, TX 78701 Please visit the Silicon Labs Technical Support web page: http://www.silabs.com/support/pages/contacttechnicalsupport.aspx and register to submit a technical support request. 2013-09-16 - an0018_Rev1.07 9 www.silabs.com ...the world's most energy friendly microcontrollers Table of Contents 1. Reset Management Unit ............................................................................................................................. 1.1. Power-on Reset and Brown-out Detection .......................................................................................... 1.2. Reading the Reset Cause Register .................................................................................................... 2. Voltage Comparator ................................................................................................................................... 2.1. Warm-up ....................................................................................................................................... 2.2. Low Power Reference ..................................................................................................................... 2.3. Voltage threshold levels ................................................................................................................... 2.4. Response Time .............................................................................................................................. 2.5. Threshold hysteresis ....................................................................................................................... 3. Energy Optimization Considerations .............................................................................................................. 4. Software Examples .................................................................................................................................... 4.1. Example 1: Reset cause register and interrupt driven VCMP ................................................................... 4.2. Example 2: Polled supply voltage monitoring ....................................................................................... 5. Revision History ........................................................................................................................................ 5.1. Revision 1.07 ................................................................................................................................. 5.2. Revision 1.06 ................................................................................................................................. 5.3. Revision 1.05 ................................................................................................................................. 5.4. Revision 1.04 ................................................................................................................................. 5.5. Revision 1.03 ................................................................................................................................. 5.6. Revision 1.02 ................................................................................................................................. 5.7. Revision 1.01 ................................................................................................................................. 5.8. Revision 1.00 ................................................................................................................................. A. Disclaimer and Trademarks ........................................................................................................................ A.1. Disclaimer ..................................................................................................................................... A.2. Trademark Information .................................................................................................................... B. Contact Information ................................................................................................................................... B.1. ................................................................................................................................................... 2013-09-16 - an0018_Rev1.07 10 www.silabs.com 2 2 2 3 3 3 3 3 3 5 6 6 6 7 7 7 7 7 7 7 7 7 8 8 8 9 9 ...the world's most energy friendly microcontrollers List of Figures 2.1. Voltage Comparator Hysteresis ................................................................................................................. 4 2013-09-16 - an0018_Rev1.07 11 www.silabs.com