I'm trying to set up timer 1 to run an isr in CTC mode. no matter what i set OCR1A to it always executes at the same frequency and if i print out TCNT1 I get values higher than OCR1A.
here is my Code
void timer1_init()
{
// set up timer with prescaler = 8 and CTC mode
TCCR1B |= (1 << WGM12)|(0 << CS12)|(1 << CS11)|(0 << CS10);
// initialize counter
TCNT1 = 0;
// initialize compare value
OCR1A = 100;
// enable compare interrupt
TIMSK1 |= (1 << OCIE1A);
// enable global interrupts
sei();
}
ISR(TIMER1_COMPA_vect){
SET(MOTOR_PORT,LEFT_MOTOR_STEP); //set the pin high
delayMicroseconds(3); //keep high for a bit
CLR(MOTOR_PORT,LEFT_MOTOR_STEP); //set it low
}
I'm using this to drive a stepper motor so using PWM mode wont work.