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

SAADC digital output formula in differential mode

Hi,

I'm developing an application for the nRF52840 that uses 3 SAADC channels. In particular, the channels are configured as below:

    nrfx_saadc_config_t saadc_config = NRFX_SAADC_DEFAULT_CONFIG;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
    err_code = nrfx_saadc_init(&saadc_config, _saadc_handler);
    if (err_code != NRFX_SUCCESS)
        return err_code;
    
    nrf_saadc_channel_config_t sen_channel_config =
        NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(NRF_SAADC_INPUT_AIN1, NRF_SAADC_INPUT_AIN0);
    sen_channel_config.gain = NRF_SAADC_GAIN1_5;
    sen_channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
    err_code = nrfx_saadc_channel_init(0, &sen_channel_config);
    if (err_code != NRFX_SUCCESS)
        return err_code;

    nrf_saadc_channel_config_t ctrl_channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    ctrl_channel_config.gain = NRF_SAADC_GAIN1_5;
    ctrl_channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
    err_code = nrfx_saadc_channel_init(1, &ctrl_channel_config);
    if (err_code != NRFX_SUCCESS)
        return err_code;

    nrf_saadc_channel_config_t offset_channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
    offset_channel_config.gain = NRF_SAADC_GAIN1_5;
    offset_channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
    err_code = nrfx_saadc_channel_init(2, &offset_channel_config);
    if (err_code != NRFX_SUCCESS)
        return err_code;

I'm able to get the samples from the SAADC and to obtain the analog voltage value by reversing the digital output value formula reported in the Product Specification v1.1:

RESULT = (V(P) – V(N)) * (GAIN/REFERENCE) * 2^(RESOLUTION - m)

where:

V(P) -> is the voltage at input P
V(N) -> is the voltage at input N
GAIN -> is the selected gain
REFERENCE -> is the selected reference voltage
RESOLUTION -> is output resolution in bits, as configured in register RESOLUTION on page 395
m ->   is 0 for single-ended channels
          is 1 for differential channels

The values that I obtain are correct for the single-ended channels (1 and 2) but for the differential channel (0) I obtain exactly half the value that I can measure using a multimeter on the same lines. I think that this behavior is due to the 'm' parameter in the formula (which is 1 for differential channels).

Am I doing something wrong in reversing the digital output formula?

Thanks.

Parents Reply Children
No Data
Related