I'm working on a project that uses Bluetooth to interface with my software so I chose a ESP32-E Firebeetle Board.
I recently changed my code to use timer interrupts rather than the crude delay that was fine for scoping out the project initially.
My problem is that the "onTimer" event doesn't fire...
to rule out something in my code causing the issue, I fired up the first Example from here:
https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/timer.html
this example failed to fire the "onTimer" either.
So I took another simple interrupt example and queried the timervalue in the main loop (code below).
I found a few interesting things by doing this, but don't understand what the fundamental issue is.
When I looked at the serial output I noticed that:
-
The first time the timer get to 1,000,000 the timer value resets, after this first occurrence it just keeps increasing.
-
The Timer is incrementing at around 78000 ticks. Since I have 500mS delay and the timer prescaler is 80, then I would expect this to be roughly 500000 ticks....So the timer is running slower than expected???
If I change the prescaler in the timer begin method from 80 to 8, then the Timer still increments at the same 78000 ticks per main loop.
This has been driving me mad all day.
I only have the 1 Firebeetle board to try, & no other ESP32 devices kicking around to try.
My module does not have any thing else connected to it.
I've also tried timers 0 thru to 3 and get the same result.
I've tried using Arduino IDE 1.8.19 and IDE 2.1.1, and am running the df robot EPS32 board package 0.2.1
If anyone can point me in the right direction I'd appreciate it. right now I'm just thinking that somehow my board is borked, or there is an issue with the DF robot library?
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++;
//Serial.print("interrupt");
portEXIT_CRITICAL_ISR(&timerMux);
}
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1000000, true);
timerAlarmEnable(timer);
}
void loop() {
delay(500);
Serial.print("timer Value: ");
Serial.println(timerRead(timer));
Serial.print("interuppt counter: ");
Serial.println(interruptCounter);
if (interruptCounter > 0) {
portENTER_CRITICAL(&timerMux);
interruptCounter--;
portEXIT_CRITICAL(&timerMux);
totalInterruptCounter++;
Serial.print("An interrupt as occurred. Total number: ");
Serial.println(totalInterruptCounter);
}
}