Page 1 of 1

Buffer size - ADC continuous mode

Posted: Fri Apr 04, 2025 1:17 pm
by crivi30
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!

Re: Buffer size - ADC continuous mode

Posted: Thu Jul 10, 2025 9:19 am
by fengcai
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