Current data from the ADC

mikl604
Posts: 44
Joined: Thu Aug 24, 2023 3:15 pm

Current data from the ADC

Postby mikl604 » Fri Dec 13, 2024 11:47 am

Hello everybody!

Can you tell me how to get the most up-to-date data from the ADC in continuous mode? I have 2 ADC channels. I need to read data from them every 10 ms. Moreover, this data should be the most recent at the time of accessing the ADC, and not outdated from the buffer.

Here is the setup of 2 ADC channels for continuous reading at 20000 Hz sampling:

adc_continuous_handle_cfg_t adc_config = // configuring the continuous mode driver
{
.max_store_buf_size = 1536, // 2-frame results buffer ???
.conv_frame_size = 768, // conversion frame for 192 samples of 2 bytes for 2 channels (9.6 ms)
};
adc_continuous_new_handle(&adc_config, &handle_ADC); // initializing the driver
adc_continuous_config_t dig_cfg = // driver configuration
{
.pattern_num = 2, // for 2 ADC channels
.sample_freq_hz = 20000, // Conversion frequency 20kHz (50ms)
.conv_mode = ADC_CONV_SINGLE_UNIT_1, // conversion mode for 1 module
.format = ADC_DIGI_OUTPUT_FORMAT_TYPE1, // output format for 1 module
};

That's how I read the ADC every 10 msec:

adc_continuous_read(handle_ADC, result_ADC, 768, &ret_num, 3); // reading a block of 192 samples for 2 channels

As I understand it, in order to always have a fresh value, the buffer should be designed for only 1 frame, that is .max_store_buf_size should be equal to 768. But if I put 768 there, I get a kernel panic and a constant restart. It works fine only if you make a buffer of 2 frames, i.e. 1536. But in this case, I'm not sure that I'm reading exactly the most recent value, and not the previous one.
What do you recommend to me?

safocl
Posts: 4
Joined: Thu Dec 12, 2024 1:53 am

Re: Current data from the ADC

Postby safocl » Fri Dec 13, 2024 8:16 pm

struct adc_continuous_handle_cfg_t have
uint32_t flush_pool
Flush the internal pool when the pool is full.
member
adc_continuous_handle_cfg_t::flags : set the flags that can change the driver's behavior. flush_pool: auto flush the pool when it's full.
(https://docs.espressif.com/projects/esp ... allocation).

Without
flush_pool=1
then
When the pool is full, a pool overflow event will emerge.
(https://docs.espressif.com/projects/esp ... flow-event)

maybe the kernel panic is related to this?

mikl604
Posts: 44
Joined: Thu Aug 24, 2023 3:15 pm

Re: Current data from the ADC

Postby mikl604 » Mon Dec 16, 2024 7:03 am

Thanks
I tried it. With self-cleaning installed and a buffer of 768, there is a constant restart: one of the tasks gets a stack overflow. It only works with a buffer more than 2 times the size of the frame.

Who is online

Users browsing this forum: No registered users and 1 guest