Como fazer a interface do servo motor com o microcontrolador AVR (ATmega16) – (Parte 21/46)

How to interface the servo motor with the AVR microcontroller (ATmega16) – (Part 21/46)

Servo Motors find great applications in industries in the area of ​​automation, control and robotics. Servo motors are well known for their precise control and work on the principle of servomechanism. Servo motors can be run at precise angles using PWM. PWM (Pulse Width Modulation) is the basic working principle behind a servo motor (for more details on PWM see PWM Mode with Phase Correction ). This article explores the servo motor interface with ATmega16 . Also to know more about the servo mechanism, see Interfacing Servo Motor with 8051 .

There are different types of servos available in the market. This article limits its scope to interfacing a commonly available servo, widely used by hobbyists, with the ATmega16. Such a servo consists of three positive power wires, ground and a control signal. Unlike other motors, servo motors do not require any drivers. When a PWM signal is applied to its control pin, the shaft rotates at a specific angle depending on the duty cycle of the pulse.

Ciclo de trabalho do pulso

Fig. 2: Pulse duty cycle and axis angular displacement when applying the PWM wave
In the figure above, the pulse on time is 1 ms and the pulse off time is 18 ms, which rotates the axis by -90 degrees. Similarly, if the pulse on time is 1.5ms and the pulse off time is the same, the servo rotates to 0 0 and if the ON time pulse increases to 2ms, it rotates to +90 0. This gives a full 180 degree rotation. The motor maintains its position for each corresponding signal.
Note: Before starting the servo, first check the lowest ON pulse that turns the servo by -90 degrees and the highest ON pulse that turns the servo by +90 degrees while keeping the OFF pulse constant. When experimenting with VS2 servo motors, it was discovered that for -90 degrees the required ON pulse was 50us and the OFF pulse was 18ms. And for +90 degrees the ON pulse was 2050us and the OFF time remained equal to 18ms. Things may differ in type and quality.
A continuous pulse of 50 us at the ON time and 18 ms at the OFF time rotates the servo axis by -90 degrees.


 while(1)

{ Engine =(1< _delay_us(50); Motor = (0< _delay_ms(18); }
If the ON time is increased, the rotation angle also increases.
The code provided rotates the servo axis by 20 degrees every 5 seconds.

Project source code

###


 // Program to rotate the servo in 20 degree steps.
#include
#include #define PORTD engine #define servo PD6 empty degree (unsigned int ); int main(empty) { unsigned int grade_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; } empty degree (unsigned int k) { k=50+(k*10); engine= (1< _delay_us(k); engine = (0< _delay_ms(18); }

###

Circuit diagrams

Circuit diagram of how to interface the servomotor with the AVR-ATmega16 microcontroller

Project Components

  • ATmega16

Project video

Conteúdo Relacionado

A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
No mundo dinâmico da engenharia elétrica, a conexão estrela-triângulo...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.