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

Sampling data with 4 ADC channels on NRF52 (BL654 module)

Hello,

I'm using BL654 module (nrf52840 inside); SDK15; softdevice s140; IAR.

In my projects I'm using peripherals: I2C(TWI), SPI. Project based on ble_app_uart example (most of sdk_config.h are default, exept TWI/SPI instances and timer3)

My goal is to add sampling data from 4 analog input channels:

Channel 1 - input 0;

Channel 2 - input 5;

Channel 3 - input 4;

Channel 4 - input 7;

My code for SAADC:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define SAMPLES_IN_BUFFER 4
#define BUFFERS_IN_CH 2
#define SAADC_SAMPLE_PERIOR_MS 1000
volatile uint8_t state = 1;
static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(3);
static nrf_saadc_value_t m_buffer_pool[BUFFERS_IN_CH][SAMPLES_IN_BUFFER];
static nrf_ppi_channel_t m_ppi_channel;
static uint32_t m_adc_evt_counter;
void timer_handler(nrf_timer_event_t event_type, void * p_context)
{
//
}
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Main(removed stuff with TWI and SPI):

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(void)
{
uart_init();
log_init();
timers_init();
power_management_init();
ble_stack_init();
//printf("ble_stack started...\r\n");
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
SAADC_Init();
// Start execution.
advertising_start();
// Enter main loop.
for (;;)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Problem:

Channel's position numbers doest match their positions in output. And sometimes hopping in arrays...

For example, I'm shorting AIN0 (channel #1) to GND and thats what I see under debug:

AIN5 (channel #2):

AIN4 (channel #3):

AIN7 (channel #4):

And one more things I would like to ask:

Since TIMER0 is used by softdevice, I'm using TIMER3 for SAADC. Am I correct that in saadc_sampling_event_init() I shoud compare events/adresses for TIMER3?

Regards

  • Hi,

     

    I setup your configuration in the peripheral/saadc example, and tried to replicate the issue, but unfortunately; I was not able to do so.

    I connected AIN0 and AIN4 to VDD, AIN5 and AIN7 to GND, and the output is always consistent (+/- a bit of jitter):

    Fullscreen
    1
    2
    3
    4
    5
    <info> app: ADC event number: 118
    <info> app: channel: 0 value: 854
    <info> app: channel: 5 value: -2
    <info> app: channel: 4 value: 840
    <info> app: channel: 7 value: -2
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    Do you see this issue often? Or is it something that occurs only in corner cases?

     

    Kind regards,

    Håkon