- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to implement a rapid blink of the LED. I have a watchdog timer that goes off every 100 ms . In the timer ISR I set a toggle blink flag to tell the main loop to write a value to the LED This works for the most part but occasionally the LED stays on or off longer than 100 ms/ I think it's because the main loop executes slower and less regularly than the timer. and the flag value gets out of sync with the current value of the LED.
WDT_ISR()
{
toggle_blink = !toggle_blink;
}
main loop
if(toggle_blink)
WriteLED(!ReadLED());
So the question is, is it OK to call WriteLED from the ISR?
If the answer is yes, I need to check a global variable to decide if the blink is needed. Wonder if that's OK too in the ISR
Thanks
Andy
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The M0 core at 24 MHz is quite fast enough to handle the if() and the LED write. To optimize use a local static uint8 for the LED state and
if(NeedToBlink) LEDPin_Write(LEDState = !LEDState);
Do not forget to switch off the LED when you set NeedToblink to false.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The M0 core at 24 MHz is quite fast enough to handle the if() and the LED write. To optimize use a local static uint8 for the LED state and
if(NeedToBlink) LEDPin_Write(LEDState = !LEDState);
Do not forget to switch off the LED when you set NeedToblink to false.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Bob, that worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome, Andy.
Bob