-
-
Save nullstalgia/059b98656a85c8821e988ccac51a62cf to your computer and use it in GitHub Desktop.
Determine AVR Speed in software https://forum.arduino.cc/index.php?topic=345862.msg2384213#msg2384213
This file contains hidden or 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
#include <avr/sleep.h> | |
#include <avr/wdt.h> | |
volatile bool wdtFired; | |
// watchdog interrupt | |
ISR (WDT_vect) | |
{ | |
wdt_disable(); // disable watchdog | |
wdtFired = true; | |
} // end of WDT_vect | |
void setup () | |
{ | |
noInterrupts (); // timed sequence follows | |
MCUSR = 0; | |
// allow changes, disable reset | |
WDTCSR = bit (WDCE) | bit (WDE); | |
// set interrupt mode and an interval | |
WDTCSR = bit (WDIE); // set WDIE, and 16 ms seconds delay | |
wdt_reset(); // pat the dog | |
wdtFired = false; | |
interrupts (); | |
unsigned long startTime = micros (); | |
while (!wdtFired) | |
{ } // wait for watchdog | |
unsigned long endTime = micros (); | |
Serial.begin (115200); | |
Serial.println (); | |
Serial.print (F("Time taken = ")); | |
Serial.println (endTime - startTime); | |
} | |
void loop () { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment