DevAcademy Lesson 6 Exercise 3: How to properly stop Timer/PPI/ADC?

Hello,

I am currently working on the Exercise 3 – Interfacing with ADC using nrfx drivers and TIMER/PPI sample.  I have it operating, however I am wondering what is the proper way to stop its operation?  I have tried:

nrfx_timer_uninit(&timer_instance);
nrfx_saadc_uninit();
nrfx_gppi_channels_disable_all();

However it appears that there is a stuck event NRFX_SAADC_EVT_DONE from the log that continually triggers the saadc_event_handler :

static void saadc_event_handler(const nrfx_saadc_evt_t *p_event) {

    LOG_DBG("%s", __func__);
    ...
    ...
}

[07:15:48.192,474] <dbg> batt_adc: saadc_event_handler: saadc_event_handler
[07:15:48.200,073] <dbg> batt_adc: saadc_event_handler: saadc_event_handler
[07:15:48.207,733] <inf>   batt_adc: SAADC buffer at 0x20002c94 filled with 200 samples
[07:15:48.216,186] <inf>  batt_adc: AVG=3183, MIN=3172, MAX=3192
[07:15:48.222,747] <dbg> batt_adc: saadc_event_handler: saadc_event_handler
[07:15:48.230,346] <dbg> batt_adc: saadc_event_handler: saadc_event_handler
[07:15:48.238,006] <inf> batt_adc: SAADC buffer at 0x20002b04 filled with 200 samples
[07:15:48.246,459] <inf> batt_adc: AVG=3184, MIN=3171, MAX=3200

  • Hi,

    When stopping SAADC sampling you need to first stop triggering sampling (by stopping the timer in your case), then stop any ongoing SAADC procedure, then wait for the end evente before  you continue to uninitialize the ADC. This is signalled by dhe drive rwith a NRFX_SAADC_EVT_DONE (If you read the specification you will see the STOPPED event, but the driver translates this to a DONE event).

    Note that you do not need to consider if sampling is ongoing or not, as the event is always generated (see product specification):

    The ADC is stopped by triggering the STOP task. The STOP task will terminate an ongoing sampling. The ADC will generate a STOPPED event when it has stopped. If the ADC is already stopped when the STOP task is triggered, the STOPPED event will still be generated.

Related