Changing timer alarm in ISR
Posted: Mon Feb 25, 2019 5:28 pm
Hi,
I'm trying to use hardware timer interrupts to change a pin's output between high and low for varying durations. To do this, I change the timer alarm value in the ISR. However, calling the timerAlarmWrite function in the ISR causes A Guru Meditation Error:
The relevant code is as follows:
I understand this is happening because timerAlarmWrite is not an IRAM_ATTR function. So my question is, is there an IRAM safe way of changing the alarm value that can be called from within an ISR?
Thanks.
I'm trying to use hardware timer interrupts to change a pin's output between high and low for varying durations. To do this, I change the timer alarm value in the ISR. However, calling the timerAlarmWrite function in the ISR causes A Guru Meditation Error:
Code: Select all
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x401abe54: bad00bad bad00bad bad00bad
Code: Select all
#define PIN_A 32
hw_timer_t * timerA = NULL;
volatile bool dcA = false;
int durationON = 80000;
int durationOFF = 120000;
void IRAM_ATTR onTimerA() {
if (dcA) // ON cycle
{
digitalWrite(PIN_A, LOW);
dcA = false;
timerAlarmWrite(timerA, durationON, true);
}
else // OFF cycle
{
digitalWrite(PIN_A, HIGH);
dcA = true;
timerAlarmWrite(timerA, durationOFF, true);
}
}
void setup() {
pinMode(PIN_A, OUTPUT);
timerA = timerBegin(2, 80, true);
timerAttachInterrupt(timerA, &onTimerA, true);
timerAlarmWrite(timerA, durationON, true);
timerAlarmEnable(timerA);
}
void loop() {
}
Thanks.