Sampling ADC with PPI and Timer on nrf connect sdk

Description: I’m working on an nRF52 project where I need the SAADC to sample at a specified interval (5000 ms in this example) using a timer and PPI to trigger sampling. However, I’m observing that the sampling does not follow the timer’s rate, the initial trigger works as expected, but subsequent samples do not follow the timer rate, even though I set the sampling rate as 5000ms the samples are continuously being printed. I suspect the issue may lie with the PPI setup between the SAADC END and START events, but I haven’t been able to pinpoint the exact cause.

Setup:

  1. Timer Configuration: Set up with nrfx_timer_extended_compare to trigger every 5000ms( example)

  2. PPI Channels: Configured two PPI channels:

  3. Issue: The SAADC samples does not follow the 5000 ms interval set by the timer.

The code:-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(ADC_CONSOLE,LOG_LEVEL_DBG);
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/uart.h>
#include <nrfx_saadc.h>
#include <nrfx_timer.h>
#include <helpers/nrfx_gppi.h>
#include <nrfx_ppi.h>
s
#define SAADC_SAMPLE_INTERVAL_MS 5000
#define TIMER_INST_IDX 0
#define SAADC_BUFFER_SIZE 2
#define MESSAGE_QEUEE_BUFFER_SIZE SAADC_BUFFER_SIZE * 20
#define STACKSIZE 1024
#define CONSOLE_THREAD_PRIORITY 7
typedef struct data{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The prj.conf:-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CONFIG_LOG=n
# CONFIG_LOG_DEFAULT_LEVEL=3
# CONFIG_LOG_MAX_LEVEL=2
# CONFIG_LOG_MODE_DEFERRED=n
# CONFIG_LOG_BACKEND_UART=y
CONFIG_PRINTK=y
CONFIG_GPIO=y
# enable uart driver
CONFIG_SERIAL=y
# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_ASYNC_API=y
# CONFIG_DEBUG_THREAD_INFO=y
# CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_NRFX_SAADC=y
CONFIG_NRFX_PPI=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Project Details:

DK- nrf52832

SDK - nrf connect sdk for vs code (v2.5.2) on ubuntu