I tried this code, but doesn’t work. For some reason i can’t decrease period time between samples to less than 0,667 [ms], even when i change the middle parameter in timerAlarmWrite. In this case i putted in 0,5 [ms].
#include <Arduino.h>
#include "esp_timer.h"
volatile int interruptCounter;
int totalInterruptCounter;
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&timerMux);
}
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 500, true);
timerAlarmEnable(timer);
}
void loop() {
if (interruptCounter > 0) {
portENTER_CRITICAL(&timerMux);
interruptCounter--;
Serial.println((analogRead(12)-1937)*0.681);
portEXIT_CRITICAL(&timerMux);
}
}