Power-fail comparator
The power-fail comparator (POF) can provide the CPU with an early warning of impending power failure. It will not reset the system, but give the CPU time to prepare for an orderly power-down.
The comparator features a hysteresis of VHYST, as illustrated in Figure 4. The threshold VPOF is set in register POFCON. If the POF is enabled and the supply voltage falls below VPOF, the POFWARN event will be generated. This event will also be generated if the supply voltage is already below VPOF at the time the POF is enabled, or if VPOF is re-configured to a level above the supply voltage.
If power-fail warning is enabled and the supply voltage is below VPOF the power-fail comparator will prevent the NVMC from performing write operations to the NVM. See NVMC — Non-volatile memory controller for more information about the NVMC.
To save power, the power-fail comparator is not active in System OFF or in System ON when HFCLK is not running.
Does the NRF51822 support BOD (Brown-Out Detection) interrupt? Or is there a power-down holding register?
https://devzone.nordicsemi.com/f/nordic-q-a/46460/does-the-nrf51822-support-bod-brown-out-detection-interrupt-or-is-there-a-power-down-holding-register
Power-fail comparator
https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html&cp=3_1_0_17_3&anchor=unique_1736318573
POFWARN Example?
https://devzone.nordicsemi.com/f/nordic-q-a/2218/pofwarn-example/9361?focus=true#9362
代码实现
// 初始化配置
// enable pof
err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled);
APP_ERROR_CHECK(err_code);
// pof event is triggered in 2.1v
err_code = sd_power_pof_threshold_set(POWER_POFCON_THRESHOLD_V21);
APP_ERROR_CHECK(err_code);
// 添加事件回调处理
static void sys_evt_dispatch(uint32_t sys_evt)
{
Motor_PowerEventHandler(sys_evt);
}
// 处理事件
void Motor_PowerEventHandler(uint32_t sys_evt)
{
switch(sys_evt)
{
case NRF_EVT_POWER_FAILURE_WARNING:
{
NRF_LOG_PRINTF("[NRF_EVT_POWER_FAILURE_WARNING]\r\n");
// disable pof
// sd_power_pof_enable(POWER_POFCON_POF_Disabled);
}break;
default:
{
}break;
}
}