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

52820 COMP interrupt problem

Hi, Friend, 

      I have a light sensor connected to P0.04/AIN2 on 52820, and use COMP to detect the change of voltage. 

      Here is my test code. When light change, the return value of nrfx_comp_sample() is correct (it can change between 0 and 1). 

      But if I channge the params of nrf_drv_comp_start(0, 0) to nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_DOWN_MASK | NRF_DRV_COMP_EVT_EN_UP_MASK, 0),  the RTT Viewer will printf sample value every 0.5s, but stoped (printing nothing) when AIN2 vlotage changed.  

      I suppose is the interrupt problem. What can I do next? Thank you.

void comp_event_handler(nrf_comp_event_t evt)
{
        NRF_LOG_INFO("VAL=%",evt);
}

void COMP_TEST()
{
        uint32_t err_code;
        nrf_drv_comp_config_t comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_2);

        comp_config.reference = 4; // <0=> Internal 1.2V, <1=> Internal 1.8V, <2=> Internal 2.4V, <4=> VDD, <7=> ARef
        comp_config.ext_ref = NRF_COMP_EXT_REF_0; // Use AIN0 as external analog reference.
        comp_config.main_mode = 0; /* // <0=> Single ended, <1=> Differential */
        comp_config.threshold.th_down = NRFX_VOLTAGE_THRESHOLD_TO_INT(1.0, 3.3);
        comp_config.threshold.th_up = NRFX_VOLTAGE_THRESHOLD_TO_INT(2.0, 3.3);
        comp_config.speed_mode = 2; // <0=> Low power, <1=> Normal, <2=> High speed
        comp_config.hyst = 0; // <0=> No, <1=> 50mV
        comp_config.interrupt_priority = 6;

        NRF_LOG_INFO("#####%d,%d,%d,%d,%d", comp_config.input, comp_config.reference, comp_config.threshold.th_down,
        comp_config.threshold.th_up, comp_config.interrupt_priority);
        err_code = nrf_drv_comp_init(&comp_config, comp_event_handler);
        nrf_drv_comp_start(0, 0);

        while (true)
        {
                NRF_LOG_INFO("VAL:%d", nrfx_comp_sample());
                NRF_LOG_FLUSH();
                nrf_delay_ms(500);
        }
}

Parents
  • Hi,

    See my comment about PRS here. As far as I can see, the nrfx_prs_acquire() function should get a NULL-pointer returned from prs_box_get(), which should skip the if-setting and return success. 

    I tested your code (with some small modifications, replaced NRF_LOG with LED blinking, and connected a button as input, as I do not have a light sensor). I was able to generate interrupts (checked with debugger that event handler is called) by changing the state of the input pin. I did test on a nRF52833 DK with emulation for nRF52820,as I do not have a board with the actual chip available right now.

    If your logging stops, it sounds like a hardfault or similar have occurred. This may have happened if you have configured the project incorrectly, or with wrong MDK files. If you could upload the full project, I can have a look at it.

    Best regards,
    Jørgen

  • Since nRF52820 does not have a LPCOMP peripheral, there is no PRS box defined for sharing resources between COMP and LPCOMP. The interrupts from NVIC will be triggered directly in nrfx_comp_irq_handler (redefined from COMP_IRQHandler, which is the default handler name defined in the MDK files). In chips variants where both LPCOMP and COMP are available, and PRS is enabled, a common interrupt handler inside PRS is defined, where interrupts are forwarder instead of the default NRFX IRQ handler for that peripheral.

Reply Children
Related