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

AIN2: Switch between ADC and LPCOMP, AIN4: Battery

Situation: We are building BLE device that have GATT service showing a analog sensor value. AIN2 is connected to the sensor. AIN4 is connected to battery. We would like to stop BLE advertising while the sensor value continue to be low, and restart when the value raise. So, we switch to LPCOMP peripheral for AIN2 when the sensor value become low.

We are using nrf51822 on SDK 8.0.0.

Problem: The switching between ADC and LPCOMP itself works well. However, while LPCOMP is on, AIN4 do not measure battery value correctly. And it seems to be the sensor value.

I read this article. But I think it is a little bit different situation. It does not switch the functions on the same pin.

We are happy if you have any advice. If you need sample code, I am preparing simple version for this situation.

  • Hi

    You observation is as expected. The LPCOMP and ADC share the MUX for the analog input pin, therefore you can not configure LPCOMP and ADC on an analog pin at the same time. In the linked thread, what I observed is that you can monitor the supply votlage of the chip with the ADC while using the LPCOMP at the same time on an analog input pin. To monitor the supply voltage with the ADC, you need to configure it as in this example, i.e. with

    /* Configure ADC - set reference input source to internal 1.2V bandgap */
    NRF_ADC->CONFIG = (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos);
    /* Configure ADC - set input source to VDD/3 */
    NRF_ADC->CONFIG |= (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos);
    

    Note: you may need to use another syntax to configure the ADC in the same way if you use the nrf_adc driver in the latest nRF51 SDK.

  • I did not understand here.

    The higher of the two input voltages will be input to both LPCOMP and ADC.

    Now, it is very clear. Thank you.

Related