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.

Parents
  • Thanks Jørgen.

    I managed to alleviate the problem greatly by using only nrf_drv_timer_disable() without calling nrf_drv_saadc_abort() as I did before.

    However, when I try to increase the sampling rate to 12.5 KSPS and even 10 KSPS, while still maintaining a decimation factor of 8, I can see the channel shifting in real time - even without start/stop (using a monitoring application on an android phone).

    With 8 KSPS, using only the timer to start/stop/ I haven't seen this yet, but maybe the bug just needs more time to manifest itself...

Reply
  • Thanks Jørgen.

    I managed to alleviate the problem greatly by using only nrf_drv_timer_disable() without calling nrf_drv_saadc_abort() as I did before.

    However, when I try to increase the sampling rate to 12.5 KSPS and even 10 KSPS, while still maintaining a decimation factor of 8, I can see the channel shifting in real time - even without start/stop (using a monitoring application on an android phone).

    With 8 KSPS, using only the timer to start/stop/ I haven't seen this yet, but maybe the bug just needs more time to manifest itself...

Children
No Data
Related