Supply Voltage Monitoring


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.

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. Power-on reset
2. Unregulated power brown-out reset
3. Regulated power brown-out reset
4. External and watchdog reset
5. 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.
 

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)
Figure 2.1. Voltage Comparator Hysteresis
image
 

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.
 

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.



































No comments:

Post a Comment