How to configure the interrupt handler for the POF. POFWARN example code.

Hi,

I am using nrf52832 board and I want to add the code for power fail comparator POF. I want to put my device into deep sleep mode if the battery voltage is reduced below 2.4 volts. Can you please share me the POF example code to generate the POFWARN event. 

1. I have also referred the ticket: (2) POFWARN Example ? - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

But I am getting error for the function softdevice_sys_evt_handler_set(sys_evt_dispatch) What are the header files need to be included to resolve this error.

2. Can we also use this function to enable the POF? nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V24)

How to configure the handler for the POFWARN event?

3. When the POFWARN event is generated, I want to put my device into deep sleep mode. Do I need to directly call the function sd_power_system_off() when the event hits?

or Do I need to disable all the device configuration before calling sd_power_system_off()?

Details:

Hardware board: nRF52832

SDK: nRF5_SDK_15.3.0_59ac345

IDE: Segger Embedded Studio

Thans in advance,

Naveed

  • Hi,

    I have configured the power fail comparator as shared below.

    To add-on to the issue, I am getting SOFTDEVICE: INVALID MEMORY ACCESS error while running the code. Please let me know what I have missed in the configuration of POF. Is my configuration correct?

    When the code runs to the function  nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V23), I am getting SOFTDEVICE: INVALID MEMORY ACCESS error.

    What should be the priority set to the POF handler in the function, NRF_SDH_SOC_OBSERVER(m_soc_observer,0, pof_evt_dispatch,NULL)..? I have set it to '0' do I need to change it?

    I want to put the device into deep sleep mode when the voltage falls below the 2.3V(changed from 2.4V). Is my code correct? 

    Please let me know how to resolve this. 

    Details:

    Hardware board: nRF52832

    SDK: nRF5_SDK_15.3.0_59ac345

    IDE: Segger Embedded Studio

    Thanks in advance,

    Naveed

  • Hi,

    1. I have also referred the ticket: (2) POFWARN Example ? - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    But I am getting error for the function softdevice_sys_evt_handler_set(sys_evt_dispatch) What are the header files need to be included to resolve this error.

    That post is very old and several tings has changed since then. To get SOC events in recent SDK versions you use NRF_SDH_SOC_OBSERVER (in the same way as NRF_SDH_BLE_OBSERVER si used to register a handler for BLE events). You can serach for NRF_SDH_SOC_OBSERVER in the SDK to see examples of how it is used. (I see from your second post that you found that).

    2. Can we also use this function to enable the POF? nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V24)

    How to configure the handler for the POFWARN event?

    Yes, with this functino you can enable (or disable) POF and set the threshold, as both of these are configurd in the POFCON register that this function assesses. Note that this function can only be used without a SoftDevice (see later in this reply for details).

    3. When the POFWARN event is generated, I want to put my device into deep sleep mode. Do I need to directly call the function sd_power_system_off() when the event hits?

    or Do I need to disable all the device configuration before calling sd_power_system_off()?

    POFWARN will just trigger an event (and block any writes to flash). If you want to enter system OFF mode, you need to do that yourself by calling sd_power_system_off(). Wakeup from system-off would be in form of a reset, but you should make sure that the system is in a safe state before entering system off mode (depending on your product). And in most designs it would make sense to set GPIOs to sensible values etc (for instance so that you don't drain the battery further by having a LED active or similar).

    Naveed said:
    To add-on to the issue, I am getting SOFTDEVICE: INVALID MEMORY ACCESS error while running the code. Please let me know what I have missed in the configuration of POF. Is my configuration correct?

    The power registers are not directly accessible when a SoftDevice is enabled, and that is why you get the invalid memory access error (see Hardware peripherals). When using a SoftDevice (after it has been enabled), you must use the sd_power_pof* functions.

    Naveed said:
    What should be the priority set to the POF handler in the function, NRF_SDH_SOC_OBSERVER(m_soc_observer,0, pof_evt_dispatch,NULL)..? I have set it to '0' do I need to change it?

    This is not interrupt priority, just the priority/order of the SoC handler subsribers. So it probably does not matter, but if it does, it depends on which handler you want to run first (in case you have multiple). The lowst number (0) is the highest priority.

    Naveed said:
    I want to put the device into deep sleep mode when the voltage falls below the 2.3V(changed from 2.4V). Is my code correct? 

    The problem is that you need to switch to SoftDevice APIs, and as long as you do that, I expect it should work.

  • Hi,

    Thanks for your reply. It was very helpful, and it worked for me.

    I want to put my device into sleep mode. when the event NRF_EVT_POWER_FAILURE_WARNING hits. I am calling sd_power_system_off() function to put the device in the sleep mode.

    when the device enters into sleep mode, I can see the blue and red led are continuously blinking non-stop. In the code I have configured the LED's using LEDS_CONFIGURE(LEDS_MASK). But as expected when the device enters in the sleep mode it should stop executing. Do I need to disable all the device configuration (gpio's, LEDs, and timers, etc) before calling sd_power_system_off()?

    When I am testing the code in the debug mode it is working fine. But when I have flashed the code into the board, I can see the Leds blinking continuously.

    Please let me know how to resolve this.

    Thanks

  • Hi,

    I have referred few tickets in the nordic forum to put the device into sleep mode correct me that we have to follow the below steps.

    void sleep_mode_enter(void)
    {
            uint32_t err_code;

            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);


            err_code = bsp_btn_ble_sleep_mode_prepare();
            APP_ERROR_CHECK(err_code);


            err_code = sd_power_system_off();
            APP_ERROR_CHECK(err_code);
    }

    OR,

    Should I directly call sd_power_system_off()?

    I want my device to turn ON only when the input is more than the threshold set that is 2.3V. If it is below the threshold it should enter into sleep mode.

    When I run the code in the release mode without debugger, I am still getting the RED LED blinking continuously with a certain period in sleep mode. As it blinks continuously it still consumes the current in the sleep mode. 

    Expected output: all the application functions shall stop and LED's will be OFF.

    Actual output: RED LED is blinking continuously which still consumes power.

    In your previous reply,

    [POFWARN will just trigger an event (and block any writes to flash). If you want to enter system OFF mode, you need to do that yourself by calling sd_power_system_off(). Wakeup from system-off would be in form of a reset, but you should make sure that the system is in a safe state before entering system off mode (depending on your product). And in most designs it would make sense to set GPIOs to sensible values etc (for instance so that you don't drain the battery further by having a LED active or similar).]

    Please let me know how to set the GPIOs to sensible values before entering into sleep mode. So that LED should stop blinking and it will not drain the battery.

    Regards,

    Naveed

  • Hi Naveed,

    Naveed said:
    Should I directly call sd_power_system_off()?

    You should configure the GPIOs properly for your product before entering system off mode.

    Naveed said:
    I want my device to turn ON only when the input is more than the threshold set that is 2.3V. If it is below the threshold it should enter into sleep mode.

    I see. First of all, I suggest you have a form of hysteresis, to avid a loop where the device enters system off mode, wakes up and enters it again (so a lower threshold for entering systme of mode than from waking up). Regarding wakeup, you can use the LPCOMP peripheral as a wakeup source from system off, and that seems to fit whell what you descrive here. So that means you need to configure the LPCOMP before enteering system off mode (you can refer to the LPCOMP sample in the SDK for how to configure it).

    Naveed said:
    When I run the code in the release mode without debugger, I am still getting the RED LED blinking continuously with a certain period in sleep mode. As it blinks continuously it still consumes the current in the sleep mode. 

    I don't know much about your hardware or firmware, but clearly the device is not in sysrtem off at this point. If it only happens when not debugging, perhaps you can debug with GPIOs? Could it be that the device is unexpectedly waking up from system off when it should not? Is the blinking caused by a reset loop or doesthe device just wake up and then you have some firmware that makes it blink?

    Naveed said:
    Please let me know how to set the GPIOs to sensible values before entering into sleep mode. So that LED should stop blinking and it will not drain the battery.

    There will be no LED blinking in system off mode (the GPIOs cannot change state in system off mode). As you see LEDs blink, the device is clearly not in system off the whole time. Regarding which state to put the GPIOs in that is entierly application specific. Which state makes sense on your design? Make sure that you set the pins to whatever is sensible for you before entering system off mode.

Related