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

SAADC scan mode sample order is not always consistent

I am seeing a problem using the nRF52 SAADC with two analog channels enabled in scan mode. Essentially, channel 0 is measuring an analog signal with gain ~= 15 while channel 1 is measuring the same signal with gain = 1.

The ADC is sampled in scan mode at 4kHz into a buffer that holds 2048 samples for each channel. When I receive the interleaved buffer, I usually see that the channel 0 ADC data is at address offset 0, 4, 8, etc and the channel 1 data is at address offset 2, 6, 0xa, etc.

Unfortunately, sometimes these channels are swapped. (ie. the channel 0 data is at address offset 2, 6, 0xa,... and the channel 1 data is at address offsets 0, 4, 8, ....).

Is there anything I can do to ensure that channel 0 data starts at offset 0 and channel 1 data starts at offset 2?

Here is a printf from the code that shows the peak value of each channel as well as the buffer address:

Capture 1:

base_ptr=0x20003028, peak=1363.000000

base_ptr=0x2000302a, peak=86.000000

Capture 2:

base_ptr=0x20005028, peak=1342.000000

base_ptr=0x2000502a, peak=96.000000

Capture 3:

base_ptr=0x20003028, peak=92.000000

base_ptr=0x2000302a, peak=1352.000000

As you can see, the first two captures have the higher gain signal in the 0 offset position as expected. However, the third capture has the lower gain signal in the 0 offset position.

Is there something I need to do to the EasyDMA module to reset between captures? Currently, I am just calling nrf_drv_saadc_buffer_convert() to start a new capture.

I am using SDK version 11.0.0 and S132 version 2.0.1

Parents Reply Children
  • The example I presented above was simplified in order to make it brief. A full examination of both channel's data shows that it is not simply a sampling rate limitation (peak error). I am sampling at 4kHz and the signal is bandwidth limited at 1kHz. The two channels' data can be compared directly and it is clear that one channel's data is always ~15 times larger than the other (at every data point). The problem is that sometimes that channel has address offset 0 and sometimes it has address offset 2.

    I am wondering if this problem could be due to the fact that my code occasionally calls nrf_drv_saadc_abort(). I am thinking there may be a bug somewhere in the driver if abort is called at the wrong time or possibly the state doesn't get cleared properly for my next call tonrf_drv_saadc_buffer_convert().

    buffer size: 2048 * 2 * sizeof(int16) = 8096 (2 byte aligned) sample rate is 4kHz