How to interface Servo motor with Atmega32 microcontroller

Microcontroller Topics
Post Reply
User avatar
Shehani
Lieutenant
Lieutenant
Posts: 61
Joined: Mon Aug 19, 2013 2:11 pm

How to interface Servo motor with Atmega32 microcontroller

Post by Shehani » Thu Sep 26, 2013 11:21 am

Servo Motor is a DC Motor equipped with error sensing negative feedback to control the exact angular position of the shaft. Unlike DC Motors it will not rotate continuously. It is used to make angular rotations such as 0-90°, 0-180° etc. Stepper Motors can also be used for making precise angular rotations. But Servo Motors are preferred in angular motion applications like robotic arm, since controlling of servo motors are simple, needs no extra drivers like stepper motor and only angular motion is possible.
Servo Motor
Servo Motor
1.png (17.96 KiB) Viewed 2462 times
Operation of Hobby Servo Motor is very simple, it has only three wires, two of them (Red and Black) used to provide power and the third wire is used to provide control signals.All about Pulse width modulation (PWM) waves are used as control signals and the angular position is determined by the width of the pulse at the control input. In this tutorial we are using a servo motor having angle of rotation from 0-180° and angular position can be controlled by varying the pulse width between 1ms to 2ms.

Note : Please refer the datasheet of your Servo Motor, before using the program in this tutorial. Angular range and control pulse width are different for different servo motors.
Controlling Angular Position of Servo Motor using Pulse Width Modulation
Controlling Angular Position of Servo Motor using Pulse Width Modulation
2.jpg (17.42 KiB) Viewed 2462 times

Circuit Diagram
Interfacing Servo Motor with Atmega32 Microcontroller – Circuit Diagram
Interfacing Servo Motor with Atmega32 Microcontroller – Circuit Diagram
3.jpg (91.99 KiB) Viewed 2462 times
8 MHz Crystal is used to provide the required clock for Atmega32 Microcontroller and 22pF capacitors are used to stabilize the operation of the crystal. 10K? resistor and 10?F capacitor is used to provide the required Power On Reset (POR) to the microcontroller. Control of servo motor is connected to the first pin of PORTC (RC0), which is declared as an output pin in the program.

Atmel Studio C Program

Code: Select all

#ifndef F_CPU
#define F_CPU 8000000UL // 16 MHz clock speed
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRC = 0x01; //Makes RC0 output pin
  PORTC = 0x00;
  while(1)
  {
    //Rotate Motor to 0 degree
    PORTC = 0x01;
    _delay_us(1000);
    PORTC = 0x00;

    _delay_ms(2000);

    //Rotate Motor to 90 degree
    PORTC = 0x01;
    _delay_us(1500);
    PORTC = 0x00;

    _delay_ms(2000);

    //Rotate Motor to 180 degree
    PORTC = 0x01;
    _delay_us(2000);
    PORTC = 0x00;

    _delay_ms(2000);
  }
}

Article courtesy of electrosome.com
Post Reply

Return to “Microcontrollers”