[SOLVED] Enable interrupts from inside a timer interrupt
castortiu Tue Jan 16, 2018 1:45 am
I need to start a timer and make it fire from inside another timer interrupt, basically I need another timer to fire even when the other timer calls has not finished.
Seems that HardwareTimer disable interrupts when it fires because inside timer 2 I start timer 3 but it doesn’t fire until immediate the call to the timer 2 has finished.
The sample below is way oversimplified, but my case is that I need to start timer A when it fires I need to start timer B however timer B may need to fire before the call to A has finished.
Long story short I need to control the brightness of my RGBMatrix, and to do that I need to control the matrix OE (OutputEnable) leg time, however I cannot start this timer until the latch from the last frame has been made, Timer A triggers the latch to make it visible on the matrixx and then proceeds to build the next frame, meanwhile Timer B has to start after the latch and has to be called(fired) to disable OE at an specific time to disable the matrix output.
Hopefully I made myself clear, but the question is very simple, I need to enable interruptions re-entrancy which seems HardwareTimer disables when the interruption fires.
I tried to put interrupts() as first line inside void ISRUpdate but nothing change, ISRUpdate1 is called as soon ISRUpdate finish;
HardwareTimer timerDisplay(2);
HardwareTimer timerDisplayEnabled(3);
timerDisplay.setMode(0, TIMER_OUTPUT_COMPARE);
timerDisplay.setPeriod(100 * microseconds_per_millisecond);
timerDisplay.attachInterrupt(0, ISRUpdate);
timerDisplay.resume();
timerDisplayEnabled.setMode(0, TIMER_OUTPUT_COMPARE);
timerDisplayEnabled.setPeriod(5);
timerDisplayEnabled.attachInterrupt(0, ISRUpdate1);
timerDisplayEnabled.pause();
bool myValue = false;
void ISRUpdate(void)
{
timerDisplay.pause();
…
…
…
timerDisplayEnabled.setPeriod(brightness); // about 100
timerDisplayEnabled.resume();
…
…
// Code in here runs for 500 microseconds, 5x more than the time in the line above
…
…
timerDisplay.setPeriod(XX);
timerDisplay.resume();
// value of myValue still is false, interrupt for timerDisplayEnabled doesn’t trigger until ISRUpdate which was called from the timer 2
// unwind from the stack.
}
void ISRUpdate1(void)
{
timerDisplayEnabled.pause();
myValue = true;
}
