Analogue input channel constants wrong in nrf52833_bitfields.h for nRF Connect SDK v3.2.1

I just upgraded my project (that runs on custom hardware with the nRF8233 using an Ezurio BL653 module) from nRF Connect SDK v3.1.0 to SDK v3.2.1 and the battery monitoring on my device stopped working with the following errors:

*** Using nRF Connect SDK v3.2.1-d8887f6f32df ***
*** Using Zephyr OS v4.2.99-ec78104f1569 ***
E: Cannot configure channel 0: -22
I: Setup AIN7 got -22
I: Battery setup: -22 0

It seems that the constants in nrf52833_bitfields.h have changed are are now out by 1, so the only way I can make it work is to change my device tree file from

    vbatt {
        compatible = "voltage-divider";
        io-channels = <&adc 7>;
        output-ohms = <180000>;
        full-ohms = <(1500000 + 180000)>;
     };
to
    vbatt {
        compatible = "voltage-divider";
        io-channels = <&adc 6>;
        output-ohms = <180000>;
        full-ohms = <(1500000 + 180000)>;
     };
Then it works and gives the correct voltages.
Why has this changed?
Parents
  • Sorry, I got this wrong!

    Those constants have not changed in nrf52833_bitfields.h. I was comparing COMP_PSEL_PSEL_AnalogInput0 with SAADC_CH_PSELP_PSELP_AnalogInput0.

    But something has changed between those versions. I'll see if I can work out what has changed.

  • Hello Charles,

    I'm not sure here if your reply means you got it working as expected or if there's still an issue you are working on?

    Best regards

    Asbjørn

  • Hi Asbjørn,

    I have it working, but I don't know why it changed in the SDK or whether my fix is the best way to fix it.

    I am monitoring the battery voltage with a resistor divider and using code based on the Battery Voltage Measurement sample.

    With the device tree set to the correct analogue input (i.e. "io-channels = <&adc 7>;" for AIN7) then in battery.c in divider_setup() I have to make the following change to make it work:

    #ifdef CONFIG_ADC_NRFX_SAADC
    	*accp = (struct adc_channel_cfg){
    		.gain = BATTERY_ADC_GAIN,
    		.reference = ADC_REF_INTERNAL,
    		.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40),
    	};
    
    	if (cfg->output_ohm != 0) {
    		//accp->input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0
    		//	+ iocp->channel;
    		accp->input_positive = iocp->channel;
    	} else {
    		accp->input_positive = SAADC_CH_PSELP_PSELP_VDD;
    	}
    
    	asp->resolution = 14;
    #else /* CONFIG_ADC_var */
    #error Unsupported ADC
    #endif /* CONFIG_ADC_var */

    I.e. not adding SAADC_CH_PSELP_PSELP_AnalogInput0 to the channel number.

    So the problem is fixed for me, I really just wanted to alert you to the issue since it seems odd that it changed between versions.

    Thanks for you help.

Reply
  • Hi Asbjørn,

    I have it working, but I don't know why it changed in the SDK or whether my fix is the best way to fix it.

    I am monitoring the battery voltage with a resistor divider and using code based on the Battery Voltage Measurement sample.

    With the device tree set to the correct analogue input (i.e. "io-channels = <&adc 7>;" for AIN7) then in battery.c in divider_setup() I have to make the following change to make it work:

    #ifdef CONFIG_ADC_NRFX_SAADC
    	*accp = (struct adc_channel_cfg){
    		.gain = BATTERY_ADC_GAIN,
    		.reference = ADC_REF_INTERNAL,
    		.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40),
    	};
    
    	if (cfg->output_ohm != 0) {
    		//accp->input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0
    		//	+ iocp->channel;
    		accp->input_positive = iocp->channel;
    	} else {
    		accp->input_positive = SAADC_CH_PSELP_PSELP_VDD;
    	}
    
    	asp->resolution = 14;
    #else /* CONFIG_ADC_var */
    #error Unsupported ADC
    #endif /* CONFIG_ADC_var */

    I.e. not adding SAADC_CH_PSELP_PSELP_AnalogInput0 to the channel number.

    So the problem is fixed for me, I really just wanted to alert you to the issue since it seems odd that it changed between versions.

    Thanks for you help.

Children
  • Hello Charles,

    thank you for the feedback and based on your description here now it looks like the definitions for SAADC_CH_PSELP_PSELP_AnalogInput0 has changed between the NCS version you have, assuming that the HW is identical. 

    You are saying that the defintion for SAADC_CH_PSELP_PSELP_AnalogInput0 in nrf52833_bitfields.h is the same between your board definitions?

    Best regards

    Asbjørn

  • Hi Asbjørn,

    nrf52833_bitfields.h has not changed between SDK versions 3.1.0 and 3.2.1, but something has.

    Here is how you can recreate the problem with the nRF52DK board.

    1. Create a new application that is a copy of the "Measure battery voltage" sample using nRF Connect SDKv3.1.0.

    2. Add the following as the file "nrf52dk_nrf52832.overlay" in the root project directory

    / {
        vbatt {
            compatible = "voltage-divider";
            io-channels = <&adc 7>;
            output-ohms = <180000>;
            full-ohms = <(1500000 + 180000)>;
         };
    };

    3. Create a Build Configuration for the board target "nrf52dk/nrf528332", using. SDK v3.1.0 and toolchain v3.1.0.

    4. Build and run that configuration on the nRF52DK and it works - you get this output on the serial port:

    *** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
    *** Using Zephyr OS v4.1.99-1612683d4010 ***
    [0:00:00.274]: 1232 mV; 0 pptt
    [0:00:05.265]: 1521 mV; 0 pptt
    [0:00:10.257]: 1138 mV; 0 pptt
    [0:00:15.250]: 1213 mV; 0 pptt

    5. Create another Build Configuration for the same project for board target "nrf52dk/nrf528332", using. SDK v3.2.1 and toolchain v3.2.1

    6. Build and run this second configuration on the nRF52DK and it fails - you get this output on the serial port:

    *** Booting nRF Connect SDK v3.2.1-d8887f6f32df ***
    *** Using Zephyr OS v4.2.99-ec78104f1569 ***
    Failed initialize battery measurement: -2

    regards,

    Charles

Related