Вы находитесь на странице: 1из 12

Logo

Home
Projects
Forum
Cytron Technologies Official Website
Navigation
open all | close all

Getting Started
rero
Buying Guides
Product Guides
Projects
Seminars & Events
News
Useful Tools / External References

Live Search
Sign In
User
Password
Remember me

Become a Member
Recover Password
Recent Comments
show plates direct on New Training Kit Coming!
ravi on Arduino Controlling MDS40A
pam on Fingerprint Reader Integrated SM630 with SM630 PC Demo GUI
Aniket on Wireless UART with Arduino and 433MHz or 434MHz module
ober on Arduino Wireless Programming (Bluetooth)
Home Getting Started Programming/Software PID for Embedded Design
Tags: Embedded, PIC Microcontroller, PID Control
PID for Embedded Design
31
Share
1
Share
Share
Share
By Kong Wai Weng
RH2T Mag, Vol.4, Mar 2010
PID control system is one of the most mature and commonly used control strategie
s in the industrial for decades thanks to its simple but effective algorithm. In
this article, we will discuss the basic concept of PID controller and how to im
plement it in the embedded system.
Introduction
Closed loop control system is an essential topic for embedded systems, bringing
together actuators and sensors with the control algorithm in software. For examp
le, motor speed can be controlled by varying the PWM duty cycle used to drive th
e motor. This is the open-loop control. However, due to the lack of feedback, th
e actual motor speed could not be verified. This is important because driving th
e motor with the same PWM duty cycle does not guarantee the motor to run at the
same speed under all circumstances. A motor will run faster in load free conditi
on than under load with the same PWM signal. In order to control the motor speed
, we need to close the loop by adding feedback of the actual motor speed to the
controller.
Besides speed control, PID control system can also be used to control other para
meters such as position, temperature, water level, stability, etc. In this artic
le, we will discuss how to implement a PID controller for position control based
on PR24.

The Problem DC Motor Position Control.
Before we begin to design a PID controller, we need to understand the problem. I
n this example, we want to move the shaft of the motor from its current position
to the target position.
motor
We want to move the output shaft of the motor from current position to target po
sition
There are a few terms commonly used to describe the PID control loops, such as:
Control Variable (CV) This is the output of the control loop. In this case, the
CV is the duty cycle of the PWM signal that drives the motor.
Process Variable (PV) This is the feedback value returned by the system to the c
ontroller. In this example, the PV is the current angle of the motor shaft.
Set Point (SP) Set point is the value that we desire for the system. In our case
, the SP is the target position of the motor shaft in angle.
Error (E) Error refers to the difference between the set point and the process v
ariable. In another words, it means how far the current position of the motor sh
aft from the target position.

The Hardware PR24
The Cytrons DIY Project Set PR24 (PID Motor Controller) is the best platform for
beginner to learn the PID algorithm. It has the following features:
PIC16F876A as the main controller.
Geared DC motor as the output.
Multi-turn variable resistor connected to the motor shaft for position feedback.
216 Character LCD for tuning and troubleshooting.
Presets for PID tuning.
Picture 049
DIY Project Set PR24 PID Motor Controller
The sample source code for the PR24 (PID Motor Controller) can be downloaded fro
m Cytrons website under the PR24 product page.

The Implementation of PID Controller
The PID controller, just like its name, comprises a proportional (P), an integra
l (I) and a derivative (D) part. The controller parts are introduced in the foll
owing sections individually and in combined operation.
Proportional Controller
When the current position of the motor shaft is still far away from the target p
osition, we want to apply more power to drive the motor towards the target posit
ion so that we can reach there faster. When the shaft is getting nearer to the t
arget position, we will reduce the power to slow it down. At the time the shaft
reaches the target position, the motor needs to be stopped. If the shaft positio
n has overshot, we need to apply negative power to the motor (reverse the motor)
to bring it back to the target position.
In short, this is called proportional controller because the power we apply to t
he motor is proportional to the error of the system.
pid
The block diagram of proportional controller
From the block diagram of proportional controller, we can see that the PWM duty
cycle (output) is the result of multiplying the error with a constant, Kp.
Error = Set Point Process Variable
Control Variable = Kp * Error
Figure below shows the example of proportional loop implemented in C language.
clip_image007
Implementation of proportional loop in C language
The value of Kp needs to be chosen carefully in order to get the optimum system
response. Lower values for Kp will tend to give smoother but slower responses.
clip_image009
System response for proportional controller with low Kp
Higher values of Kp will yield much quicker response but may cause overshoot, wh
ere the output oscillates before settling.
clip_image011
System response for proportional controller with high Kp
Excessively high values of Kp may even throw the loop into an unstable state whe
re the output oscillates without ever settling at the set point.
clip_image013
System response for proportional controller with excessively high Kp

