Better way with ESP32 of Analog-Read on core0.
Posted: Fri Aug 16, 2019 8:55 am
Hello guys!
I have a complicated question.
The thing:
Right now i measure on ADC1 on core0 with the stanrad analogRead() func.
The esp capable running my adc read with 8Khz to read and measure a 4 - 4,4Khz signal from a signal generator.
The way i do it is pretty easy. Iam running a task on the core 0.
The issue:
Sometimes i get completelly different signal width on every single wave, sometimes strange gaps in the signals.Maybe because of the delay between measurements.(The signals are even on an oscilloscope).
The question:
Does anybody know a better way to measure at 8Khz?
I'am visualizing it on a webserver with async web and websockets to a canvas by Chart.js.
Sorry if i forget something.
This is a minimal working sketch in PlatformIO.
I have a complicated question.
The thing:
Right now i measure on ADC1 on core0 with the stanrad analogRead() func.
The esp capable running my adc read with 8Khz to read and measure a 4 - 4,4Khz signal from a signal generator.
The way i do it is pretty easy. Iam running a task on the core 0.
The issue:
Sometimes i get completelly different signal width on every single wave, sometimes strange gaps in the signals.Maybe because of the delay between measurements.(The signals are even on an oscilloscope).
The question:
Does anybody know a better way to measure at 8Khz?
I'am visualizing it on a webserver with async web and websockets to a canvas by Chart.js.
Sorry if i forget something.
This is a minimal working sketch in PlatformIO.
Code: Select all
#include <Arduino.h>
TaskHandle_t TaskHandle_2; // CREATE TASK TANDLE
/* ADC SETTINGS AND THE MEASURE FUNCTION */
#define CHANNEL 34 // ADC1 BECAUSE OF THE WIFI
uint16_t offset = 1757; //middle DC level reading
uint16_t vReal[200]; // BUFFER TO READ
double samplingFrequency = 80000; // IN HZ
unsigned long microseconds;
unsigned int sampling_period_us = round(1000000*(1.0/samplingFrequency));
uint16_t samples = 200; //READ SAMPLES
static const inline void ADC_Meres() {
if (olvasunk_e == true) { // ADC MEASURE TURN ON FLAG
microseconds = micros(); // LET'S SEE WHERE ARE WE
uint32_t volatile register ilevel = XTOS_DISABLE_ALL_INTERRUPTS; // SAVE THE INTERRUPTS TO A VOLATILE AND TURN ALL OF IT OFF
for (int i = 0; i < samples; i++) { // BEGIN THE SAMPLING WITH 8KHZ
vReal[i] = analogRead(CHANNEL); // READ THE SIGNAL ON I/O-34
while (micros() - microseconds < sampling_period_us) {} // WAIT THE DESIRED MICROS
microseconds += sampling_period_us;
}
XTOS_RESTORE_INTLEVEL(ilevel); // RETURN INTERRUPT LEVEL
}
}
void setup(){
Serial.begin(115200);
xTaskCreatePinnedToCore ( loop0, "v_getIMU0", 30000, NULL, 10, &TaskHandle_2, 0 );
}
static void loop0(void * pvParameters){
for( ;; ){
vTaskDelay(1); // REQUIRED TO RESET THE WATCH DOG TIMER
ADC_Meres(); // 8Khz ANALOG READ
}
}
void loop(){
}