ADC speed?
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: ADC speed?
From my notes, the sample rate you have to set for ADC acquisition on the current esp-idf is (actual_sample_rate)/(bits_per_sample).
Re: ADC speed?
So you mean to read 6ksps from adc 12bit per sample, should i set i2c sampling frequency to the 12x6 = 72khz ?ESP_Sprite wrote:From my notes, the sample rate you have to set for ADC acquisition on the current esp-idf is (actual_sample_rate)/(bits_per_sample).
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: ADC speed?
No:
- The sample depth is the I2S sample depth you specify when initializing the driver, most likely you use 16bit/sample.
- You need to divide, so 6000 samples/s and 16 bit means 6000/16=375.
- The sample depth is the I2S sample depth you specify when initializing the driver, most likely you use 16bit/sample.
- You need to divide, so 6000 samples/s and 16 bit means 6000/16=375.
Re: ADC speed?
here is a small test code , i think i2s driver is not reliable.ESP_Sprite wrote:No:
- The sample depth is the I2S sample depth you specify when initializing the driver, most likely you use 16bit/sample.
- You need to divide, so 6000 samples/s and 16 bit means 6000/16=375.
Whit this code i can read 5.977 (less than 6) times 100 from serial port.
It means 5.977 * 1000(buffer size) = 5977sample per second not 6000!
Second problem is ; if i set SAMPLE_RATE less than some value 6000 , real result is very different than setting.
For example if i set it to 5000, it gives 270000 sample per second .
How can i solve such problems ?
Code: Select all
#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_log.h"
#include "driver/i2s.h"
#include "soc/syscon_reg.h"
#include "driver/adc.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
uint32_t SAMPLE_RATE = 6000;
uint32_t NUM_SAMPLES = 1000;
static QueueHandle_t i2s_event_queue;
void setup(){
Serial.begin(115200);
Serial.printf("%d :",APB_CLK_FREQ);
i2s_config_t i2s_config ;
i2s_config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
i2s_config.sample_rate = SAMPLE_RATE;
i2s_config.dma_buf_len = NUM_SAMPLES;
i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
i2s_config.use_apll = false,
i2s_config.communication_format = I2S_COMM_FORMAT_I2S;
i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1;
i2s_config.dma_buf_count = 2;
i2s_driver_install(I2S_NUM_0, &i2s_config, 1, &i2s_event_queue);
i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_0);
i2s_adc_enable(I2S_NUM_0);
}
void loop(){
uint16_t i2s_read_buff[NUM_SAMPLES];
system_event_t evt;
if (xQueueReceive(i2s_event_queue, &evt, portMAX_DELAY) == pdPASS) {
if (evt.event_id==2) {
i2s_read_bytes(I2S_NUM_0, (char*)i2s_read_buff,NUM_SAMPLES*2, portMAX_DELAY);
Serial.write(100);
}
}
}
Re: ADC speed?
Your code is exactly what I have been looking for trying to dma an adc buffer. However when I change the input from ADC Chan 0 to ADC chan 5, IO33 that I am using. I appear to have a value of 24575 at 0V and 20480 at 3.3V.
What are these values actually supposed to represent? they're linear and scale between the two voltages but assuming that I had to do some silly math like:
(val-24575)*-1
All the adc values are there, but what am I actually reading? Some sort of I2S scaled raw data that fits into the I2C protocol?
What are these values actually supposed to represent? they're linear and scale between the two voltages but assuming that I had to do some silly math like:
(val-24575)*-1
All the adc values are there, but what am I actually reading? Some sort of I2S scaled raw data that fits into the I2C protocol?
Re: ADC speed?
I just got a ESP32 and wanted to know this, the speed depends on the ADC averaging and the ADC bit resolution. So I found the following sample times. Averaging parameter k goes in rows and the bit resolution k goes in columns. All times are in microseconds.
9 10 11 12
1 9.6 9.9 10.1 10.2
2 12.2 12.6 12.7 13.0
4 17.4 17.8 18.5 18.9
8 27.9 28.8 29.9 30.8
16 49.0 50.9 52.9 54.9
I guess everything depends on the clock and bus speeds in the ESP32, but this is what I found. In other words, the ADC sampling frequency can go up to 20 to 100kHz and it mainly depends on the number of averaging cycles by the ADC. ADC averaging cycles and resolution can be modified with the functions analogSetClockDiv(k) and analogReadResolution(j) where "k" is between 1 and 16 cycles and j between 9 and 12 bits.
9 10 11 12
1 9.6 9.9 10.1 10.2
2 12.2 12.6 12.7 13.0
4 17.4 17.8 18.5 18.9
8 27.9 28.8 29.9 30.8
16 49.0 50.9 52.9 54.9
I guess everything depends on the clock and bus speeds in the ESP32, but this is what I found. In other words, the ADC sampling frequency can go up to 20 to 100kHz and it mainly depends on the number of averaging cycles by the ADC. ADC averaging cycles and resolution can be modified with the functions analogSetClockDiv(k) and analogReadResolution(j) where "k" is between 1 and 16 cycles and j between 9 and 12 bits.
-
- Posts: 2
- Joined: Sun Dec 15, 2019 2:49 pm
Re: ADC speed?
Hey!
I am a newbie with the ESP32 world.
I tried running the example program of peripherals/adc and found that each conversion took about 40us.
That mean, a sampling speed of 25K Samples/second.
Is that really possible or I am being mistaken?
I am a newbie with the ESP32 world.
I tried running the example program of peripherals/adc and found that each conversion took about 40us.
That mean, a sampling speed of 25K Samples/second.
Is that really possible or I am being mistaken?
Re: ADC speed?
As reported in an earlier post in this thread, I have measured 9.5μs (including the time taken to store in an array). This agrees with the measurements made by PA1EJO (with averaging parameter set to 1).KhushalShah wrote: ↑Sun Dec 15, 2019 2:54 pmI tried running the example program of peripherals/adc and found that each conversion took about 40us.
That mean, a sampling speed of 25K Samples/second.
Is that really possible or I am being mistaken?
However . . . . .
BaartCM wrote: ↑Sat Sep 08, 2018 1:19 pmI found out by experimenting that I can read the adc’s at a much higher rate than 6k but that the data is garbage. If I sample vibration readings from a motor at say 4K sps, I get a peak at the correct frequency when I do an fft but if I sample at a higher rate than 6k, the peak is not at the correct frequency and the fft content is rubbish.
It's still not clear to me why the bandwidth limit is said to be . . . . .
I guess the limit is due to the fact that, unlike Atmel microcontrollers, the ESP32 does not have a sample-and-hold circuit (that we know of).ESP_Sprite wrote: ↑Wed Apr 18, 2018 8:45 amThe bandwidth of the ADC just is more-or-less 6KHz if you want a linear frequency response.
I understand 6kHz is the analogue bandwidth limit, not a recommended maximum sample rate.
-
- Posts: 1
- Joined: Wed Feb 03, 2021 11:28 pm
Re: ADC speed?
Buen día
Actualmente estoy trabajando en un proyecto para análisis de vibraciones, utilizo la placa ESP32 WROOM32 y tomo muestras de uno de los canales de ADC cada 40 microsegundos sin problema, esto equivale a muestrear la señal a una frecuencia de 25khz, con lo que podemos realizar espectro FFT con rango hasta 12.5khz. ¿Entonces todo lo que este arriba de 6khz no es confiable?
Actualmente estoy trabajando en un proyecto para análisis de vibraciones, utilizo la placa ESP32 WROOM32 y tomo muestras de uno de los canales de ADC cada 40 microsegundos sin problema, esto equivale a muestrear la señal a una frecuencia de 25khz, con lo que podemos realizar espectro FFT con rango hasta 12.5khz. ¿Entonces todo lo que este arriba de 6khz no es confiable?
Re: ADC speed?
Hello Strontium,
i'm interested on you project. Could you give us an update?
Many thanks!!
i'm interested on you project. Could you give us an update?
Many thanks!!
Strontium wrote: ↑Wed Jul 11, 2018 3:32 amI am working on a development module that will have (among other things) 7 ADC inputs capable of 12 bit @ 1Msps. I am just finishing the layout now and will post more information elsewhere, however if you are interested in a small ESP32 based module with this feature drop me a PM and i will keep you updated.
Who is online
Users browsing this forum: amiral, Orange_Murker and 104 guests