-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Open
Labels
Status: OpenedIssue is newIssue is new
Description
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
General issue report
When querying multiple channels with continuous ADC, I have noticed that the sample count per second does vary quite a bit for each channel, whilst the overall count per second remains constant.
Sample code
adc_continuous_handle_t c_handle = nullptr;
const adc_continuous_handle_cfg_t c_cfg = {
.max_store_buf_size = I2S_DMA_BUF_LEN*4,
.conv_frame_size = I2S_DMA_BUF_LEN,
};
adc_continuous_new_handle(&c_cfg, &c_handle);
adc_continuous_config_t dig_cfg = {
.pattern_num = 6,
.sample_freq_hz = 6 * 1000 * 200, // 100 samples per solenoid per ms
.conv_mode = ADC_CONV_SINGLE_UNIT_1,
.format = ADC_DIGI_OUTPUT_FORMAT_TYPE1,
};
adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
for (int i = 0; i < 6; i++) {
adc_pattern[i].atten = ADC_ATTEN_DB_11;
adc_pattern[i].channel = sample_channels[i] & 0x7;
adc_pattern[i].unit = ADC_UNIT_1;
adc_pattern[i].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH; // 12bits
}
dig_cfg.adc_pattern = adc_pattern;
adc_continuous_config(c_handle, &dig_cfg);
adc_continuous_start(c_handle);
esp_err_t ret;
uint32_t samples[adc_channel_t::ADC_CHANNEL_9]; // Indexes all ADC channels like this
uint32_t now = GET_CLOCK_TIME();
while(true) {
ret = adc_continuous_read(c_handle, adc_read_buf, I2S_DMA_BUF_LEN, &out_len, portMAX_DELAY);
if (ret == ESP_OK) {
for (int i = 0; i < out_len; i += SOC_ADC_DIGI_RESULT_BYTES) {
adc_digi_output_data_t *p = (adc_digi_output_data_t*)&adc_read_buf[i];
samples[p->type1.channel]++;
}
first_read_complete = true;
if (GET_CLOCK_TIME() - now > 1000) {
now = GET_CLOCK_TIME();
uint64_t total = 0;
for (int i = 0; i < (uint8_t)adc_channel_t::ADC_CHANNEL_9; i++) {
printf("Channel %d - %lu\n", i, samples[i]);
total += samples[i];
samples[i] = 0;
}
printf("--TOTAL %llu --\n", total);
}
}
}
Output:
As you can see, whilst the total sample count per second remains constant, the count per channel varies quite a bit.
Is there any reason for this behaviour?
Metadata
Metadata
Assignees
Labels
Status: OpenedIssue is newIssue is new