This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

LCOMP/COMP cannot wakeup the device

Hi,

I use  'nRF5_SDK_15.2.0_9412b96\examples\ble_peripheral\ble_app_uart' as my project base for PCA10040.  The code has its default sleep mode which use 'sleep_mode_enter' function for idle evt in 'on_adv_evt'.  And I add comps like the following content.

static void sensor_timeout_handler(void * p_context)
{
      UNUSED_PARAMETER(p_context);

    nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_UP_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT);
}

static void comp_event_handler(nrf_comp_event_t event)
{
    uint32_t                err_code;

    if (event == NRF_COMP_EVENT_UP)
    {
        nrf_gpio_pin_toggle(BSP_LED_2); // just change state of first LED
    }
    //nrf_gpio_pin_toggle(BSP_LED_2); // just change state of first LED
    sensor_count++;

    err_code = app_timer_start(m_sensor_timer_id, sensor_time_intervel, NULL);
    APP_ERROR_CHECK(err_code);
}

/**
 * @brief Initialize COMP driver.
 */
static void comp_init(void)
{
    uint32_t                err_code;

    nrf_drv_comp_config_t config = NRF_DRV_COMP_DEFAULT_CONFIG(3);
    // initialize LPCOMP driver, from this point LPCOMP will be active and provided
    // event handler will be executed when defined action is detected
    err_code = nrf_drv_comp_init(&config, comp_event_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_UP_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT);

}

And I call ' comp_init' in the main function. What should do to wakeup the LCOMP by giving a high voltage pulse to p0.05. But the device cannot wake up from it.

Does anybody caught this issue? 

Do you have any advices for let  only LCOMP/COMP wakeup system?

Parents
  • Hi,

    The LPCOMP peripheral can be used as a wake-up source from system off low power mode, but the COMP peripheral cannot. Your comments indicate that you want to use the LPCOMP (which is what you need in this case), but you are in fact using the COMP (via the COMP driver). I recommend you refer to the LPCOMP example to see how it is used with the LPCOMP driver.

  • Thanks !  I wanna use lpcomp to wakeup device, and use comp for step count. Can this two moudle existence in the same project?

  • Hi,

    Yes, you can use the LPCOMP and COMP in the same project, that is no problem.

  • Thank you! 

    1.) Compile eror oeccurred  after I set 'COMP_ENABLED 1', 'LPCOMP_ENABLED 1', 'NRFX_COMP_ENABLED 1' and 'NRFX_COMP_ENABLED 1' in sdk_config.h,  and added 'nrfx_comp.c' and 'nrfx_lpcomp.c' into the project. and  changed the code in main.c:

    ......

    #include "nrfx_common.h"

    #include "nrf_comp.h"
    #include "nrfx_comp.h"
    #include "nrf_drv_comp.h"

    #include "nrf_lpcomp.h"
    #include "nrfx_lpcomp.h"
    #include "nrf_drv_lpcomp.h"

    ...

    static void sensor_timeout_handler(void * p_context)
    {
          UNUSED_PARAMETER(p_context);

        //nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT);
        nrf_drv_comp_start(NRFX_COMP_EVT_EN_CROSS_MASK, NRFX_COMP_SHORT_STOP_AFTER_UP_EVT);
        //nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_DOWN_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT);
    }

    static void comp_event_handler(nrf_comp_event_t event)
    {
        uint32_t                err_code;

        if (event == NRF_COMP_EVENT_UP)
        {
            nrf_gpio_pin_toggle(BSP_LED_2); // just change state of first LED
        }
        //nrf_gpio_pin_toggle(BSP_LED_2); // just change state of first LED
        sensor_count++;

        err_code = app_timer_start(m_sensor_timer_id, sensor_time_intervel, NULL);
        APP_ERROR_CHECK(err_code);
            //nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT);
    }

    /**
     * @brief Initialize COMP driver.
     */
    static void comp_init(void)
    {
        uint32_t                err_code;

        nrfx_comp_config_t config = NRFX_COMP_DEFAULT_CONFIG(2);
        // initialize LPCOMP driver, from this point LPCOMP will be active and provided
        // event handler will be executed when defined action is detected
        err_code = nrf_drv_comp_init(&config, comp_event_handler);
        APP_ERROR_CHECK(err_code);
        //nrf_drv_lpcomp_enable();
        nrf_drv_comp_start(NRFX_COMP_EVT_EN_UP_MASK, NRFX_COMP_SHORT_STOP_AFTER_UP_EVT);
        //nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_DOWN_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT);
        //nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT);
    }

    static void lpcomp_event_handler(nrf_lpcomp_event_t event)
    {
        if (event == NRF_LPCOMP_EVENT_DOWN)
        {
        }
    }
    /**
     * @brief Initialize LPCOMP driver.
     */
    static void lpcomp_init(void)
    {
        uint32_t                err_code;

        nrfx_lpcomp_config_t config = NRFX_LPCOMP_DEFAULT_CONFIG;
        //config.input = NRF_LPCOMP_INPUT_2; // input 2: AIN2, P0.04
        config.input = NRF_LPCOMP_INPUT_3;
        // initialize LPCOMP driver, from this point LPCOMP will be active and provided
        // event handler will be executed when defined action is detected
        err_code = nrfx_lpcomp_init(&config, lpcomp_event_handler);
        APP_ERROR_CHECK(err_code);
        nrf_lpcomp_enable();

    }

    Error: L6200E: Symbol COMP_LPCOMP_IRQHandler multidfined (by nrf_lpcomp.o and nrf_comp.o)

    2.) I tried to  define 'NRFX_PRS_BOX_3_ENABLED', and no compile errors.

    3.) Then I want to know for what does 'NRFX_PRS_BOX_3_ENABLED' used?

    // COMP_LPCOMP_IRQn

    #if NRFX_CHECK(NRFX_PRS_ENABLED) && NRFX_CHECK(NRFX_PRS_BOX_3_ENABLED)

    #define nrfx_prs_box_3_irq_handler  COMP_LPCOMP_IRQHandler

    #else

    #define nrfx_comp_irq_handler       COMP_LPCOMP_IRQHandler

    #define nrfx_lpcomp_irq_handler     COMP_LPCOMP_IRQHandler

    #endif

    Am I doing right?

  • Hi,

    Yes, you are doing things right. I did not specify that in my previous reply, but the drivers have support for using peripherals with the same IRQ number (essentially much of the same HW). You must enable it by setting NRFX_PRS_ENABLED and NRFX_PRS_BOX_3_ENABLED to 1 in your projects sdk_config.h. This way, the interrupt will be forwarded to the correct handler, depending on weather the LPCOMP or COMP is currently enabled.

    You can see how this is used by looking at for intsance nrfx_lpcomp.c, where nrfx_prs_acquire() is called by nrfx_lpcomp_init() and nrfx_prs_release() is called by nrfx_lpcomp_uninit(). You will find the same thing for COMP in nrfx_comp.c.

    Then the only thing you need to remember is to uninit the LPCOMP before initializing the COMP and vice versa.

  • Hi , May I know what does the macro 'NRFX_PRS_BOX_3_ENABLED' mean?

  • Hi , May I know what does the macro 'NRFX_PRS_BOX_3_ENABLED' mean?

Reply Children
Related