Hi,
Nice to meet you. I am a new entry in this forum, looking for help
I have this setup: D1 mini ESP32 program using PlatformIO and Arduino framework
My goal is run an ISR as fast as possible ( at least >100 000 HZ ) while running the loop task for monitor values from ISR and print data trough serial
Currently I was able to run up to 25 000 HZ, higher rate will crash the MCU
Code here
#include <Arduino.h>
hw_timer_t * timer3 = NULL;
volatile long timerCounter = 0;
volatile float a, b;
static const uint16_t timir_divider = 80;//F = 1 000 000
static const uint64_t timir_max_count = 40;
static long tick_5s = 5000000/timir_max_count;
void IRAM_ATTR onTimer3() {
REG_WRITE(GPIO_OUT_W1TC_REG, BIT4);
timerCounter++;
a = a + 0.0000000001f;
b = b + a;
if(b > 100000.0f){
a = 0.0f;
b = 0.0f;
}
}
void setup() {
pinMode(4,OUTPUT);
REG_WRITE(GPIO_OUT_W1TS_REG, BIT4);
delay(500);
// Initialize Serial Monitor
Serial.begin(115000);
timer3 = timerBegin(3, timir_divider, true);
timerAttachInterrupt(timer3, &onTimer3, true);
timerAlarmWrite(timer3, timir_max_count, true);
timerAlarmEnable(timer3);
}
void loop() {
if(timerCounter > (tick_5s)){
timerCounter = 0;
Serial.println("cycle");
}
}