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

[nRF52832] How to start/stop SAADC the right way?

Hi,

I have designed a system that uses the SAADC to sample 3 analog inputs in scan mode at 8 KSPS, performs downsampling by a factor of 8 using the DSP, and sends the results over BLE.

The sampling is done using PPI (EasyDMA) in a double-buffering scheme according to the Nordic example.

The application works great when waking up from reset. However, the ADC needs to be stopped whenever the BLE link is disconnected to save battery. When the connection is restored, the ADC needs to be started again.

This is where I experience problems: Whenever the ADC is restarted, I get problems where it suddenly isn't double-buffering (only one buffer used).
Another problem is that the 3 channels are shifted: instead of receiving the channels in order [1,2,3], I get [2,3,1] or [3,1,2].

Clearly, this is due to a wrong method of starting and stopping the ADC. What I tried:

  1. Using nrf_drv_saadc_uninit() to turn off the ADC and then repeating the entire init process after reconnect, including issuing the 2 nrf_drv_saadc_buffer_convert() instructions to initiate the double-buffer. This results in a single-buffer behavior.

  2. Only stopping the sampling timer using nrf_drv_timer_disable() and nrf_drv_timer_enable(). This also had the single-buffer behavior.

  3. using nrf_drv_timer_enable() to restart the sampling timer and re-issuing the 2 nrf_drv_saadc_buffer_convert() instructions. This resulted in correct double-buffering but still shifted channels (not every time, but a lot).

What is the correct way to start and stop the SAADC?

Thanks, Michael.

Related