Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SAADC changing value range (signed to unsigned)

Hello Nordic Support,

I am using SAADC on nRF52840 with nRF5_SDK_15.3.0_59ac345

I use the following configurations:

{ 
    .resolution         = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION, // 12 bits
    .oversample         = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE, // 0
    .interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY,                       // 5
    .low_power_mode     = NRFX_SAADC_CONFIG_LP_MODE                             // 0
}


{                                                   
    .resistor_p = NRF_SAADC_RESISTOR_DISABLED,      
    .resistor_n = NRF_SAADC_RESISTOR_DISABLED,      
    .gain       = NRF_SAADC_GAIN1_6,                
    .reference  = NRF_SAADC_REFERENCE_INTERNAL,     
    .acq_time   = NRF_SAADC_ACQTIME_10US,           
    .mode       = NRF_SAADC_MODE_SINGLE_ENDED,      
    .burst      = NRF_SAADC_BURST_DISABLED,         
    .pin_p      = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1),       
    .pin_n      = NRF_SAADC_INPUT_DISABLED          
}

The SAADC value, as I have been using is signed. I wonder if Nordic will later support unsigned value, or you will not? Or are there any ways to convert from signed SAADC to unsigned SAADC?

Thank you and best regards,

           Duy

Parents Reply
  • Hi,

    The SAADC output is in the range [0, +2^(resolution)] in single ended mode. If resolution = 12, then the range is [0, 4096]

    If the SAADC samples VDD, then the output value is:

    RESULT = (VDD) * (GAIN/VDD) * 2(RESOLUTION)

    RESULT = VDD * (GAIN/VDD) * 2^(12) = GAIN * 2^12

    If GAIN = 1, sampling VDD will output: 0b0001 0000 0000 0000 = 4096
    The sample will then be stored with 2's complement applied. 
    Negative values are due to ground bounce, if you experience this often, then consider to use differential mode instead.
    regards
    Jared 
Children
Related