-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to WDT library Adds the capability of using the HFRC oscillator for WDT. * Update keywords.txt Lgtwdt keyword added * Update wdt_interrupt_HF.ino Line contain "LGTWDT Lgtwdt;" deleted because it is integrated to file WDT.h * Update WDT.h Defining name Lgtwdt form class LGTWDT integrated to WHT.h Users do not need to write it into their own program. * Update keywords.txt --------- Co-authored-by: LaZsolt <[email protected]>
- Loading branch information
Showing
3 changed files
with
177 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lgt8f/libraries/WDT/examples/wdt_interrupt_HF/wdt_interrupt_HF.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************** | ||
* This example shows how the watchdog interrupt works. * | ||
* About every 512ms there will be a wdt interrupt. * | ||
* If you uncomment the line containing wdt_reset() the * | ||
* sketch will not detect wdt interrupt signal. * | ||
* * | ||
* Updated on August 2023 by gpb01 to user the HFRC * | ||
* clock on WDT. * | ||
******************************************************** | ||
* When writing an Interrupt Service Routine (ISR): * | ||
* Keep short,don't use delay(), don't do serial prints * | ||
* Make variables shared with the main code volatile * | ||
* Read this: https://gammon.com.au/interrupts * | ||
********************************************************/ | ||
#include <WDT.h> | ||
|
||
volatile boolean isrflag; | ||
|
||
void setup() { | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
Serial.begin(19200); | ||
Serial.println(F("Skech started.")); | ||
isrflag = false; | ||
|
||
Lgtwdt.begin(WTOH_32MHZ); // Select HFRC oscillator for WDT | ||
|
||
wdt_ienable(WTOH_512MS); | ||
} | ||
|
||
void loop() { | ||
int n = 0; | ||
do { | ||
Serial.print(F(" Elapsed step: ")); | ||
Serial.println(n); | ||
delay(128); | ||
if (digitalRead(LED_BUILTIN)) | ||
digitalWrite(LED_BUILTIN, LOW ); | ||
else | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
if (isrflag) { | ||
Serial.println(F("--There was a wdt interrupt.--")); | ||
isrflag = false; | ||
wdt_ienable(WTOH_512MS); | ||
} | ||
//wdt_reset(); | ||
} while( n++ < 1000 ); | ||
} | ||
|
||
ISR (WDT_vect) | ||
{ | ||
isrflag = true; | ||
wdt_reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters