I'm fooling around with my new Teensy2.0++ and trying to learn how to play with interrupts. I want to make the LED toggle at 1Hz (one second on, one second off). I've tried following Dean's tutorial and the datasheet, but I'm having some trouble, the LED is toggling, but at much longer than 1Hz, which makes me think I'm missing something. Here's my code:
#include#include #include ISR(TIMER1_COMPA_vect) { PORTD ^= (1 << 6); } void init (void) { /**** Clock Settings ****/ // Enable Clock Change CLKPR = (1 << CLKPCE); // Set Clock Prescaler to 0x00 (16 Mhz) CLKPR = 0x00; /**** Peripheral Initialization ****/ /* Timer 1 - 1 Second Interrupt Generator */ // Set CTC Mode & prescaler to 256 TCCR1B |= (1 << WGM12 | 1 << CS12 | 0 << CS11 | 0 << CS10); // Set Output Compare Channel A for 1 Hz @ 16 MHz / 256 OCR1A = 62499; TIMSK1 |= (1 << OCIE1A); PRR0 = 0x00; /**** GPIO Initialization ****/ // LED DDRD |= (1<<6); /**** Enable Interrupts ****/ sei(); } int main(void) { init(); while(1) { } }
I'd like to be running at 16Mhz, so I think I've done my math right, but I'm not certain. Changing the value in OCR1A doesn't seem to do anything to the toggle speed, which makes me think I'm totally missing something here, but I'm not sure. Any thoughts?