fbpx

Interface Servo Motor With AVR

Description

Servo motor uses a servo mechanism. It is a closed-loop mechanism that uses position feedback to control the precise angular position of the shaft.

  • Some special types of applications of the electrical motor where rotation of the motor is required for just at a certain angle not continuously for a long period of time.
  • Motor is required with some special arrangement which makes the motor to rotate at a certain angle for a given electrical input (signal).
  • Servo motors have three wires.
  • Two of them are red and black which is used to give power to the motor.
  • The third wire is used to provide a control signal for the angular position.
  • It uses Pulse Width Modulated (PWM) waves as control signals.
  • The angle of rotation is determined by the width of the pulse at the control pin.

Hardware Required

  • Servo Motor.
  • Atmega16 MicroController.

Circuit

Virtual Circuit

Code

 #include <avr/io.h>
 #include <util/delay.h>
 void _nop_();
 void Delay_servo(unsigned int us);
 int main(void)
 {
 PORTC=0xff;
 while(1)
 {
 //Turn to 0 degree
 PORTC = 0x01;
 Delay_servo(50);
 PORTC = 0x00;
 _delay_ms(1000);
 //Turn to 90 degree
 PORTC=0x01;
 Delay_servo(82);
 PORTC=0x00;
 _delay_ms(1000);
 //Turn to 180 degree
 PORTC=0x01;
 Delay_servo(110);
 PORTC=0x00;
 _delay_ms(1000);
 }
 }
 void Delay_servo(unsigned int us)
 {
 while(us--)
 {
 _nop_();
 }
 }
 void _nop_()
 {
 
 } 

Leave a Reply

Your email address will not be published. Required fields are marked *