Home Tutorials Brown-Out Detection in ARM Projects Explained with Examples

Brown-Out Detection in ARM Projects Explained with Examples

by shedboy71

In embedded systems, reliable operation requires not just the right software but also stable power conditions. Microcontrollers are made to work within a certain voltage range. If the supply voltage drops below this range, the microcontroller may act in ways that are not expected.

The CPU might not follow the right instructions, memory writes might get messed up, and peripherals might not work right. These conditions are especially dangerous because they can damage the system state without causing an immediate reset. Brown-out detection is a hardware feature that keeps this from happening by watching the supply voltage and forcing a reset when it drops below a safe level.

Brown-out detection is an important part of making strong and fault-tolerant systems on ARM Cortex-M microcontrollers, like those made by STMicroelectronics.

What Is Brown-Out Detection?

A brown-out happens when the supply voltage drops below the level needed for normal operation but doesn’t go all the way to zero. In contrast, a full power loss means that the system just shuts down.

The microcontroller may keep running during a brown-out, but it won’t always work. The brown-out detection circuitry keeps an eye on the supply voltage and compares it to a set threshold. If the voltage goes below this level, the system is reset or kept in reset until the voltage goes back up to a safe level.

This mechanism makes sure that the microcontroller never runs in a voltage range that is too high. Instead of continuing to run with possibly corrupted data, the system is put into a known and controlled state.

After the voltage stabilises, the device restarts without any problems, which lowers the chance of long-term problems or strange behaviour.

Why Brown-Out Detection Matters

Voltage instability happens more often in real life than many developers think. As the battery runs out, the voltage of battery-powered systems slowly drops.

When motors, radios, or other peripherals turn on, systems with high current loads may suddenly lose voltage. Even regulated power supplies can have short dips in power because of changes in load or the environment.

If you don’t have brown-out detection, these situations can cause failures that are hard to notice and fix. A system might seem to work only sometimes, damage stored data, or get stuck in invalid states that don’t go away even when the power comes back on.

Brown-out detection stops these problems by making sure that the system either runs within safe limits or completely resets.

This is especially important for applications that involve data logging, communication, or control systems, where mistakes can have big effects.

Brown-Out Detection on ARM Cortex-M Systems

Most ARM Cortex-M microcontrollers include built-in brown-out detection, often referred to as a Brown-Out Reset (BOR) or Power Voltage Detector (PVD). These features are implemented in hardware and operate independently of the main CPU, ensuring that they remain active even when the system is unstable.

The BOR typically triggers a reset when the supply voltage drops below a fixed or configurable threshold. The PVD, on the other hand, can generate an interrupt when the voltage crosses a threshold, allowing the firmware to take action before a full reset occurs. Together, these features provide both protection and flexibility.

Configuration of these features is usually done through option bytes or control registers, depending on the microcontroller family. Once enabled, they operate automatically without requiring continuous software intervention.

Configuring Brown-Out Reset (BOR)

Brown-Out Reset is often configured at the hardware or firmware level using option bytes. These settings determine the voltage threshold at which the reset is triggered.

Higher thresholds provide greater protection but may cause resets in systems where the supply voltage naturally fluctuates near the lower limit. Lower thresholds allow more tolerance but increase the risk of operating in unsafe conditions.

In many STM32 devices, BOR levels can be selected during programming. Once configured, the microcontroller will automatically reset whenever the supply voltage drops below the selected level. This reset behaves like a standard system reset, restarting the program from the reset handler.

Because BOR operates entirely in hardware, it does not require runtime code to function. However, it is still important to understand how it interacts with the rest of the system, particularly during startup and reset handling.

Example: Detecting a Brown-Out Reset

After a reset occurs, it is often useful to determine whether it was caused by a brown-out event. STM32 microcontrollers provide status flags that indicate the source of the reset. By checking these flags during startup, the firmware can take appropriate action, such as logging the event or adjusting system behavior.

#include "stm32f4xx.h"

static uint8_t brownout_detected = 0;

void check_reset_source(void) {
    if (RCC->CSR & RCC_CSR_BORRSTF) {
        brownout_detected = 1;
    }

    // Clear reset flags
    RCC->CSR |= RCC_CSR_RMVF;
}

int main(void) {
    check_reset_source();

    if (brownout_detected) {
        // Handle brown-out event (log, safe mode, etc.)
    }

    while (1) {
        // Main application
    }
}

In this example, the firmware checks whether the BOR reset flag is set. If it is, the system can respond accordingly. This might include entering a safe mode, delaying operation until the voltage stabilizes, or recording the event for diagnostics.

Using the Power Voltage Detector (PVD)

While BOR forces a reset, the Power Voltage Detector provides a more proactive approach. It allows the firmware to detect a voltage drop before it reaches the reset threshold.

This enables the system to take preventive action, such as saving data, shutting down peripherals, or preparing for a controlled reset.

The PVD can be configured to generate an interrupt when the voltage crosses a specified threshold. This interrupt is handled by the firmware, giving it a brief window to respond.

Example: PVD Interrupt for Voltage Monitoring

The following example demonstrates how to configure the PVD to generate an interrupt when the voltage drops below a threshold.

#include "stm32f4xx.h"

void pvd_init(void) {
    // Enable power interface clock
    RCC->APB1ENR |= RCC_APB1ENR_PWREN;

    // Configure PVD level (example level)
    PWR->CR |= PWR_CR_PLS_LEV5;

    // Enable PVD
    PWR->CR |= PWR_CR_PVDE;

    // Enable EXTI line for PVD
    EXTI->IMR |= EXTI_IMR_IM16;
    EXTI->RTSR |= EXTI_RTSR_TR16;

    // Enable interrupt in NVIC
    NVIC_EnableIRQ(PVD_IRQn);
}

void PVD_IRQHandler(void) {
    if (EXTI->PR & EXTI_PR_PR16) {
        EXTI->PR |= EXTI_PR_PR16;

        // Voltage drop detected
        // Take action: save data, disable peripherals, etc.
    }
}

int main(void) {
    pvd_init();

    while (1) {
        // Normal operation
    }
}

In this example, the system receives an interrupt when the voltage drops below the configured threshold. This allows the firmware to react before a full brown-out reset occurs, providing an opportunity to protect critical data or transition to a safe state.

Combining BOR and PVD for Robust Design

The most reliable systems often use both BOR and PVD together. The PVD provides early warning, allowing the firmware to prepare for a voltage drop, while the BOR ensures that the system resets if the voltage continues to fall. This combination creates a layered defense against power instability.

For example, when the PVD interrupt is triggered, the firmware might save important data to non-volatile memory and shut down non-essential peripherals.

If the voltage continues to drop, the BOR will reset the system, ensuring that it does not operate in an unsafe state. When power returns, the system can recover using the saved data.

Practical Considerations

When setting up brown-out detection, it’s important to choose the right voltage thresholds based on how the system is running. The threshold should be high enough to keep things from working wrong, but low enough to keep things from resetting when the voltage changes.

The design of the power supply is also very important. Using decoupling capacitors, voltage regulators, and proper grounding can help keep the supply stable and lower the chances of brown-out conditions.

People should think of brown-out detection as a safety feature, not a replacement for good power design.

Testing is necessary to make sure the system works properly when the voltage is low. This could mean pretending that the voltage drops and watching how the system reacts. Checking both PVD interrupts and BOR resets helps make sure that the system works well in real life.

 

Share

You may also like