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

Calibrating SAADC on nrf52832

Hi,

I am using an nRF52832 with S132 and SDK v15.0.0 and already read in the forum about issues related to the SAADC calibration (inlcuing the erratum  [86]). The problem I have is that the ADC constantly (not only once!) delivers wrong data after I call the calibrate_offset function.

The stuff that happens over time is basically:

-> The SAADC is initialised

-> the channels (2) are initialised

-> the buffer_convert function is called

-> (because the buffer-convert funtion was already called and the SAADC is in IDLE although no START or SAMPLE task was triggered yet) -> the nrfx_saadc_abort() function is called

This is the first point, where somthing goes wrong since sometimes the nrfx_saadc_abort() itself hangs when waiting for the SAADC to become IDLE again. Do I have to do a dummy TASK_SAMPLE before calling the abort function so that a conversion is in progress? it seems that simply aborting without issuing a SAMPLE before fails in waiting for "NRFX_WAIT_FOR((m_cb.adc_state != NRF_SAADC_STATE_IDLE), HW_TIMEOUT, 0, result);". (But I have to call the abort function to get into IDLE after calling buffer_convert?)

->  nrfx_saadc_calibrate_offset() is called

-> The values i get from this time by calling TASK_SAMPLE  are wrong

Besides of the concrete problem, I have the following questions, wo which I did not yet find an answer to.

1.) I am NOT using SAADC in LP Mode. Is the workaround for the erratum [86] still necessary for SDK V15.0.0 or is ia patch alredy somehow included in v15?

2.) I am unsure about how to implement the workaround. It is described as Stopping the SAADC after calibration, but stopping seems to invole waiting for an STOPPED EVENT. Do i have to wait and therefore somehow poll for that event? What is an easy way to do that?

3.) In all the SAADC examples, I see that the event handler checks for the NRFX_SAADC_EVT_DONE event and gets the data from the buffer. Why is that done, when there is explicitly stated that this event does not guaratee that the samples are already in RAM? Why not waiting for the END event? The p_buffer->type does not even seem to expose the END event? Why is that?

4.) I see that in examples, in the Event handler the occurence of the event CALIBRATEDONE is used to again call buffer_convert to set up the buffer again. If i call the calibrate_offset function before a call to buffer_convert, i guess thats a problem because in the event handler the buffer is set to the last one used, but there is no (useful) "last" buffer in this case?)

5.) Could someone provide a minimal working example (minimal main program plus callback) for just initialising the ADC / the ADC channels, perform calibration and set up the buffer for a "real" conversion directly after a startup? All the examples I found use cyclic turning on/off or inti / uninits that make things a bit unclear for a basic understanding.

Thanks a lot!

  • Hi!

    I would have to check next week since I do not remember the exact code that I used to get rid of the described error. I only remeber that I changes my ADC code to only have one channel enabled at a time. I can send you the piece in a few days if you whish. One BIG word of caution, though.

    Although I managed to get rid of the error and calibration in regular interval does not throw errors, I have the feeling that calibration does not work at all on the 52832. Of course I cannot prove that or be sure, but  we invested a lot of time to measure the code the adc delivers on a number of boards under controlled thermal conditions and we had one devkit with nrf52832 where the calibration even made things worse than without any calibration.

    I had another private ticket open on a similar topic because of confidential code, but we never managed to get rid of problems with bad performance of calibration (we have "jumps" in the signal of about 6 LSB12b, which might be ok from a datasheet perspective, but does defeat the purpose of the calibration unless you use a very wide temperature range).

    BR

  • Thanks for sharing your experiences. Indeed, as you found, I can get calibration to run successfully once at startup (but not again), but I too am not observing much improvement. Without calibration, I am measuring GROUND at -1 to -2 raw value (10-bit). Calibration will sometimes bring this to zero, but sometimes not. Have not tried yet under temperature variations.

    If you are able to dig up the old code, it might be of use to me & others using this ticket in the future. It seems to come up pretty high in search results :-)

Related