Current data from the ADC
Posted: 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?
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?