Trying to read the voltage of two ADC inputs, each with different voltage divider circuits.
Using zephyr/samples/boards/nrf/battery, I can get the correct voltage if I pick one input or the other. However, if I copy battery.c to battery2.c changing the ADC input, I get incorrect values from both inputs.
If I use zephyr/samples/drivers/adc, the wrong voltages are displayed and changing one input affects both values. (Should be 15V and 3.9V)
ADC reading: - adc@e000, channel 4: 8779 = 1928 mV - adc@e000, channel 6: 8745 = 1921 mV ADC reading: - adc@e000, channel 4: 8790 = 1931 mV - adc@e000, channel 6: 8740 = 1920 mV ADC reading: - adc@e000, channel 4: 8774 = 1927 mV - adc@e000, channel 6: 8738 = 1919 mV
DTS:
/ { zephyr,user { io-channels = <&adc 4>, <&adc 6>; }; }; &adc { status = "okay"; #address-cells = <1>; #size-cells = <0>; channel@4 { reg = <4>; zephyr,gain = "ADC_GAIN_1_6"; zephyr,reference = "ADC_REF_INTERNAL"; zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; zephyr,input-positive = <NRF_SAADC_VDD>; zephyr,resolution = <14>; zephyr,oversampling = <8>; }; channel@6 { reg = <6>; zephyr,gain = "ADC_GAIN_1_6"; zephyr,reference = "ADC_REF_INTERNAL"; zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; zephyr,input-positive = <NRF_SAADC_VDD>; zephyr,resolution = <14>; zephyr,oversampling = <8>; }; }; / { vbatt { compatible = "voltage-divider"; io-channels = <&adc 4>; output-ohms = <100000>; full-ohms = <(100000 + 100000)>; power-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>; }; vin { compatible = "voltage-divider"; io-channels = <&adc 6>; output-ohms = <100000>; full-ohms = <(100000 + 12000)>; }; };
Any idea why the Zephyr ADC is displaying the wrong values or how to read multiple inputs with the nRF example?