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

nRF52840 DK lpcomp reads 0 (zero) no matter what voltage is applied to the input

I want to use a comparator without interrupt.

The measurement is not time critical.

Therefore, I chose the LPCOMP.

For initialization I use the following code:

static void lpcomp_init(uint8_t ref)
{
    nrf_lpcomp_config_t config;
    config.reference = (nrf_lpcomp_ref_t)ref;
    config.detection = NRF_LPCOMP_DETECT_CROSS;
    config.hyst      = LPCOMP_HYST_HYST_Hyst50mV;
    // config LPCOMP, from this point LPCOMP will be active
    nrf_lpcomp_configure(&config);
    nrf_lpcomp_input_select(PIN_REGENSENSOR);

    nrf_lpcomp_enable();
}

For reading the value I use the following code:

  uint8_t  lpcomp_result;

  nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_SAMPLE); 
  lpcomp_result = (uint8_t)nrf_lpcomp_result_get();

Although the input is approximately VDD I get the value 0 back.

How can I use the LPCOMP (or COMP) without interrupts?

Parents Reply
  •     uint32_t ref = NRF_LPCOMP_REF_SUPPLY_1_8;
        nrf_lpcomp_config_t config;
        config.reference = (nrf_lpcomp_ref_t)ref;
        config.detection = NRF_LPCOMP_DETECT_CROSS;
        config.hyst      = LPCOMP_HYST_HYST_Hyst50mV;
        nrf_lpcomp_configure(&config);
        nrf_lpcomp_input_select(NRF_LPCOMP_INPUT_7);
    
        nrf_lpcomp_enable();
    
        while (true)
        {
          nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_SAMPLE); 
          lpcomp_result = (uint8_t)nrf_lpcomp_result_get();
          nrf_gpio_pin_write(BSP_BOARD_LED_1, lpcomp_result);
          NRF_LOG_INFO("LPcomp: %d", (int)lpcomp_result);
    
          NRF_LOG_FLUSH();
          nrf_delay_ms(500);
        }
    

Children
Related