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.
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)
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.
###
Circuit diagrams
Circuit diagram of how to interface the servomotor with the AVR-ATmega16 microcontroller |
Project Components
- ATmega16