I have a timer setup as follows:
/******** Set timer1 for 8-bit fast PWM output ********/
pinMode(9, OUTPUT); // Make timer's PWM pin an output
TCCR1B = (1 << CS10); // Set prescaler to full 16MHz
TCCR1A |= (1 << COM1A1); // PWM pin to go low when TCNT1=OCR1A
TCCR1A |= (1 << WGM10); // Put timer into 8-bit fast PWM mode
TCCR1B |= (1 << WGM12);
/******** Set up timer 2 to call ISR ********/
TCCR2A = 0; // We need no options in control register A
TCCR2B = (1 << CS21); // Set prescaller to divide by 8
TIMSK2 = (1 << OCIE2A); // Set timer to call ISR when TCNT2 = OCRA2
OCR2A = 28; // sets the frequency of the generated wave 32 is C3
sei();
I'd like to change the value of OCR2A during runtime. Simply changing the value in a function doesn't do what I was expecting. Does the timer have to be reset first or interrupts disabled then re-enabled? Thanks for any help that can be offered.