Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
void run_servos_pwm(){ // Set PB1 and PB2 as outputs DDRB |= (1 << 1) | (1 << 2); // Ask for 50Hz (20ms) PWM signal (ms count should be halved) ICR1 = 20000/2 ; // Center both servos OCR1A = 1500/2 ; OCR1B = 1500/2 ; // Ask for non-inverted PWM on OC1A and OC1B TCCR1A = (1 << COM1A1) | (1 << COM1B1); // Configure timer 1 for Phase and Frequency Correct PWM mode, with no prescaling TCCR1B = (1 << WGM13) | (1 << CS10);}
#define SERVO_PWM_LEFT(_us) OCR1A=_us/2#define SERVO_PWM_RIGHT(_us) OCR1B=_us/2
OCR1A = integer_between_450_and_1050 ; //for the left servoOCR1B = integer_between_450_and_1050 ; //for the right servo
Incidentally: Phase and Frequency Correct mode is really aimed at DC motors and, although it will still work fine, you can also use Fast PWM mode for servos.