Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not real time update from adc_digi_read_bytes (IDFGH-6755) #8383

Open
eos1d3 opened this issue Feb 11, 2022 · 1 comment
Open

Not real time update from adc_digi_read_bytes (IDFGH-6755) #8383

eos1d3 opened this issue Feb 11, 2022 · 1 comment
Assignees
Labels
Status: Opened Issue is new

Comments

@eos1d3
Copy link

eos1d3 commented Feb 11, 2022

Environment

  • Development Kit: [ESP32-S2-Saola-1]
  • Kit version : v1.2
  • IDF version: ESP-IDF Release v4.4
  • Build System: idf.py
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2) 8.4.0
  • Operating System: macOS
  • Using an IDE?: [VS Code]
  • Power Supply: [USB]

Problem Description

The ADC readings on console are not updated immediately. It can take up to 60 seconds to see new value.

//Detailed problem description goes here.
It seems each call to adc_digi_read_bytes, it returns a lot of old ADC values and current ADC values are not read immediately. By connecting one ADC pin to GND and start the board, first reading are all 0. Then connect 3.3V to the same ADC pin, the console is still showing 0 reading for up to 60 seconds.

Expected Behavior

Change of ADC voltage will see real time update reading in console.

Actual Behavior

Huge delay to see ADC value changes (depends on ADC settings below):

#define TIMES              256
vTaskDelay(1);             // at line 161 in the example

The above needs 5 seconds delay to see new value.

#define TIMES              16
vTaskDelay(100);           // at line 161 in the example, change to 1 second delay

The above needs 60+ seconds delay to see new value.

Steps to reproduce

1. Copy ADC DMA Example: https://github.com/espressif/esp-idf/blob/master/examples/peripherals/adc/dma_read/main/adc_dma_example_main.c
2. For easy debugging, use only ADC1 as shown in the code below:

#define ADC_CONV_MODE       ADC_CONV_SINGLE_UNIT_1 
#define ADC_OUTPUT_TYPE     ADC_DIGI_OUTPUT_FORMAT_TYPE1  

. . . 

static adc_channel_t channel[2] = {ADC1_CHANNEL_2, ADC1_CHANNEL_3};

@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 11, 2022
@github-actions github-actions bot changed the title Not real time update from adc_digi_read_bytes Not real time update from adc_digi_read_bytes (IDFGH-6755) Feb 11, 2022
@eos1d3
Copy link
Author

eos1d3 commented Feb 11, 2022

The concept of saving old and outdated ADC values in ringbuffer is likely wrong. Old ADC values are actually useless and must be ignored. Each time a call to get the ADC values must all be the current values.

For example, if ADC is used for over-current detection, the response time is too slow and all values are actually irrelevant any more.

I use a lot ST 8-bit and 32-bit MCU and never see this kind of ringbuffer implementation. For continuous ADC reading, ST DMA will just update current values to an integer array, from first channel to last channel and then restart repeatedly. Old values are overwritten in the array. So the array always contain real time values.

With STM32 MCU, it has hardware oversampling so that the ADC will continuously scan selected channels in 2x, to 256x times. And it will divide the sum of each channel by number of oversampling with hardware. Optionally the ADC can be programmed to right shift the sum of each channel automatically from 1 to 8 bits, so the width of ADC bits adjust from 12 bits to 16 bits.

ESP does not have hardware oversampling, but I think it is better to do similar way by by using interrupt.

In the ADC DMA example, I used 2 ADC channels, adc_digi_read_bytes returns 128 values. This consumes a lot of memory with the structure of each element. With ST approach, it is just an array of two integer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

3 participants