-
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.
Merge pull request #274 from dbuezas/Better_wdt_lib
Better wdt lib and lgt low power lib
- Loading branch information
Showing
22 changed files
with
3,116 additions
and
80 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
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
49 changes: 49 additions & 0 deletions
49
lgt8f/libraries/WDT/examples/wdt_interrupt/wdt_interrupt.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,49 @@ | ||
/******************************************************** | ||
* This example shows how the watchdog interrupt works. * | ||
* About every 4 seconds there will be a wdt interrupt. * | ||
* If you uncomment the line containing wdt_reset() the * | ||
* sketch will not detect wdt interrupt signal. * | ||
******************************************************** | ||
* 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; | ||
wdt_ienable(WTO_4S); | ||
} | ||
|
||
void loop() { | ||
int n = 0; | ||
do { | ||
Serial.print(F(" Elapsed time: ")); | ||
Serial.print(n); | ||
Serial.println(" s"); | ||
delay(999); | ||
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(WTO_4S); | ||
} | ||
//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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/**************************************************** | ||
* This example shows how the watchdog reset works. * | ||
* It restarts every 4 seconds. If you uncomment * | ||
* the line containing wdt_reset() the sketch will * | ||
* run continuously. * | ||
****************************************************/ | ||
#include <WDT.h> | ||
|
||
void setup() { | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
Serial.begin(19200); | ||
Serial.println(F("Skech started.")); | ||
wdt_enable(WTO_4S); | ||
} | ||
|
||
void loop() { | ||
int n = 0; | ||
do { | ||
Serial.print(F("Elapsed time: ")); | ||
Serial.print(n); | ||
Serial.println(" s"); | ||
delay(499); | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
delay(499); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
//wdt_reset(); | ||
} while( n++ < 1000 ); | ||
} |
This file was deleted.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
lgt8f/libraries/lgt_LowPower/examples/adcNoiseReduction/adcNoiseReduction.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,59 @@ | ||
/******************************************************************************* | ||
* This example shows how to use Noise Reduction mode. ( In short Noise * | ||
* Reduction mode stops the core and most of the pheripherials clocks and * | ||
* an ADC conversion starts automatically. ) * | ||
* The example periodically read A0 input. The sleep time is shorter than the * | ||
* specified because the ADC wakes it up at the end of the conversion. This * | ||
* library clears the WDT immediately after waking up. * | ||
* This example also show how to clear ADIF flag before entering sleep mode. * | ||
* * | ||
* - You should pay attention to that reading any analalog input with ADC * | ||
* ( analogRead() ) the intrerrupt flag of the ADC ( ADIF ) is set. * | ||
* This is causes the MCU wakes up immediately from any sleep mode. To avoid * | ||
* waking up immediately must clear the ADIF bit in ADCSRA before sleep. * | ||
*******************************************************************************/ | ||
|
||
#include "lgt_LowPower.h" | ||
|
||
int avalue; | ||
int measuredpin = A0; | ||
|
||
void setup() | ||
{ | ||
// No setup is required for LowPower library | ||
Serial.begin(9600); | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
pinMode(measuredpin,INPUT); | ||
analogReference(INTERNAL1V024); | ||
// analogReadResolution(12); | ||
avalue = analogRead(measuredpin); // Sets the ADMUX for the later use | ||
} | ||
|
||
void loop() | ||
{ | ||
|
||
// Clear ADC interrupt flag before sleep guarantees waiting until the | ||
// conversion is completed. | ||
ADCSRA |= (1 << ADIF); | ||
|
||
// Enter idle state for 8 s with the rest of peripherals turned off | ||
// LGT8Fx8P | ||
LowPower.adcNoiseReduction(SLEEP_8S, ADC_ON, TIMER2_OFF); | ||
|
||
// Do something here. Example: Read sensor, data logging, data transmission. | ||
digitalToggle(LED_BUILTIN); | ||
|
||
// Reading directly the ADC register the resolution will always 12 bits | ||
// regardless of what was set with the analogReadResolution(). | ||
|
||
avalue = ADC; // Reading the result made while sleeping. | ||
avalue -= (avalue >> 7); // Gain-error correction of LGT8F328P | ||
|
||
Serial.print(F("Measued value: ")); | ||
Serial.print(avalue/4); | ||
Serial.println(F(" mV")); | ||
|
||
// Waiting for the end of data transmission. The Noise Reduction sleep mode | ||
// stops serial port during next ADC conversion. | ||
Serial.flush(); | ||
} |
Oops, something went wrong.