ADC channel changes from NCS 3.1.1 to NCS 3.2.0

Hi Nordic,

I'm using custom board based on nrf52840 SoC. After migrating the SDK, the original device tree configuration for ADC became unavailable, but I failed to find relevant explanations in the SDK migration guide. Through my own attempts, I modified the original dts that worked properly in ncs3.1.1 into a new dts, and it now works properly.
The old dts:

/ {
    vbatt {
        compatible = "voltage-divider";
        io-channels = <&adc 7>;
        output-ohms = <1000000>;
        full-ohms = <2000000>;
    };
};

&adc {
    status = "okay";
};

The new dts:

/ {
    vbatt {
        compatible = "voltage-divider";
        io-channels = <&adc 6>;
        output-ohms = <1000000>;
        full-ohms = <2000000>;
    };
};

&adc {
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
    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_AIN7>; /* P0.31 on nRF52840 */
        zephyr,resolution = <12>;
    };
};

These are two problems I encountered during my testing.

1.This error occurs during ADC setup when using channel 7 in NCS 3.2.0: <err> adc_nrfx_saadc: Cannot configure channel 0: -22. Normally, all 8 channels should be usable properly. I don't know why the error occurs in NCS 3.2.0.

2.If I do not use channel 6 but other channels such as channel 0 and channel 1, the voltage collected using adc_raw_to_millivolts(); will not be valid data. I do not see any other ADC channels being used in the final generated zephyr.dts, so I am not sure what exactly causes only channel 6 to be able to collect valid battery level data.

I hope you guys can answer my questions. Thank you very much.

Parents
  • Hi 

    I will investigate this. It might be related to new nrfx version where they introduced a log of breaking changes ref https://github.com/NordicSemiconductor/nrfx/blob/master/doc/nrfx_4_0_migration_guide.md 

    Regards

    Runar

  • Update:

    So Zephyr has made some changes in the ADC driver and you now need to configure each channel by themself compared to how it was before. 

    1.This error occurs during ADC setup when using channel 7 in NCS 3.2.0: <err> adc_nrfx_saadc: Cannot configure channel 0: -22. Normally, all 8 channels should be usable properly. I don't know why the error occurs in NCS 3.2.0.

    Your overlay seems to be valid for me. Can you do a pristine build and compare your overlay.dts to the generated one after building? 

    2.If I do not use channel 6 but other channels such as channel 0 and channel 1, the voltage collected using adc_raw_to_millivolts(); will not be valid data. I do not see any other ADC channels being used in the final generated zephyr.dts, so I am not sure what exactly causes only channel 6 to be able to collect valid battery level data.

    This makes sense as as i presume your battery divider is is connected to pin corresponding to AIN7. No other channel can see the signal if you don't change the dts. 

    Regards

    Runar

Reply
  • Update:

    So Zephyr has made some changes in the ADC driver and you now need to configure each channel by themself compared to how it was before. 

    1.This error occurs during ADC setup when using channel 7 in NCS 3.2.0: <err> adc_nrfx_saadc: Cannot configure channel 0: -22. Normally, all 8 channels should be usable properly. I don't know why the error occurs in NCS 3.2.0.

    Your overlay seems to be valid for me. Can you do a pristine build and compare your overlay.dts to the generated one after building? 

    2.If I do not use channel 6 but other channels such as channel 0 and channel 1, the voltage collected using adc_raw_to_millivolts(); will not be valid data. I do not see any other ADC channels being used in the final generated zephyr.dts, so I am not sure what exactly causes only channel 6 to be able to collect valid battery level data.

    This makes sense as as i presume your battery divider is is connected to pin corresponding to AIN7. No other channel can see the signal if you don't change the dts. 

    Regards

    Runar

Children
Related