I want to control a servo using the mega8 and pwm.
The problem is the pwm frequency is the double it should be.
The mega 8 has a 16Mhz quartz.
The pwmfreq I calculated like in the datasheet:
Pwmfreq = 16000000 / (prescalcer* (top+1))
prescaler is 256
top is 10bit equals 1023
This should leed to 61 hz
What I get is 122hz
Here is the relevant part of the code:
void init_servo ( void )
TCCR1A = (1<<WGM11)|(1<<COM1A1) |(1<<COM1B1); //9BIT FAST PWM for 1A and 1B
TCCR1B = (1<<CS12) ; //prescaler CK/256
DDRB |= ( 1<<PB1 ); //Servo left
DDRB |= ( 1<<PB2 ); //Servo right
What have I done wrong?