Re: ADC speed?
Posted: Thu Oct 04, 2018 2:51 am
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).
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).
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.
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);
}
}
}
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?
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.
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.
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.