nrf52805: ADC polling mode issue

Hardware setup: Custom board using BC805M-P (with App protect)
Software: nrf5 SDK S112 v17.0.2 ->Segger V7.30

My Objective: 

measure the Li-ion battery voltage(4.2V -100% till 3.6V-0%) through an external resistive divider & internal 0.6v ref voltage. (I'm not worried about the current consumption as of this moment. would like to make this concept work & all the other optimisations shall see later. Regarding optimisations yes I'm aware of this page: https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/measuring-lithium-battery-voltage-with-nrf52)

What works so far?
for the moment my example measured voltage value is being transmitted over BLE through the battery service. it's all working well.
But the ADC is just measuring some garbage value (random) which is clearly not correct.

My concept of ADC polling mode is taken from this post & modified for my work. https://devzone.nordicsemi.com/f/nordic-q-a/14486/measuring-the-battery-voltage-with-nrf52832/129422



The ADC result value is clearly not accurately working when I'm just calling the function manually upon a button press. ble_Update_BatteryVoltage();

What am I doing wrong?

Thanks, for any valuable input I'm new to NRF. 
Gokunath 

  • Small tip, the SAADC pin numbering can be confusing leading to using the wrong pin; AIN2 is P0.4

  • Hey,

    Yes I've verified this on the nrf52805_bitfields.h file (under modules/nrfx/mdk) 

    its mentioned as this : " #define SAADC_CH_PSELP_PSELP_AnalogInput2 (3UL) /*!< AIN2 */"

    I've verified my PCB connections too it's under P0.04.

    Voltages to the voltage divider are coming in crisp & voltage drop is similar to theoretical expectations with some milli volt differences.

    Should I continue to debug this? or shall I go back to some tried & tested method example code on Saadc? (is it available if so please let me know where can i find them. ) may be interrupt on button press is preferred.

  • Hi Gokulnath,

    My Objective: 

    measure the Li-ion battery voltage(4.2V -100% till 3.6V-0%) through an external resistive divider & internal 0.6v ref voltage. (I'm not worried about the current consumption as of this moment. would like to make this concept work & all the other optimisations shall see later

    You could try the peripheral/saadc sample in nRF5 SDK.

    But the ADC is just measuring some garbage value (random) which is clearly not correct.

    What does this look like? Would you be able to provide an example? Does the this change if you change the voltage?

    Thanks, for any valuable input I'm new to NRF. 

    nRF Connect SDK is recommended for new designs. Please see the nRF Connect SDK and nRF5 SDK statement as well as the nRF Connect SDK Fundamentals course at Nordic Developer Academy.

    https://www.nordicsemi.com/Products/Development-software/nrf-connect-sdk

    Here are some samples for nRF Connect SDK. You could start with simple_blocking or simple_nonblocking: hal_nordic/nrfx/samples/src/nrfx_saadc at master · zephyrproject-rtos/hal_nordic · GitHub

  • There is a bug here, the result is read before the SAADC sample has completed:

    Change to:

  • Hey,

    I've made these suggested changes. 

    Ofc the value oscillation is better than before but still, it moves a lot.

    ->My voltage bridge is always on for this particular test & I verified it on the Circuit level during operation

    My new code below:




    Regarding the example output which you asked  

    I've just parsed the output of the Battery for each button press on the BLE terminal into the txt file for simpler understanding. (All the numbers are in hex format)

    What does this look like? Would you be able to provide an example? Does the this change if you change the voltage?

    My Observations:
    I could see the Voltage on BLE clearly moves to the changes in input, My question is why it's not as stable as the bare-metal saadc example when I access it on the above polling method when the input voltage is constant?  


    My other trials:
    I've tried the default saadc peripheral example from the SDK 17.0.2 /17.1 
    It outputs the value stable on the 52DK via uart. it also responds to the changes to the input voltage accurately.

    But when I add the same code with the BLE stack the output has the same oscillation issue as mentioned in the above output text.

    Thanks for your inputs. 

1 2 3 4