Regarding the Value Obtained from the ADC

conducted an ADC experiment using the nRF5 DK (PCA10056).

The power supply for the nRF5 was provided via USB.

Based on the SAADC sample, I coded the following:

[main.c]
  void saadc_init(void)
  {
         :
      nrf_saadc_channel_config_t channel_config =
          NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
+     channel_config.gain = NRF_SAADC_GAIN1_6;

      err_code = nrf_drv_saadc_init(NULL, saadc_callback);
                     :
  }

[sdk_config.h]
  // <o> NRFX_SAADC_CONFIG_RESOLUTION  - Resolution
  // <0=> 8 bit 
  // <1=> 10 bit 
  // <2=> 12 bit 
  // <3=> 14 bit 
  #ifndef NRFX_SAADC_CONFIG_RESOLUTION
- #define NRFX_SAADC_CONFIG_RESOLUTION 1
+ #define NRFX_SAADC_CONFIG_RESOLUTION 2
  #endif

While running, I checked the value of "channel_config," and it was as follows.

channel_config
  .resistor_p : NRF_SAADC_RESISTOR_DISA3LED ( 0 )
  .resistor_n : NRF_SAADC_RESISTOR_DISA3LED ( 0 )
  .gain       : NRF_SAADC_GAIN1_6 ( 0 )
  .reference  : NRF_SAADC_REFEREUCE_INTERNAL ( 0 )
  .acq_time   : NRF_SAADC_ACQTIME_10US ( 2 )
  .mode       : NRF_SAADC_MODE_SINGLE_ENDED ( 0 )
  .burst      : NRF_SAADC_BURST_DESABLED ( 0 )
  .pin_p      : NRF_SAADC_INPUT_AIN1 ( 2 )
  .pin_n      : NRF_SAADC_INPUT_DISABLED ( 0 )

I applied 3.0V to P0.03 and checked the value at the following line (the line marked with "!").

  void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
  {
      if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
      {
                :
          err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
!         APP_ERROR_CHECK(err_code);
                :
      }
  }

The expected value was:

3413.3333 = ((3.0 - 0.0)*(1/6))/0.6 * 2^12

However, the actual value was 860.

I verified the value with a tester and confirmed that 3.0V was properly applied.

Why is there such a discrepancy?

I haven’t performed calibration, but I don't think that would result in a 4x difference.

I believe there is a misunderstanding somewhere, but what could it be?

Parents
  • Hi kkuma256,

    I reviewed your configuration carefully and see no issue. All of your configurations are correct, and your expected value is also correct.

    The only thing I can see is that if the resolution is 10 bit, then the expected value would be 853. If this is the case, your result of 860 would make sense.

    The value in NRFX_SAADC_CONFIG_RESOLUTION only change the default resolution when using NRFX_SAADC_DEFAULT_CONFIG.
    Could you be configuring your own nrfx_saadc_config_t, of the resolution is set again somewhere?

    Could you please look into your nrfx_saadc_config_t() and check if the resolution is correct?

    Hieu

Reply
  • Hi kkuma256,

    I reviewed your configuration carefully and see no issue. All of your configurations are correct, and your expected value is also correct.

    The only thing I can see is that if the resolution is 10 bit, then the expected value would be 853. If this is the case, your result of 860 would make sense.

    The value in NRFX_SAADC_CONFIG_RESOLUTION only change the default resolution when using NRFX_SAADC_DEFAULT_CONFIG.
    Could you be configuring your own nrfx_saadc_config_t, of the resolution is set again somewhere?

    Could you please look into your nrfx_saadc_config_t() and check if the resolution is correct?

    Hieu

Children
  • The direct cause has been identified.

    Previously, the SAADC initialization was done with:

    err_code = nrf_drv_saadc_init(null, saadc_callback);
    

    However, when I explicitly initialized it like this:

    nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    

    I was able to get the expected values.

    Thank you very much.

    However, another issue has arisen, so I will ask about it in a separate issue.

Related