A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://microcontrollerslab.com/servo-motor-interfacing-pic16f877a-microcontroller/ below:

Interfacing a Servo Motor with PIC16F877A Microcontroller

In this tutorial, you will learn to interface oa servo motor with the PIC16F877A microcontroller. This tutorial covers the programming required to control the servo motor, as well as the hardware connections between the servo motor and the PIC16F877A microcontroller. Let’s start with a basic introduction to the servo motor. Then, I will move forward with its circuit diagram and programming.

What is a Servo Motor?

A servo motor is a unique type of motor that executes actions according to specific instructions. What sets it apart is its exceptional angular precision. Unlike typical electric motors that continuously rotate until power is applied or removed, a servo motor rotates precisely to a designated degree or until directed otherwise. After reaching the designated position, the motor ceases its movement and remains idle until a new instruction is provided for subsequent actions.

Servo motors are governed by a servomechanism, a system that manages their operation. The motor’s angular rotation and final position are guided by feedback mechanisms. The control line’s input determines the desired position for the output shaft. This intricate interplay between input, feedback, and control ensures that servo motors respond with remarkable accuracy to specific positional requirements.

servo motor? SG-90 Servo Motor Introduction 

SG90 is a low-cost and high-output power servo motor. It can rotate up to 180 degrees and each step can be of maximum 90 degrees. Moreover, it is small enough that it can easily fit into your robotics ARM or obstacle avoidance robotics projects. On top of that, it requires only one output pulse signal to control its movement. 

Pinout 

The following figure shows the pinout diagram of the SG90 servo motor. It consists of three pins only such as PWM, ground, and Vcc pin. Brown, orange and red wires are GND, Vcc, and PWM pins respectively. Details and functionality of each pin are listed in the next section. 

Pin Configuration Details

VCC and ground, as their names suggest, are the power supply pins used to power the servo motor. Only a 5-volt power signal is required to power this motor. Most microcontrollers or development boards have an onboard 5-volt supply that we can use to power SG90 servos.

PWM Pin is an input pin of a servo motor. We provide a PWM output signal from the pic microcontroller to drive the servo motor through this pin. 

This table briefly described all three pins: 

Wire of motor Possible colors of each wire Vcc pin Red GND pin Black, or brown Control Signal / PWM pin  Yellow, orange, or white How to control Servo motor rotator movement? 

The position of the servo rotator is directly related to the width of the pulse applied to the PWM signal of the motor.

To control rotation, we apply pulses to the PWM pin of the servo motor. The frequency of the PWM signal should be 50Hz, which means the control signal pulse should be applied to the PWM pin every 20ms. The width of the pulse has a direct relation with the angular position of the motor.

For SG90-type servo motors, a pulse width of 1 ms corresponds to a 0-degree rotation, 1.5 ms corresponds to a 90-degree rotation, and 2 ms corresponds to a 180-degree rotation.

Hence, the pulse width between 1ms to 2ms controls the shaft position of the servo motor between 0 to 180 degrees.

Note: This pulse duration may be different for different types of servo motors. 

Circuit Diagram for Servo Motor Interfacing with PIC16F877A Microcontroller

The circuit diagram provided illustrates the interfacing of a servo motor with a PIC16F877A microcontroller. Let’s break down the components and connections shown in the diagram:

Overall, the circuit diagram illustrates a straightforward interaction between the PIC16F877A microcontroller and the servo motor. By connecting the control wire of the servo motor to the RB0 pin of the microcontroller, precise angular displacement can be achieved by adjusting the length of the applied pulse, thus enabling accurate motor control.

circuit diagram of servo motor interfacing with pic microcontroller

The circuit diagram for this setup is straightforward. The control wire of the servo motor is directly linked to the RB0 pin of the microcontroller. This specific pin is responsible for delivering the necessary angular displacement to the motor. In this project, our focus is on a servo motor designed for an angular range of 0° to 180°. Within this defined scope, we achieve precise control over the motor’s rotation by manipulating the width of the pulses, ensuring that the desired angle is attained with accuracy.

Pic Microcontroller MikroC Code

The following code is written using MikroC for PIC compiler. But if you don’t know how to use MikroC for PIC compiler, you can check the following tutorials:

The provided code is for controlling a servo motor’s rotation at three different angles (0°, 90°, and 180°) using a PIC16F877A microcontroller.

void Rotation0() //0 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(800); // pulse of 800us
PORTB.F0 = 0;
Delay_us(19200);
}
}

void Rotation90() //90 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(1500); // pulse of 1500us
PORTB.F0 = 0;
Delay_us(18500);
}
}

void Rotation180() //180 Degree

{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(2200); // pulse of 2200us
PORTB.F0 = 0;
Delay_us(17800);
}
}

void main()
{
TRISB = 0; // PORTB as Ouput Port
do
{
Rotation0(); //0 Degree
Delay_ms(2000);
Rotation90(); //90 Degree
Delay_ms(2000);
Rotation180(); //180 Degree
}while(1);
}

Individual functions for angular rotation of the motor by 0°, 90°, and 180° have been defined at the beginning of the code. However, there are a few clarifications and corrections to be made in the explanation:

In this tutorial, we are not using the actual Pulse Width Modulation (PWM) feature of the PIC16F877A microcontroller to generate pulses. Instead, the pulses are simulated using delays within the program. Each delay duration for a specific angle corresponds to the pulse length required for the motor to rotate to the respective angle.

In summary, the program mimics the effect of Pulse Width Modulation by utilizing timed delays. The duration of each delay corresponds to the required pulse length for the servo motor to rotate to the specified angle. This approach, while not employing true hardware PWM, achieves the desired rotation angles effectively.

Furthermore, it’s important to point out that while this method works, it may not offer the precision and accuracy of hardware PWM in more demanding applications. Also, the exact pulse durations might need adjustments based on the servo motor’s specifications and characteristics.

Applications

Servo motor has a large number of application in industries. In industrial manufacturing, the conveyor belt uses servo motors to control the precise movement of the belt. Servo motors are most popular in robotics. The precise angular displacement of a robot’s arm is controlled by a servo motor. The physical movement of the solar panel with respect to the sun is also carried out by servo motors in a solar tracking system.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4