Hello,
I have tried to implement a ten minutes Intervall with Timer Overflow Interrupt for Timer 2 (Arduino Uno), but the interrupt seems never to start. The LED at pin 13 is always low.
#include <avr/sleep.h>
#define ledPin 13
/* Timer2 reload value, globally available */
volatile unsigned int tcnt2;
volatile long n = 0L;
/* Setup phase: configure and enable timer2 overflow interrupt */
void setup() {
/* Configure the test pin as output */
pinMode(ledPin, OUTPUT);
/* First disable the timer overflow interrupt while we're configuring */
TIMSK2 = 0x00;
/* Configure timer2 in normal mode (pure increment counting, no PWM etc.) */
TCCR2A = 0x00;
/* Select clock source: internal I/O clock (SCHAUEN, OB ES LANGSAMEREN CLK GIBT --> ES GIBT NUR EXTERNEN COUNTER ZUSÄTZLICH) */
ASSR = 0x20;
/* Now configure the prescaler to CPU clock divided by 1024 */
// Prescaler auf 1024
TCCR2B = 0x07;
/* Save value globally for later reload in ISR */
tcnt2 = 0x01;
/* Finally load end enable the timer */
TCNT2 = tcnt2;
//Interrupt im Statusregister SREG freigeben
SREG = 0x80;
/* Disable Compare Match A interrupt enable (only want overflow) */
TIMSK2 = 0x01;
// Enable Interrupt in TIFR2-Register
TIFR2 = 0x01;
// activate power-save mode (auf Nomenklatur achten)
SMCR = 0x07;
// SLEEP instruction
sleep_enable();
sleep_mode();
}
/* void measurement () {
Serial.println("starte messung");
// during measurment IR has to be disabled
} */
ISR(TIMER2_OVF_vect) {
// clear sleep enable
sleep_disable();
if (n == 937500L){
// measurement();
for (int i = 0; i < 3000; i++) {
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
}
n = 0;
}
n = n + 1;
}
void loop() {
// SLEEP instruction
sleep_enable();
sleep_mode();
digitalWrite(ledPin,LOW);
}
At the moment I cannot find the error. Therefore I would be happy to get a hint to solve the problem. Moreover I'm interested to know, how to control the counter of timer 2, if I do not use a serial print.
Regards and thank you very much for your help
BeDa