Integral Controller
As can be seen from the graph of P controller, the actual position of the motor
shaft, when settles down will not reach the target position. This is because whe
n the current position is near to the target position, the error becomes very sm
all and the computed PWM duty cycle is too small for the motor to overcome the f
riction and gravity. The small error that exists when the system has settled dow
n is called the steady state error.
Steady State Error
Steady state error due to the friction and gravity
To overcome the problem of steady state error for the P controller, I controller
is being introduced. As its name suggests, the integral is merely an accumulate
d error signals encountered since startup.
Integral = ?(Error)
This total is multiplied by a constant, Ki, and is added into the loop output. U
nlike the P controller, the I controller is rarely used alone, but mostly in com
bination with the P or PD controller. When the system has already settled down w
ith a small steady state error, the integral still continues to accumulate until
the CV is large enough to bring the PV inline with SP. The equations for PI con
troller are as follow:
Error = Set Point Process Variable
Integral = Integral + Error
Control Variable = (Kp * Error) + (Ki * Integral)
Figure below shows the example of PI controller implemented in C language.
clip_image017
Implementation of PI loop in C language
Just like the P controller, the value of Ki needs to be chosen carefully. Too lo
w the value, the steady state error is corrected very slowly; too high the value
, the system becomes unstable and oscillates.
clip_image019
System response for PI controller with no steady state error
Because the integral can grow quite large when the set point cannot be reached,
some applications stop accumulating the error when the CV is saturated.

Derivative Controller
Lets say you are driving a car, and you need to stop your car exactly 100m from y
our current position as soon as possible. If you are travelling at 10km/h, you w
ould want to accelerate your car so that you can reach the target sooner. In con
trast, if you are cruising at 100km/h, you need to start braking so that you can
stop at 100m and will not overshoot. This is where the derivative controller co
mes into play.
The derivative of any variable describes how that variable changes over time. In
a PID controller, the derivative is the rate of change of the error. In digital
form, it can be described as:
Derivative = Error Last Error
where Error is the current error value and Last Error is the error value for the
previous iteration.
Negative values of derivative indicate an improvement (reduction) in the error s
ignal. For example, if the last error was 20 and the current error is 10, the de
rivative will be -10. When these negative values are multiplied with a constant,
Kd, and are added to the output of the loop, it can slow down the system when a
pproaching the target.
Just like the I controller, the D controller is rarely used alone, but mostly in
combination with the P or PI controller. The equations for the PD controller ar
e as follow:
Last Error = Error
Error = Set Point Process Variable
Derivative = Error Last Error
Control Variable = (Kp * Error) + (Kd * Derivative)
Figure below shows the example of PD controller implemented in C language.
clip_image021
Implementation of PD loop in C language
The damping effect of the D controller allows the system to have a higher value
of Kp and/or Ki without overshooting. In consequent, this will give the system a
better response time to set point changes. However, too high the value of Kd wi
ll also have negative effect. The D controller tense to amplify the noise exists
in the feedback loop. If the Kd is too high, the system will become jerky if th
e feedback loop is noisy.
clip_image023
System response for PD controller

Joining Them Together PID Controller
By joining the P, I and D controller, we can take the advantages of the combined
benefits from each controller. We have the P controller for fast system respons
e, I controller to correct the steady state error and D controller to dampen the
system and reduce overshoot.
clip_image025
The block diagram of PID controller
From the block diagram of PID controller, we can see that the output of the loop
is merely the sum of output from P, I and D controller. The equations for the P
ID loop are illustrated below:
Last Error = Error
Error = Set Point Process Variable
Integral = Integral + Error
Derivative = Error Last Error
Control Variable = (Kp * Error) + (Ki * Integral) + (Kd * Derivative)
Figure below shows the example of PID controller implemented in C language.
clip_image027
Implementation of PID loop in C language
clip_image029
System response for the correctly tuned PID controller

Summary
PID controller is a simple yet effective control system widely used in industria
l. However, to implement the PID controller is simple, but not the tuning. The p
rocess of tuning the PID parameters (Kp, Ki and Kd) is a continuous trial and er
ror process. There is no exact way to calculate the value for the parameters unl
ess the whole system is mathematically modeled and simulated. Experience is an i
mportant factor to get the optimum PID parameters based on the observation of th
e system behavior during the tuning process. If you have inquiry, feel free to d
iscuss in our technical forum.
References:
Dennis Clark and Michael Owings: Building Robot Drive Trains.
Thomas Braunl: Embedded Robotics Mobile Robot Design and Applications with Embed
ded Systems.
http://en.wikipedia.org/wiki/PID_controller
http://www.expertune.com/tutor.html
http://www.newportus.com/products/techncal/techncal.htm
http://www.dprg.org/tutorials/2003-10a/motorcontrol.pdf
31


1

1



You may also like:

SIEMENS TC35 GSM Development Board, GSM-TC35

G15 Cube Servo on Mobile Robot

CIKU + LCD Keypad Shield

Controlling MD10C with Arduino

CIKU + Mifare Reader/Writer CR038

Low cost DC supply solution, 3.7V 1100mAh Li-Ion Battery (LI-3.7-1100
Related Posts:
How RC Servo Works?How RC Servo Works?
How does Stepper Motor Works Part 1How does Stepper Motor Works Part 1
Configure the Operation Mode (Closed Loop or Open Loop) of BLD04AConfigure the O
peration Mode (Closed Loop or Open Loop) of
How Does Stepper Motor Works Part 2How Does Stepper Motor Works Part 2
Published by: ober on June 22, 2012.

2 Responses to PID for Embedded Design
vamsi krishna says:
July 25, 2013 at 1:27 am
nice tutorial . is there any tutorial for implementing the fuzzy logic in microc
ontroller for motor control

tinku jangid says:
August 24, 2014 at 5:33 pm
can u tell me how much we will generate in relate to get a fixed or set point fr
equency

Leave a Reply

Name (required)
Mail (will not be published) (required)
Website


.
Help us improve the wiki Send Your Comments
2012 Tutorial by Cytron | Powered By Wordpress

Вам также может понравиться