Hi,
I'm working on a project where I need to sample an ADC with an accurate sample rate. It essentially works except that I do not get the correct rate from the timer. It is close but not correct. I have verified this using the clock on my dev board (nRF54L15-DK) and by setting an output pin and measuring with an oscilloscope.
My timer is configured to trigger the ADC 400 times/s (2.5 ms), but when I run it, I most often get a rate around 404 triggers/s. Sometimes it runs at 398 and sometimes at 400.
My code is based on the DevAcademy "Exercise 3 – Interfacing with ADC using nrfx drivers and TIMER/PPI" (academy.nordicsemi.com/.../), and in fact to me it looks like the same problem exists in the example in the exercise. In the example code the timer runs with an interval of 50 us, the ADC fills buffers of 8000 samples which equals to a full buffer every 400 ms. I would expect the timestamps of the log to be 400 ms apart (with some jitter), but instead it looks like they are drifting over time. I see it when running the example on my nRF54L15-DK, and it can be seen in the log at the end of the exercise as well where there is about 399 ms between log entries.
Log from the exercise:
*** Booting nRF Connect SDK ***
[00:00:00.653,900] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples
[00:00:00.653,900] <inf> main: AVG=2064, MIN=2029, MAX=2099
[00:00:01.052,673] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples
[00:00:01.052,673] <inf> main: AVG=2064, MIN=2025, MAX=2097
[00:00:01.451,446] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples
[00:00:01.451,446] <inf> main: AVG=2064, MIN=2028, MAX=2094
[00:00:01.850,097] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples
[00:00:01.850,128] <inf> main: AVG=2062, MIN=2009, MAX=2100
[00:00:02.248,840] <inf> main: SAADC buffer at 0x20001150 filled with 8000 samples
[00:00:02.248,870] <inf> main: AVG=2064, MIN=2029, MAX=2103
[00:00:02.647,521] <inf> main: SAADC buffer at 0x20004fd0 filled with 8000 samples
[00:00:02.647,521] <inf> main: AVG=2064, MIN=2025, MAX=2098
Why do I see this drift? I hope someone can enlighten me.
br
Kristoffer