Thứ Sáu, 14 tháng 12, 2018

How to interface Servo Motor with AVR Microcontroller (ATmega16)

Developed By: 

Akshay Daga
Servo motors find huge applications in industries in the field of automation, control & robotics. The servo motors are well known for their precise control and work on the principle of servo mechanism. The servo motors can be made to run at precise angle using PWM. The PWM (pulse width modulation) is the basic working principle behind a servo motor (For more details about PWM refer Phase correct PWM mode). This article explores the interfacing of servo motor with ATmega16. Also to know more about servo mechanism see Interfacing Servo Motor with 8051.

Interfaceing Servo Motor With AVR Microcontroller Prototype



There are different types of servos available in the market. This article bounds its scope to interfacing a commonly available servo, widely used by hobbyist with ATmega16. Such a servo consists of three wires positive supply, ground and a control signal. Unlike other motors, Servo motorsdon’t require any driver. When a PWM signal is applied to its control pin the, the shaft rotates to a specific angle depending on the duty cycle of the pulse.
Duty Cycle of Pulse
Fig. 2: Duty Cycle of Pulse and Angular Displacement of shaft on applying PWM wave
In the above figure the ON time for pulse is 1ms and off time pulse is 18ms this rotates the shaft to -90 degree. Similarly if the on time of pulse is 1.5ms and the off time of pulse same the servo rotates to 00 and if ON time pulse increases to 2ms it rotates to +900. This gives a complete 180 degree rotation. The motor maintains its position for every corresponding signal.
Note: Before starting with servo first check the lowest ON pulse which rotates servo to -90 degree and the highest ON pulse which rotates the servo to +90 degree while keeping the OFF pulse constant. While experimenting with VS2 servo motors it was found that for -90degree the ON pulse required was 50us and OFF pulse was 18ms. And for +90 degree the ON pulse was 2050us and keep the OFF time same as 18ms. Things may differ on the type and quality.
A continuous pulse of 50 us ON time and 18ms OFF time rotates the axis of servo to -90 degree.

while(1)
{
Motor =(1<<servo);
_delay_us(50);
Motor = (0<<servo);
_delay_ms(18);
}
If the ON time is increased the rotation angle also increases.
The given code rotates the servo axis by 20 degree after every 5 sec.




Circuit:
Circuit Diagram of How to interface Servo Motor with AVR Microcontroller (ATmega16)

Code:
// Program to rotate servo at the step of 20 degree.
#include<avr/io.h>
#include<util/delay.h>
 
#define motor PORTD
#define servo PD6
 
void degree(unsigned int );
 
int main(void)
{
unsigned int degree_value,time;
DDRD=0b01000000;
for(degree_value=0;degree_value<180;degree_value +=20)
for(time=0;time<50;time++)
{
degree(degree_value);
}
return 0;
}
 
void degree(unsigned int k)
{
k=50+(k*10);
motor= (1<< servo);
_delay_us(k);
motor = (0<<servo);
_delay_ms(18);
}
 

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01 # candientu ,  # fujihatsu ,  # candientufujihatsu  #candientu,  # candientufujhatsu , #fuji...

Bài đăng phổ biến