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

SAADC oversample with burst configuration

Dear DevZone,

I am trying to configure the SAADC on my custom nRF52840 board.

I would like to use it in blocking mode together with oversample 16x and burst enabled.

I started from the example provided in the SDK, and I firstly removed all the parts related to non-blocking mode.

Then I modified the parameters to set oversample and burst mode. Here the steps I performed:

  • I modified the configuration struct to enable burst in this way:

#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P) \
{ \
.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_3US, \
.mode = NRF_SAADC_MODE_SINGLE_ENDED, \
.burst = NRF_SAADC_BURST_ENABLED, \ //enabled burst mode to automatically acquire 2^oversample samples with one request
.pin_p = (nrf_saadc_input_t)(PIN_P), \
.pin_n = NRF_SAADC_INPUT_DISABLED \
}

  • I modified the following value in the sdk_config file:

// <0=> Disabled
// <1=> 2x
// <2=> 4x
// <3=> 8x
// <4=> 16x
// <5=> 32x
// <6=> 64x
// <7=> 128x
// <8=> 256x

#ifndef NRFX_SAADC_CONFIG_OVERSAMPLE
#define NRFX_SAADC_CONFIG_OVERSAMPLE 4
#endif

Is the procedure correct? Am I missing something? Do you think there could be any issues related to the buffer size if I use the blocking mode (nrfx_saadc_sample_convert function)?

Thank you very much in advance,

best regard,

Gianluca Milani

Parents
  • Hi,

    It seems correct for blocking mode. However, what is your intention of using blocking mode instead of non-blocking? Are you using PPI to connect the SAMPLE task with the COMPARE event as in the example? That could be a bit problematic as it could lead to the buffer swap issue.

    regards

    Jared 

  • Dear Jared, 

    thank you very much for your answer.

    I would use it without any PPI, I am initializing the saadc without any instructions in the callback handler:

    void saadc_callback_handler(nrf_drv_saadc_evt_t const * p_event)
    {
      //Empty
    }
    
    
    void saadc_init(void)
    {
    
      ret_code_t err_code;
    
      // Create a config struct and assign it default values along with Pin number for ADC input
      //
      // Chosen paramters:
      //
      //    - Internal reference
      //    - Gain 1/6
      //    - Acquisition time 3us
      //    - Single ended
      //
      // The reasons for the choice of these parameters values can be found at the following link:
      //
      // https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/measuring-lithium-battery-voltage-with-nrf52
    
      // Configure the input as Single Ended (One Pin reading)
    
    
      nrf_saadc_channel_config_t  channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    
    
      // Initialize the saadc
    
      err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
      APP_ERROR_CHECK(err_code);
    
      // Initialize the channel which will be connected to that specific Pin
      // The selected channel is 0
    
      err_code = nrf_drv_saadc_channel_init(0, &channel_config);
      APP_ERROR_CHECK(err_code);
    
    
    
    
    }
    

    and I am triggering the saadc conversion only when I need it, using:

     nrfx_saadc_sample_convert(0, &adc_val);

    Am I doing the wrong steps if I want to implement oversampling?

    Thanks,

    Best regards,

    Gianluca

Reply
  • Dear Jared, 

    thank you very much for your answer.

    I would use it without any PPI, I am initializing the saadc without any instructions in the callback handler:

    void saadc_callback_handler(nrf_drv_saadc_evt_t const * p_event)
    {
      //Empty
    }
    
    
    void saadc_init(void)
    {
    
      ret_code_t err_code;
    
      // Create a config struct and assign it default values along with Pin number for ADC input
      //
      // Chosen paramters:
      //
      //    - Internal reference
      //    - Gain 1/6
      //    - Acquisition time 3us
      //    - Single ended
      //
      // The reasons for the choice of these parameters values can be found at the following link:
      //
      // https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/measuring-lithium-battery-voltage-with-nrf52
    
      // Configure the input as Single Ended (One Pin reading)
    
    
      nrf_saadc_channel_config_t  channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    
    
      // Initialize the saadc
    
      err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
      APP_ERROR_CHECK(err_code);
    
      // Initialize the channel which will be connected to that specific Pin
      // The selected channel is 0
    
      err_code = nrf_drv_saadc_channel_init(0, &channel_config);
      APP_ERROR_CHECK(err_code);
    
    
    
    
    }
    

    and I am triggering the saadc conversion only when I need it, using:

     nrfx_saadc_sample_convert(0, &adc_val);

    Am I doing the wrong steps if I want to implement oversampling?

    Thanks,

    Best regards,

    Gianluca

Children
No Data
Related