Nrf52832 Internal ADC is taking approx 35us. Need help to minimize it withing 10us

Hello,

I am working with nRF5 SDK v17.1.0 and using nRF52832DK board. While working with SAADC module I found that nrfx_saadc_sample_convert() API is taking almost 35us (I have verified by driving GPIO low before this API call and high after this API call) using DSO. 

Someone, please help me to reduce the timing. I want to minimize this time  within 10us for two-channel read back to back (i.e read channel 0 and read channel 1 should be done within 10us when acq_time is set to 3us or 5us)

Please check my SAADC configuration code:

void saadc_init(void)
{
    ret_code_t err_code;

    nrfx_saadc_config_t saadc_config;

    /* Configure SAADC in low power mode */
    saadc_config.low_power_mode = true;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_10BIT;
    saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
    saadc_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;

    nrf_saadc_channel_config_t channel_config0 =
        NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
        channel_config0.gain = NRF_SAADC_GAIN1_4; 
        channel_config0.reference = NRF_SAADC_REFERENCE_INTERNAL;
        channel_config0.burst = 1;
        channel_config0.acq_time = NRF_SAADC_ACQTIME_5US; //NRF_SAADC_ACQTIME_3US

    nrf_saadc_channel_config_t channel_config1 =
        NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
        channel_config1.gain = NRF_SAADC_GAIN1_4;
        channel_config1.reference = NRF_SAADC_REFERENCE_INTERNAL;
        channel_config1.burst = 1;
        channel_config1.acq_time = NRF_SAADC_ACQTIME_5US;


    err_code = nrfx_saadc_init(&saadc_config, saadc_callback);
    APP_ERROR_CHECK(err_code);


    err_code = nrfx_saadc_channel_init(0, &channel_config0);
    APP_ERROR_CHECK(err_code);

    err_code = nrfx_saadc_channel_init(1, &channel_config1);  
    APP_ERROR_CHECK(err_code);
}

void read_adc()
{

  static nrf_saadc_value_t  adc_ch_val;
  static uint8_t toggle = 0;
  //alternate read the ADC channel 0 & 1
  toggle ^= 1;
  adc_ch_val = 0;

  //only for testing of timing  
  NRF_P0->OUTCLR = 1<<6;  //clear gpio p0.6
  if(toggle)
  {
        nrfx_saadc_sample_convert(0, &adc_ch_val);
        printf("Channel  Volts -  %f\n", ((2.4 * adc_ch_val)/1024)  );
  }
  else
  {
        nrfx_saadc_sample_convert(1, &adc_ch_val);
        printf("Channel  Volts -  %f\n", ((2.4 * adc_ch_val)/1024)  );
  }
  //only for testing
  NRF_P0->OUTSET = 1<<6;  //set gpio 0.6
}

Thanks & Regards,

SC

Parents
  • Hello Jared,

    "I don't think there is any way of decreasing this time actually. Are you trying to decrease the SAADC sampling time? "

    The API nrfx_saadc_sample_convert() is taking approx 35us to give one ADC sample. I want to minimize this time period so that is why I tried changing the acquisition time but as per your reply, it seems that that will not optimize the time.

    Is it possible in any way to reduce the time period required by nrfx_saadc_sample_convert() ?

    Best Regards,

    Sanket Chadawar

Reply
  • Hello Jared,

    "I don't think there is any way of decreasing this time actually. Are you trying to decrease the SAADC sampling time? "

    The API nrfx_saadc_sample_convert() is taking approx 35us to give one ADC sample. I want to minimize this time period so that is why I tried changing the acquisition time but as per your reply, it seems that that will not optimize the time.

    Is it possible in any way to reduce the time period required by nrfx_saadc_sample_convert() ?

    Best Regards,

    Sanket Chadawar

Children
  • Hi Sanket,

    nrfx_saadc_sample_convert() does not start the sampling, it will instead process the already sampled data from the buffer. Decreasing the acquisition time will therefore not affect the conversion time. I don't think it's possible to change the conversion time. However, you can decrease the amount of time that you need to call the conversion routine by increasing the buffer size and only process the data when you need to. 

    regards

    Jared 

  • Hello Jared,

    As per your reply "you can decrease the amount of time that you need to call the conversion routine by increasing the buffer size and only processing the data when you need to. "

    Would you please help to share the API which will do these steps as you mentioned?

    Also, let me know if nrfx_saadc_sample_convert() does not start the sampling then which API shall I use to start the sampling whenever it is desired ?

    Best Regards,

    Sanket Chadawar

  • Hi there,

    There isn't an API for increasing the buffer size, instead you would have to increase the size of the nrf_saadc_value_t array buffer that you pass to nrf_drv_saadc_buffer_convert(). Increasing the buffer size means that nrf_drv_saadc_buffer_convert() which process the sampled data has to be called less often as it takes longer time for the buffer to fill with sampled data. 

    If you use PPI + SAADC as in the SAADC example in the SDK then sampling is done automatically on a COMPARE event as long as the SAADC START task has been triggered( which is done automatically in nrf_drv_saadc_buffer_convert())

    regards
    Jared 

Related