PID Speed Control of DC Motor Using Microcontroller
PID Speed Control of DC Motor Using Microcontroller
microcontroller
http://www.help2educate.com/pid-speed-control-of-dc-motor-using-microcontroller/
Syed Noman ud din Microcontrollers 4 Comments 966 Views
In this article we will look at the implementation of PID speed control of DC motor using
microcontroller. The design procedure, the schematic, code and simulation of PID speed
control of DC motor using microcontroller will also be highlighted.
Contents [hide]
4 Simulation results
5 Code
In this figure, the process (plant) is the object to be controlled. The purpose of PID controller
is that the desired output (y) is obtained according to the predetermined set values of the input
(r). To achieve this goal, the error signal is calculated from closed loop feedback and input.
The controller generates the manipulated signal which is given as input to the plant (process).
As an example, consider a heating tank in which some liquid is heated to a desired
temperature by firing natural gas. The process variable y is the temperature of the liquid. The
input r is set point (temperature) and the difference between input (r) and feedback (y) is
error.
e=ry
The manipulated variable u is the flow of the fuel gas. The disturbance is any factor, other
than the manipulated variable, that influences the process variable. For simplicity we ignore
any disturbance in this case.
The compensator C(s) is the computational rule that determines the manipulated variable u
based on its input data, which is the error e in the case of figure shown above. It must be
noted that the process variable y is assumed to be measured by the detector with sufficient
accuracy such that feedback to the system can be regarded as equal to y. The output sensing
device is not shown in the figure.
Three variables through which the error is manipulated to generate control signal (u) are
proportional gain (kp), integral gain (Ki) and differential gain (Kd). The control signal (U)
to the plant is equal to the proportional gain (Kp) times the magnitude of the error plus the
integral gain (Ki ) times the integral of the error plus the derivative gain (Kd ) times the
derivative of the error.
The discrete PID controller is being implemented using PIC-18F452. The driver utilized for
controlling the motor id dual bridge IC 298. The purpose of using dual bridge IC 298 is that
motor cannot be controlled directly from microcontroller. Motor needs high current as well as
it produces back emf due to which it can damage the controller.
To generate feedback, motor encoder is used which generates PWM (pulses) of variable
frequency based on speed of dc motor. The output of the motor encoder is being fed to the
LM2907-8 which translates frequency to voltage. The capacitor is being utilized to remove
the dc component in the encoder output because LM2907-8 require the input in the range -2.5
to +2.5. The LM2907 converts the frequency of the encoder output to voltage which is being
fed to the Analog Channel 0 RA0 of the microcontroller. Analogue input voltage is given to
RA1 (analog channel) input which provides the set-point for the speed of the motor. The
potentiometer provide the value for the set-point. The two voltages are compared to find the
error voltage. Using the error voltage, the PID implanted in microcontroller determines the
control signal which is the PWM waves with certain duty cycle.
Simulation results
The circuit is simulated in Proteus the results are shown in the following figure. Initially the
potentiometer settings is at zero resistance applying full voltage to provide set point for the
speed of DC motor. The width of PWM waves will show the PID response.
PWM provided by the controller when the potentiometer is at the 100%:
Now the potentiometer setting is at 92% to provide new set point for the speed of DC motor.
The PWM output is shown. It can be seen that the width (duty cycle) is increased.
Code
The code is written in C language and complied in MIKRO C compiler
double drive=0;
double Duty=0;
double error=0;
double i_error=0;
double error_old=0;
double e_dot=0;
//integral error
//keeping the track of previous error
//derivative error
} }
If you have any questions please ask in the comments. If you like it please share it with your
friends.