Buffer size - ADC continuous mode

crivi30
Posts: 1
Joined: Fri Apr 04, 2025 1:01 pm

Buffer size - ADC continuous mode

Postby crivi30 » Fri Apr 04, 2025 1:17 pm

Hello, I need help calculating the buffer size in ADC continuous mode.
Let's say I want to read 128 samples for 5 ADC channels (128 x 5 = 640 samples in total).

Code: Select all

#define NUM_CHANNELS 5
#define SAMPLES 128
#define FRAME (SAMPLES * sizeof(adc_digi_output_data_t))
If I want to store only one conversion frame, should I set MAX_BYTE_RNG as:

Code: Select all

#define MAX_BYTE_RNG FRAME 
or maybe

Code: Select all

#define MAX_BYTE_RNG FRAME * NUM_CHANNELS
---

Then, configuring the ADC handle:

Code: Select all

adc_continuous_handle_cfg_t adc_config;
adc_config.max_store_buf_size = MAX_BYTE_RNG;
adc_config.conv_frame_size = FRAME;

When reading the returned buffer:

Code: Select all

int max_len = FRAME * NUM_CHANNELS;
esp_err_t ret;
adc_digi_output_data_t result[max_len] = {0};

ret = adc_continuous_read(stream_handle, result, max_len, len_out, 0);
with MAX_BYTE_RNG = FRAME, I receive a buffer of 128 samples interleaved instead of 640.
with MAX_BYTE_RNG = FRAME*NUM_CHANNEL, I receive a buffer with random number of samples (128,256,640).

Can someone clarify this?

Thank you in advance!

fengcai
Posts: 2
Joined: Sat Nov 09, 2024 2:22 am

Re: Buffer size - ADC continuous mode

Postby fengcai » Thu Jul 10, 2025 9:19 am

the doc sucks. i'm playing around with this API as well. according to sample code, all parameters are in bytes , which means:

samples = bytes/ [bytes per sample] / channels

Who is online

Users browsing this forum: Bing [Bot], ChatGPT-User and 2 guests