From b489a846df99f96d6ef85ff523def16f5fceb979 Mon Sep 17 00:00:00 2001 From: Michael Zimmermann <148790477+Kruemelbahn@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:34:28 +0100 Subject: [PATCH] Create CheckTimer2.ino --- examples/CheckTimer2/CheckTimer2.ino | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/CheckTimer2/CheckTimer2.ino diff --git a/examples/CheckTimer2/CheckTimer2.ino b/examples/CheckTimer2/CheckTimer2.ino new file mode 100644 index 0000000..33ad584 --- /dev/null +++ b/examples/CheckTimer2/CheckTimer2.ino @@ -0,0 +1,35 @@ +volatile boolean state; +boolean state13; + +#define LEDPIN 6 + +// toggles every 2ms +ISR(TIMER2_COMPA_vect) +{ + state = !state; + digitalWrite(LEDPIN, state); +} + +void setup() +{ + pinMode(LEDPIN, OUTPUT); + pinMode(13, OUTPUT); + state = true; + state13 = true; + + cli(); + // set up Timer 2: + TCCR2A = 0; // normal operation + TCCR2B = bit(WGM22) | bit(CS20) | bit(CS22); // CTC, pre-scaling = 128 + OCR2A = 249 * clockCyclesPerMicrosecond() / 16; // compare A register value (8-Bit!) (250 * clock speed / 128) + TIMSK2 = bit(OCIE2A); // interrupt on Compare A Match + + sei(); // set interrupts flag +} + +void loop() +{ + // toggles prox. all 4.1µs + state13 = !state13; + digitalWrite(13, state13); +}