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

About SAADC, Easy-DMA and channels (nRF5_SDK)

There's an example saadc_pca10036 in the SDK. I am wondering how this piece of code works in that example:

void saadc_init(void)
{
    ret_code_t err_code;
    nrf_saadc_channel_config_t channel_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
    err_code = nrf_drv_saadc_init(NULL, saadc_callback);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_init(0, &channel_config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);
}

Specifically, why there are two calls of same function, nrf_drv_saadc_buffer_convert()? Does it set some kind of double-buffering?

In my case, I have four ADC-inputs I want to sample 200 times per second each. How should I configure the SAADC subsystem?

EDIT: Also, how do I know which channel was triggered when I get into the callback (below)?

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
   if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
   ...
Parents
  • Hi,

    Please refer to the infocenter documentation for the SAADC driver.

    Yes, you are correct, this is double buffering. "The driver supports double buffering, which means that nrf_drv_saadc_buffer_convert can be called twice and the buffer that is provided in the second call will be used immediately after the first one is filled."

    "To trigger sampling, call the function nrf_drv_saadc_sample or, through PPI, use the task SAMPLE from SAADC. nrf_drv_saadc_sample_task_get can be used to get the task address." The most power efficient way would be to set up a timer with compare events that line up with 200 times per second, and then trigger the SAMPLE task via PPI on this timer event.

    When you get NRF_DRV_SAADC_EVT_DONE you can read the data from the buffer specified in the call to nrf_drv_saadc_buffer_convert().

    Best regards,

    Øyvind

  • Thanks for answer :) I am still a bit confused, can you please read my more detailed explanation below (did not fit here).

Reply Children
No Data
Related