The R/C Servo Motors are used in model aircraft, R/C Trucks, R/C motorboats and robots.
Radio Control Servo motors are position servo systems that are controlled digitally (through PWM). The usual range is about 180 degrees.
The connections to the motor are
1. GND (Black)
2. VCC (Red)
3. Control (White)
A typical Servo looks like below
The PWM signal to control the position should have a pulse duration between 10-30 msec. and the on time determines the position of servo. A 1.5 msec on-time makes the Servo position at the middle (the pulse is given below)
In order to Interface the R/C Servo to the AVR Project board, three wires are used to connect the Servo to the Board. Two of the wire can be connected to the any VCC and GND signal. The control wire is connected to the PORTD PIN5 (OC1A/PD5). The Timer1 of the ATMEGA16 can produce a PWM output on this pin. Two Switches are also connected to the PC0 and PC1 to make it rotate Clockwise and Counter Clockwise.
Code for the project is as below, Also the complete project in zip form
#include "avr/io.h"
#define BitVal(x) (1 << (x))
void main (void)
{
DDRD = BitVal(5); //Program PORTD5 pin as output
PORTC = 0x03; //Enable pullups for Switch detection
TCCR0 = BitVal(CS01); //Start Timer 0
ICR1 = 0xFFFF; //Set Max limit for the Timer, ~16ms period on 4MHz
TCCR1A = BitVal(WGM11) | BitVal(COM1A1); //Fast PWM, Wave Form output
TCCR1B = BitVal(CS10) | BitVal(WGM13) | BitVal(WGM12);
OCR1A = 6000; //1.5mS
while(1){
if(TCNT0 > 200){ // Process the key press with a delay
TCNT0 = 0;
if(((PINC & BitVal(0)) == 0) && (OCR1A > 1100))
OCR1A --; //turn clockwise
if(((PINC & BitVal(1)) == 0) && (OCR1A < 10000))
OCR1A ++; // turn counter clockwise
}
}
}