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

SAADC Sample Convert Bug

I am using the SAADC on the nRF52832, SDK12.2.0, with it set to 12 bits and low power mode. I have enabled five channels which I run blocking nrf_drv_saadc_sample_convert conversions on periodically, currently once a second.

When I print the results out via RTT every second sample is incorrect. I have looked at both my conversion math and the counts value and the problem is in the count value returned from the ADC. See below, the converted result should be ~2.4V but i get 2.4V, then one second later 4.4V.

2.396097
4.437609
2.392563
4.437609
2.390207
4.444677

I added a print statement to see if the interrupt being called (which it shouldn't since it's disabled in the call to nrf_drv_saadc_sample_convert but to my surprise it was being called.

SAADC_EVENT STARTED 2.396097
SAADC_EVENT STARTED 4.437609
SAADC_EVENT STARTED 2.392563
SAADC_EVENT STARTED 4.437609
SAADC_EVENT STARTED 2.390207
SAADC_EVENT STARTED 4.444677

Taking closer look at nrf_drv_saadc_sample_convert I found that a call to nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED) is required after the conversion is finished.

Here is my patch for nrf_drv_saadc_sample_convert

@@ -333,6 +333,7 @@
     {
         timeout--;
     }
+    nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED);
     nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
 
     if (m_cb.active_channels > 1)

This bug also seems to be in SDK 13.0.0-1.alpha.

Can someone from Nordic please comment on my proposed solution?

EDIT Feb. 7,/17 : Attaching a main.c that demonstrates the issue. This main.c is modified version of SDK12.2.0 blinky_FreeRTOS example.

main.c

Cheers, Darren

Related