toggle clock on timer overflow
int period;
void setup()
{
TCCR2A = 0x00; // Wave Form Generation Mode 0: Normal Mode; OC2A disconnected
TCCR2B = (1<<CS22) + (1<<CS21) + (1<<CS20); // prescaler = 1024
TIMSK2 = (1<<TOIE2); // interrupt when TCNT2 is overflowed
DDRD |= (1<<PD7); // Portmanipulation: replaces pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop()
{
}
ISR(TIMER2_OVF_vect){
PORTD ^= (1<<PD7); // toggle PD7
period = TCNT2 *0.0000625*1024;
Serial.print("Period: ");
Serial.println(period);
}
reference:
No comments:
Post a Comment