Skip to content

Instantly share code, notes, and snippets.

@matthijskooijman
Created May 9, 2014 13:31
Show Gist options
  • Save matthijskooijman/6284a7e7842a82d42fc6 to your computer and use it in GitHub Desktop.
Save matthijskooijman/6284a7e7842a82d42fc6 to your computer and use it in GitHub Desktop.
void setup(){
Serial.begin(115200);
cli();
// Enable asynchronous mode for timer2 (uses external 32kHz
// crystal. This might corrupt the settings registers, so we'll
// have to (re-)set them all.
// TCCR2B.
ASSR |= (1 << AS2);
delay(10); // Just in case - didn't help :-(
// Outputs disconnected, normal mode
TCCR2A = 0;//(1 << WGM21) | (1 << WGM20);
OCR2B = 60;
OCR2A = 160;
// Start timer, prescaler 1024, meaning a single timer increment
// is 1/32s
TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20);
// Clear any pending interrupt
TIFR2 = (1 << TOV2) | (1 << OCF2A) | (1 << OCF2B);
// enable interrupts
TIMSK2 = (1 << TOIE2) | (1 << OCIE2A) | (1 << OCIE2B);
sei();
while(1);
}
ISR(TIMER2_COMPA_vect) {
Serial.print("A"); Serial.println(TCNT2);
// Do nothing, only used to trigger a wakeup
}
ISR(TIMER2_COMPB_vect) {
Serial.print("B"); Serial.println(TCNT2);
// Do nothing, only used to trigger a wakeup
}
static volatile bool overflow;
ISR(TIMER2_OVF_vect) {
Serial.print("O"); Serial.println(TCNT2);
// Do nothing, only used to trigger a wakeup
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment