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

How does 52840 use SAADC to sample voltage?

Hi,

I'm using the SAADC to sample external voltage to fill in the battery service. I have use APP_TIMER_DEF to create a timer to do it every 30 seconds. Also I have init the adc:

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_AIN7);

err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_channel_init(7, &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);}

But I couldn't find the function start the ADC and how to get the sample result in the ADC interrupt? Could anyone tell me? Thanks

Parents
  • Hi,

    This is shown in the SAADC peripheral example in our SDK.

    The example works in the following way:

    • SAADC peripheral is configured and channels and buffers are setup. The example use double-buffering, meaning that one buffer is used for sampling while the other (filled) buffer is processed.
    • Timer is setup to trigger an event every 400 ms. The timer event is connected to the SAADC sample task through a PPI channel. On every timer event, the sample task is called, triggering a single sample.
    • When the SAADC sample task have been called SAMPLES_IN_BUFFER times, the buffer will be full, triggering the SAADC callback (saadc_sampling_event_init). The content of the buffer is printed using NRF_LOG, before the buffer is setup for sampling again.

    If you want lower power, you can check out the SAADC low-power example on our GitHub. This example use RTC for low power, and also include calibration for increased sampling accuracy.

    Best regards,

    Jørgen

  • Hello to the past.

    I have a question about the Jørgen's explanation about the SAADC callback.

    In the SAADC peripheral example you linked, NRF_DRV_SAADC_EVT_DONE is used to check whether the buffer is ready. However, if the SAADC callback is triggered when sample task have been called SAMPLES_IN_BEFFER times, why do we need to check NRF_DRV_SAADC_EVT_DONE?

Reply Children
Related