I have SG90 servo motor purchased from ebay.com. I wrote below code, but I am able to get swing of 90 degree instead of 180 degree. I verified that servo is of 180 degree by running arduino code. I also verified PB1 pin that PWM is of 50 Hz and ON time changes between 1 and 2 msec correctly. What could be happening here? I am using ardiono nano board (Atmega328P)
#include <avr/io.h> #include <util/delay.h> void initialize_timer1(void); int main(void) { initialize_timer1(); OCR1A=93; // almost 1.5 ms _delay_ms(2000); while(1) { OCR1A=62; //1 ms _delay_ms(2000); OCR1A=124; //2 ms _delay_ms(2000); } } void initialize_timer1(void) { //TIMER1 INITIALIZATION DDRB|= 1<<PB1; //OC1A AS PWM OUTPUT TCCR1A &= ~((1<<WGM10)|(1<<COM1A0)); // FOR FAST PWM mode 14 TCCR1A|=(1<<COM1A1)|(1<<WGM11); // FOR FAST PWM mode 14 ICR1 = 1249; //TOP VALUE for 20msec (50Hz) TCCR1B |= (1<<CS12) | (1<<WGM13)|(1<<WGM12); //PRESCALER 256, MODE 14 }