@15 - 8051 Advanced - IV - Data Converters Sensors and Controllers
@15 - 8051 Advanced - IV - Data Converters Sensors and Controllers
28
24
20
16
Discrete digital signal
12
0
0 1 2 3 4 5 6 7 8 9 10
Time (s)
A/D and D/A Conversion
1023
32 Digital Analog
Input DAC Output
28 896
24 768
zoomed in
20 640
16 512
Discrete digital signal
12 384
0 0
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3
Time (s) Analog signal (volts)
Nyquist Theorem
• A bandlimited analog signal that has been sampled can be perfectly
reconstructed from an infinite sequence of samples if the sampling rate
fsample exceeds 2fmax samples per second, where fmax is the highest frequency
in the original signal.
– If the analog signal does contain frequency components larger than
(1/2)fsample, then there will be an aliasing error.
– Aliasing is when the digital signal appears to have a different frequency
than the original analog signal.
Voltage (V)
1 1.5
Voltage (V)
0 1.0
0 2 4 6 8 10
-1 0.5
-2 0.0
Voltage (V)
1 1.5
Voltage (V)
0 1.0
0 2 4 6 8 10
-1 0.5
-2 0.0
Voltage (V)
1 1.5
Voltage (V)
0 1.0
0 2 4 6 8 10
-1 0.5
-2 0.0
-3 0.0 0.2 0.4 0.6 0.8 1.0
Time (ms)
Frequency (kHz)
Analog-to-Digital Converter Precision
• Quantitative DAS performance
– range (rx)
– resolution (Δx)
– precision (nx in alternatives)
– frequencies of interest (fmin to fmax)
– repeatability (σ of repeated measurements, same conditions)
– reproducibility (σ of repeated measurements, different conditions)
• When:
range of values is known value integer •
range of values is small
• How:
1) variable integer, called I.
may be signed or unsigned
may be 8, 16 or 32 bits (precision)
2) fixed constant, called (resolution)
value is fixed, and can not be changed
not stored in memory
specify this fixed content using comments
Fixed-Point Numbers
• The value of the fixed-point number:
Fixed-point number I•
Smallest value = Imin • D, where Imin is the smallest integer
Largest value = Imax • D, where Imax is the largest integer
=0.01 V
Vin = 3•N/1024 how ADC works
Vin = I • 0.01 definition of fixed point
I = (3•100*N)/1024 substitution
I = (75•N)/256 simplify
I = (75•N+128)/256 round to closest integer
I = (m•N+512)/1024+b calibrate to get m and b
Lab 8 Calibration
Position Analog input ADC sample Correct Fixed-point Measured Fixed-point Output
0.00 cm 0.000 2 0 11
0.40 cm 0.653 224 400 380
0.80 cm 1.408 479 800 803
1.20 cm 2.119 721 1200 1205
1.60 cm 2.815 958 1600 1599
n
1
n
x
i 0
ti xmi
Digital ↔ Analog Conversion
fs = 1/Dt
Signal has frequencies 0 to ½ fs
DAC Performance
• Resolution, range, precision
• Maximum sampling frequency
• Monotonicity
– Input increase causes output increase (always)
nonlinear nonmonotonic
Vout Vout
Ideal Ideal
• Resolution 768
zoomed in
– 3.3V/15 = 0.22V 640
• Precision 512
– 4 bits 384
– 16 alternative 256
Analog Digital
ADC
• Speed 128 Input Outputs
• Monotonic 0
0 1 2 3
Analog signal (volts)
ADC0804 (National Semicond.)
ADC0808/0809: Multi-(Analog)-Channel
• 8 analog input lines
– Selected by 3-bit, internally share 1 ADC
– Conceptually, analog multiplexor on input
– ALE latches the address
• 8-bit output port
– Similar to the single-channel ADC
Pin interface and timing diagram
Schematic for ADC0809
Digital vs Analog Ground
Code example
PID Motor Control Using ADC0809
Sensing Robot Arm Position Using Resistive Potentiometer
Electret Microphone Interface
• Current Electret Condenser Microphones (Record sound)
Digital Thermometer with MCU
• LM35 has an operating range of -55 to 150OC, giving 10.0 mV/OC. The
amplifier gain of the signal conditioning circuit is calculated by dividing the
span of output voltage of the amplifier (i.e., 5V) by the span of the sensor
output (i.e. 127.5x10mV = 1.275 mV for the temperature measurement
range 0-127.5OC) => the amplifier gain is 5/1.275 = 3.921.
Digital Thermometer with MCU
• Any MCU with ADC can be used to interface to the output of the
conditioning circuit. For example, a built-in 8 bit ACD with 0-5 range is used.
• As the sensor itself is calibrated to give 10.0mV/ OC, it will be easier if we
adjust the amplifier gain and ADC resolution. Let us calibrate the signal
conditioning for 0-127.5OC and setup the ADC to obtain the resolution of
0.5OC. We can put the binary point to the right of the seven MSBs. The ADC
output range will be 0000 000.0 to 1111 111.1. Note that if we truncate this
fraction, then we get only 1OC resolution giving a range of 0-127OC. If we use
this binary number as it is, the resolution will be 0.5 OC, the temperature
range will be 00.0-127.5OC (see tables 13.5 for details).
RTD/Thermocouple: XTR103
RTD/Thermocouple: XTR101
Analog Proximity Sensors
• Maxbotix LV-EZ0 Ultrasonic Range Finder
The waveform on the left uses a 4-bit DAC, while on one on the right uses a 12-bit DAC.
Experimental data of a 32-output 523 Hz sine-wave. Experimental data of a 256-output 523 Hz sine-wave.
97
Synthesizing Digital Music
• Recall Nyquist’s Sampling Theorem
– We can reproduce any bandlimited signal from its
samples if we sample correctly and at a frequency, fsam,
that is at least twice the highest frequency component of
the signal, fmax.
• Where do we get the samples?
– We could sample a series of musical tones
– We can compute the samples
Synthesizing Digital Music
• What is a musical tone?
– A sinusoid of a particular frequency
– Notes vary by twelfth root of 2 ~ 1.059
• What would the samples be?
– Fixed point numbers
• How do we generate a sinusoid?
– Output appropriate digital values via a resistor network that
effectively produces an pseudo-analog signal
• What about frequency?
– Employ a programmable timer to tell us when to output the
next value
Synthesizing Digital Music
• 440 Hz sine wave generated by 6-bit DAC
Frequency
spectrum
Music Generation (cont.)
• Objectives
– Employ LM3S to generate appropriately scaled digital
outputs at a specified frequency
• Three frequencies are required
• Frequencies are to be determined by switch settings
– Four digital outputs are are inputs to a resistor network
that serves as a digital-to-analog converter (DAC)
• Four output bits => 16 levels
Music Generation (cont.)
DAC hardware
Employ least significant four bits of a GPIO port
Arrange resistor network in 1, 2, 4, 8 sequence
Each port bit can assume digital levels of 0 and 5 V
Ports are current limited – max 8 mA
R3
R2
R1
R0
Music Generation (cont.)
• DAC software
– Interactions via device drivers
– Two device drivers required:
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7
theta (radians)
SinTab 8,9,11,12,13,14,14,15,15,15,14
14,13,12,11,9,8,7,5,4,3,2 32 value sinusoid
2,1,1,1,2,2,3,4,5,7
Sinusoid Waveform
Discrete Half-Period
2.5000
2.0000
1 + sin(x * Pi / 16)
1.5000
Series1
1.0000
0.5000
0.0000
11
13
15
17
1
9
Discrete Half-Period
obtained from previous half-period data
1.2000
1.0000
2 - sin(x * Pi / 16)
0.8000
0.6000 Series1
0.4000
0.2000
0.0000
11
13
15
17
1
9
The Two Discrete Half-Periods
2.5000
2.0000
1 + sin(x*Pi/16)
1.5000
1.0000
0.5000
0.0000
10
13
16
19
22
25
28
31
1
7
Some Relevant Numbers From Excel
X 1 + sin(x * Pi/16) 2 - sin(x * Pi/16) 8 * 1 + sin(x * Pi/16)
0 1.0000 1.0000 8
1 1.1951 0.8049 10
2 1.3827 0.6173 11
3 1.5556 0.4444 12
4 1.7071 0.2929 14
5 1.8315 0.1685 15
6 1.9239 0.0761 15
7 1.9808 0.0192 16
8 2.0000 0.0000 16
9 1.9808 0.0192 16
10 1.9239 0.0761 15
11 1.8315 0.1685 15
12 1.7071 0.2929 14
13 1.5556 0.4444 12
14 1.3827 0.6173 11
15 1.1951 0.8049 10
16 1.0000 1.0000 8
Four-bit Approximation
18
8 * {1 + sin(x * Pi / 16)
16
14
12
10
Series1
8
6
4
2
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
4-bit sinusoid table
4-bit sin table
15
14
13
12
4-bit DAC output
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7
theta (radians)
SinTab 8,9,11,12,13,14,14,15,15,15,14
32 value sinusoid 14,13,12,11,9,8,7,5,4,3,2
2,1,1,1,2,2,3,4,5,7
112
Musical Notes
Note f T (ms) t - ouput (μs for 32 points)
C 523 1.91 59.75
B 494 2.02 63.26
b 466
B 2.15 67.06
A 440 2.27 71.02
b 415
A 2.41 75.30
G 392 2.55 79.72
b 370
G 2.70 84.46
F 349 2.87 89.54
E 330 3.03 94.70
b 311
E 3.22 100.48
D 294 3.40 106.29
b 277
D 3.61 112.82
C 262 3.82 119.27
Tone Generation
unsigned long I;
SysTick ISR
// 4-bit 32-element sine wave
const unsigned char wave[32]= {
8,9,11,12,13,14,14,15,15,15,14 Output one
value to DAC
14,13,12,11,9,8,7,5,4,3,2
2,1,1,1,2,2,3,4,5,7};
15,23,32,40,42,39,32,26,23,23,24,25, 30
20
25,26,29,30,31,32,34,37,39,37,35,34,
10
34,34,33,31,30}; 0
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64
20,20,20,19,16,12,8,4,3,5,10,17, 60
26,33,38,41,42,40,36,29,21,13,9, 50
9,14,23,34,45,52,54,51,45,38,31, 40
26,23,21,20,20,20,22,25,27,29, 30
30,29,27,22,18,13,11,10,11,13,13, 20
13,13,13,14,16,18,20,20,20}; 10
0
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64
Data Acquisition System Design
Data Acquisition System Design
• Time quantizing - Nyquist theory
– Nyquist theory states that if the signal is sampled at fs, then the
digital samples only contain frequency components from 0 to ½fs.
– Conversely, if the analog signal does contain frequency components
larger than ½fs, then there will be an aliasing error. Aliasing is when
the digital signal appears to have a different frequency than the
original analog signal.
V(t) = A sin(2πft + φ)
– Nyquist theory says that if fs is strictly greater than twice f, then one
can determine A, f and φ from the digital samples. \
But if fs less than or equal to 2•f, then the apparent frequency, as
predicted by analyzing the digital samples, will be shifted to a
frequency between 0 and ½fs.
– Valvano Postulate: If fmax is the largest frequency component of the
analog signal, then you must sample more than ten times fmax in order
for the reconstructed digital samples to look like the original signal
when plotted on a voltage versus time graph.
Data Acquisition System Design
• Time quantizing - Nyquist theory (Con.)
– The choice of sampling rate, fs, is determined by the
maximum useful frequency contained in the signal.
fs > 2 fmax
c = circumference
n = number of slots per rotation
w = wheelbase
Odometry
• Derivations (Continued)
– We can divide the change in position into two components
– The exact calculation for position change is
dz = (L+w/2)*tan(dθ/2)
but if dθ is small, we can approximate
dz by the arc length.
dz = dθ/2*(L+w/2)
• Initialize
– We initialize the system by specifying the initial position and yaw.
(x,y,θ) (0.01cm, 0.01cm, 0.01 radians)
Odometry
• Calculations (run this periodically, measuring LCount RCount)
Lr = LCount*c/n (0.01cm)
Rr = RCount*c/n (0.01cm)
L = (w*Lr)/(Rr - Lr) (0.01cm)
dθ = (100*Lr)/L (0.01 radians)
dz = ((dθ/2)*(L+w/2))/100 (0.01cm) approximation
or dz = (tan(dθ/2)*(L+w/2))/100 (0.01cm) more accurate
x = x + dz*cos(θ) (0.01cm)
y = y+ dz*sin(θ) (0.01cm) first part of move
θ = θ + dθ (0.01 radians)
x = x + dz*cos(θ) (0.01cm)
y = y+ dz*sin(θ) (0.01cm) second part of move
Odometry
• Needs very accurate sensors
• Errors accumulate
• OK for relative travel from known position
– Periodic absolute knowledge of position
MCU Based Controllers
• On/Off Controllers
• PID Controllers
• Fuzzy Controllers
On/Off Controllers
• Simple
• Cheap
• Used In residential heating and domestic refrigerators
• Limited use in process control due to continuous
cycling of controlled variable excessive wear
on control valve.
On/Off Controllers
• Synonyms:
“two-position” or “bang-bang” controllers.
C(s) = Kp
– Let X(s), X*(s), E(s) be the Laplace transforms of the state variable x(t), desired state
variable x*(t), the error e(t).
– m is the DC gain and τ is its time constant.
– The transfer function of the motor is H(s) = m/(1+τ ⋅s)
– The overall gain of the control system is
X(s)/X*(s) = G(s)H(s)/(1+G(s)H(s))
PID Controller
• Transfer function:
• Time windows:
– Proportional action responds to current error.
– Integrator action responds to accumulated past error.
– Derivative action anticipated future error.
• Frequency band:
– Proportional action: all-band
– Integrator action: low pass
– Derivative action: high pass
169
Effects of Proportional, Integral and Derivative Action
• A proportional controller (Kp) reduces the rise time and reduces but never eliminates the
steady-state error (unless use the feed forward action).
– Increasing Kp makes the response more oscillatory
• An integral control (Ki) eliminates the steady-state error, but it may make the transient
response worse.
– Response creeps slowly for small Ki, but faster for larger Ki, but the system also becomes more oscillatory.
• A derivative control (Kd) increases stability of the system, reducing the overshoot, and
improving transient response (increase response speed).
– Damping decreases again when derivative time becomes too large, i.e. derivative action does not help if the prediction
time Td is too large.
– A drawback with derivative action is that an ideal derivative has very high gain for high frequency signals. This means
that high frequency measurement noise or signal of step change will generate large variations of the control signal =>
put rapidly changing signals of control effort on actuators, make them vibrate and worn out.
• Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent on each other.
In fact, changing one of these variables can change the effect of the other two. For this reason, the table
should only be used as a reference when you are determining the values for Ki, Kp and Kd.
Effects of Proportional, Integral and Derivative Action
174
PID Structures
175
PID Structures
• Series to ideal form conversion:
176
Example: Incremental Control
Example: PI motor controller
Example: Integral Controller
• Let Error be the control variable
– 1) angle to wall
– 2) speed difference between wheels
– 3) distance to wall
• Run the controller
– 1) Faster than time constant of motor
– 2) No faster than sensor input rate
Controller Performance
• The response time is the delay after X* is changed for the
system to reach a new constant state.
where Tf is the filter time constant and n is the order of the filter.
– Tf is a compromise between filtering capacity and performance.
– The value of Tf can be coupled to the controller time constants in the same way as for the
derivative filter above.
– If the derivative time is used, Tf = Td/N is a suitable choice.
– If the controller is only PI, Tf = Ti/N may be suitable.
Wash-out Filtering
• If the 2nd filter is used, the PID controller is
• This structure has the advantage that we can develop the design methods
for an ideal PID controller and use an iterative design procedure.
• The controller is first designed for the process P(s). The design gives the
controller parameter Td.
• An ideal controller for the process
is then designed giving a new value of T d etc.
• Such a procedure will also give a clear picture of the trade-off between
performance and filtering
Other Modified Derivative Actions
Derivative action is the most difficult to tune, why?
Derivative action is the most difficult to tune, why?
Derivative action is the most difficult to tune, why?
188
Derivative action is the most difficult to tune, why?
• Consider the following process:
P(s) = 2 e−0.2s/(s + 1)
controlled by a PID controller in series form with Kp = 1
and Ti = 1.
• If Td = 0.01, GM=12.3dB, PM=68.2 deg.
• If Td = 0.05, GM=13.2dB, PM=72.7 deg.
• If Td = 0.5, the system stability is lost!
• In summary:
– Sensitive to noise
– Hard to tune (4 parameters)
Setpoint Weighting
• The normal PID controller leads to a system with error feedback because the
controller acts on the error. In this case, there could be a large initial peak of
the control signal, which is caused by the derivative of the reference signal.
The peak can be avoided by
Control Digital
Wind-up
• Windup is such a phenomena caused by the interaction of integral action and
saturations.
– All actuators have limitations: a motor has limited speed, a valve cannot be more than fully opened
or fully closed, etc. Thus the control variable could reach the actuator limits. When this happens
the feedback loop is broken and the system runs as an open loop because the actuator will remain
at its limit independently of the process output. And the error signal that is driving the controller
cannot reduce. If a controller with integrating action is used, the error will continue to be
integrated => The change in the error signal have no effect upon the control signal . This means that
the integral term may become very large or, colloquially, it “winds up”. Because of the saturation
this growth is not fed through the system and hence the controller cannot supply a corrective
action. The growth in the integral block output is called ‘wind-up’ and is a problem because the
output of the integral block can become very large before the error sign changes. In such cases it is
then required that the error has opposite sign for a long period before things return to normal. The
consequence is that any controller with integral action may give large/long transients when the
actuator saturates. This can continue for a long time and cause the controller to behave badly.
• One way to stop this is to reset the output of the integrator to zero at periodic times. Most commercial
controllers will have an ‘integral reset’ feature for this or place limits on the integrator output directly
within the integrator block. This does not completely prevent wind-up, because it only influences the
integral part of controller output.
• The other way is to use anti-windup.
Wind-up
• Actuator saturation reduces a control system’s ability to
follow a command input;
• Actuator saturation degrades transience performance;
• Anti-windup mitigates the adverse effects of actuator saturation;
– Traditional way for the design of anti-windup gain is ad hoc.
– Direct methods to control design in the presence of actuator saturation
– Systematic ways to design anti-windup gains, with guarantee of stability
and performance.
Conditional Integration
• The integral term is limited to a predefined value.
• The integration is stopped when the error is greater
than a predefined threshold, namely, when the process
variable value is far from the setpoint value.
• The integration is stopped when the control variable
saturates
• The integration is stopped when the control variable
saturates and the control error and the control variable
have the same sign
– i.e., when ue > 0
Wind-up Example
• Figure 6.6 shows control of an integrating process with a PI controller and integrator
windup which is generated by a change in the reference value.
– Windup may also be caused by large disturbances or equipment malfunctions. It can also occur in many
other situations.
• The initial set point change is so large that the actuator saturates at the high limit.
The integral term increases initially because the error is positive; it reaches its
largest value at t = 10 when the error goes through 0. The output remains saturated
at this point because of the large value of the integral term. It does not leave the
saturation limit until the error has been negative for a sufficiently long time to let
the integral part come down to a small level.
• Control signal bounces between its limits several times. The net effect is a large
overshoot and a damped oscillation where the control signal flips from one extreme
to the other as in relay oscillation.
• The output finally comes so close to the set point that the actuator does not
saturate. The system then behaves linearly and settles.
Wind-up Example
Control Digital
Anti-Windup: Set-point Limitation
• Introduce limiters on the setpoint variations so that
the controller output never reaches the actuator limits.
• This frequently leads to conservative bounds and poor
performance.
• It does not avoid windup caused by disturbances.
Anti-Windup:
Incremental Algorithms
• In the early phases, integral action was integrated with the actuator by having a
motor drive the valve directly. In this case windup is handled automatically because
integration stops when the valve stops.
• When controllers were implemented by analog techniques, and later with
computers, many manufacturers used a configuration that was an analog of the old
mechanical design. This led to the so-called velocity algorithms.
– A velocity algorithm first computes the rate of change of the control signal which is then fed to an
integrator. In some cases this integrator is a motor directly connected to the actuator. In other cases the
integrator is implemented internally in the controller.
– With this approach it is easy to avoid windup by inhibiting integration whenever the output saturates.
This method is equivalent to back-calculation, which is described below.
– If the actuator output is not measured, a model that computes the saturated output can be used. It is
also easy to limit the rate of change of the control signal.
Anti-windup for Automatic Reset Configuration
Anti-Windup: Back-Calculation
200
Anti-Windup: Back-Calculation
PID with Tracking Input
202
Anti-Windup:
Back-Calculation and Tracking
• When the output saturates, the integral term is recomputed so that its new value
gives an output at the saturation limit.
– It is advantageous not to reset the integrator instantaneously but dynamically with a time
constant Tt.
• Figure 6.7 shows a block diagram of a PID controller with anti-windup based on
back-calculation using the actuator math model.
• The system has an extra feedback path generated by measuring the actual actuator
output, or the output of a mathematical model of the saturating actuator.
Control Digital
Anti-Windup:
Back-Calculation
• eS is zero when no saturation & extra feedback loop has no effect on system.
• When the actuator saturates, the signal e S ( 0) is feedback to the integrator
through the gain Tt.
– The normal feedback path around the process is broken because the process input remains
constant. There is, however, a feedback path around the integrator. e S ( 0) is fed back in a way to
reduce the input to the integrator until eS = 0. This reduces the controller output until it equals the
saturation limit and stops wind-up.
– Because of this, the integrator output is driven towards a value such that the integrator input
becomes zero (eS goes towards zero), this reduces the controller output until it equals the saturation
limit and stops, i.e. the controller output is kept close to the saturation limit.
– The controller output will then change as soon as the error changes sign and integral windup is
avoided.
– By increasing the value of the anti-wind-up gain it is possible to reduce the wind-up some more. Be
careful of a big anti-wind-up gain because stability can be influenced - try to use the smallest value
that gives a reasonable response.
Anti-Windup:
Back-Calculation
• The integrator input (= 0) is:
where ulim is the saturating value. It means that the signal v settles on a value slightly
outside the saturation limit and the control signal can react as soon as the error
changes time/sign. This prevents the integrator from winding up.
• The rate at which the controller output is reset is governed by the feedback gain
(called tracking gain), Kt =1/Tt, a large value of Kt give a short reset time. Kt can,
however, not be too large because measurement error can then cause an undesirable
reset.
Anti-Windup Example
Back Calculation
• In Fig. 6.8, the output of the integrator is quickly reset to a value such that
the controller output is at the saturation limit, and the integral has a
negative value during the initial phase when the actuator is saturated.
– This behavior is drastically different from that in Figure 6.6, where the integral has a positive
value during the initial transient.
– Also notice the drastic improvement in performance compared to the ordinary PI controller
used in Figure 6.6.
• The effect of changing the values of the tracking time constant (T t = 1/Kt) is
illustrated in Figure 6.9.
– Advantageous to choose a very small value of the time constant because the integrator is
then reset quickly.
– Some care must be exercised when introducing anti-windup in systems with derivative action.
If the time constant is chosen too small, spurious errors can cause saturation of the output,
which accidentally resets the integrator. The tracking time constant Tt should be larger than Td
and smaller than Ti. A rule of thumb, a reasonable compromise is to choose Kt ≈ 1/Ti for PI
control and as Tt ≈ sqrt(TiTd) for PID control.
Anti-Windup Example
Back Calculation
Anti-Windup Example
Back Calculation
Cruise Control Example
• Fig. 10.7a shows the wind-up.
– A car encounters a hill that is so steep (6◦) that the throttle saturates when the cruise
controller attempts to maintain speed.
– When encountering the slope at t = 5 the velocity decreases and the throttle increases to
generate more torque. The torque required is however so large that the throttle saturates.
– The error decreases slowly because the torque generated by the engine is just a little larger
than the torque required to compensate for the gravity. The error is large and the integral
continues to build up until the error reaches zero at time 30, but the controller output is still
much larger than the saturation limit and the actuator remains saturated. The integral term
starts to decrease and at time 45 and the velocity settles to quickly to the desired value.
– Notice that it takes considerable time before the controller output comes in the range where
it does not saturate resulting in a large overshoot.
• In Fig. 10.7b (Kt = 2), because of the feedback from the actuator model the
output of the integrator is quickly reset to a value such that the controller
output is at the saturation limit and the large overshoot is avoided.
Cruise control
• Tracking gain: Kt = 2
Controllers with a Tracking Mode
• Figure 6.10 shows a PID module with a tracking signal. The new input TR is called a
tracking signal because the controller output will follow this signal. Notice that
tracking is inhibited when w = v. Using the module the system shown in Figure 6.7
can be presented as shown in Figure 6.11.
Controllers with a Tracking Mode
Bumpless Transfer
Bumpless Transfer
Bumpless Transfer
Bumpless Transfer
Motor Parameter Determination
• 1) Step response of the motor to get time constant τ.
2008
PID Controller Design
Performance Criteria For PID Design
• Ensure that the closed loop system has desirable dynamic and steady-
state response characteristics.
• Ideally, we would like the closed-loop system to satisfy the following
performance criteria:
1. The closed-loop system must be stable.
2. The effects of disturbances are minimized, providing good disturbance
rejection.
3. Rapid, smooth responses to set-point changes are obtained, that is, good set-
point tracking.
4. Steady-state error (offset) is eliminated.
5. Excessive control action is avoided.
6. The control system is robust, that is, insensitive to changes in process
conditions and to inaccuracies in the process model.
PID Controller Design
• Trade-offs in control problems
– Set point tracking vs. disturbance rejection
– Robustness vs. performance
• In process industries, more than 97% of the regulatory controllers
are of the PID type.
• Most loops are actually under PI control (as a result of the large
number of flow loops).
• Pulp and paper industry over 2000 loops:
– Only 20% of loops worked well (i.e. less variability in the automatic mode
over the manual mode).
– 30% gave poor performance due to poor controller tuning.
– 30% gave poor performance due to control valve problems (e.g. control
valve stick-slip, dead band, backlash).
– 20% gave poor performance due to process and/or control system design
problems.
PID Controller Design
• Process industries:
– 30% of loops operated on manual mode.
– 20% of controllers used factory tuning.
– 30% gave poor performance due to sensor and control valve problems.
• Chemical process industry:
– Half of the control valves needed to be fixed (results of the Fisher diagnostic valve
package).
– Most poor tuning was due to control valve problems.
• Refining, chemicals, and pulp and paper industries over 26,000
controllers:
– Only 32% of loops were classified as excellent or acceptable.
– 32% of controllers were classified as fair or poor, which indicates unacceptably sluggish
or oscillatory responses.
– 36% of controllers were on open- loop, which implies that the controllers were either
in manual or virtually saturated.
– PID algorithms are used in vast majority of applications (97%). For the rare cases of
complex dynamics or significant dead time, other algorithms are used.
PID Design Methods
• PID controller settings can be determined by a number
of alternative techniques:
1.Direct Synthesis (DS) method
2. Internal Model Control (IMC) method
3. Controller tuning relations
4. Frequency response techniques
5. Computer simulation
6. On-line tuning after the control system is installed.
PID Controller Implementation
• Implementation methods:
– Pneumatic
– Hydraulic
– Electronic
– Digital
Implementation based Operational Amplifiers
Control Digital
Why digital PID?
• PID controllers have survived many changes in technology, from
mechanics and pneumatics (continuous) to microprocessors
(digital) via electronic tubes, transistors, integrated circuits.
• Microprocessor has had a dramatic influence on the PID
controller. Practically all PID controllers made today are based on
microprocessors.
– Provide additional features like automatic tuning, gain scheduling, and
continuous adaptation.
– Programmable, flexibility, easy digital integration,…
Digital Control System
Computer Implementation
Sampling
• When the controller is implemented in a computer, the analog inputs are
read and the outputs are set with a certain sampling period. This is a
drawback compared to the analog implementations, since the sampling
introduces dead-time in the control loop.
• When a digital computer is used to implement a control law, the ideal
sequence of operation is the following.
– Wait for clock interrupt
– Read analog input
– Compute control signal
– Set analog output
– Update controller variables
– Repeat
• Notice that an output is sent to the actuators as soon as it is available. The time
delay is minimized by making the calculations in Step 3 as short as possible and
performing all updates after the output is commanded.
Computer Implementation
Sampling
• With this implementation, the delay is minimized.
• If the analog input is read with a sampling period h, the average delay of the
measurement signal is h/2.
• The computation time is often short compared to the sampling period. This
means that the total delay is about h/2.
• However, most controllers and instrument systems do not organize the
calculation in this way. Therefore, the delays introduced because of the
sampling is often several sampling periods. ?????
Control Digital
Computer Implementation
Aliasing - Prefiltering
• Because of sampling/aliasing, high frequency signals, which in analog controllers
normally are effectively eliminated by low-pass filtering, may appear as low-
frequency signals in the bandwidth of the sampled control system => disturb the
system adversely.
– To avoid this, an analog prefilter which effectively eliminates all signal components with
frequencies above half the sampling frequency should be introduced. Such a filter is called an anti-
aliasing filter.
– A second-order Butterworth filter is a common anti-aliasing filter. Higher-order filters are also used
in critical applications.
• The selection guide of the filter bandwidth (ωb)
– Assume we want the prefilter to attenuate signals by a factor of 16 at half the sampling frequency
(ωs), we need to design:
(ωs/2ωb)2 = 16 => ωb= ωs/8
i.e., the bandwidth is 1/8 of the sampling frequency f S & the prefilter significantly attenuate any
disturbance signals of the high frequency (above f S/2) accordingly.
– Notice that the dynamics of the prefilter is often significant. It should be accounted for in the
control design by combining it with the process dynamics.
Digital Control System
Approximating Continuous-Time Controllers
235
Approximating Continuous-Time Controllers
Discrete PID control
using Numerical Integration
Discrete PID control
using Numerical Integration
Control Digital
Digital PID
Digital PID: Inverse Response
• Inverse Response: When the initial response of a dynamic
system is in adirection opposite to the final outcome, it is
called an inverse response.
• Obtaining the effective delay (Half rule):
– Effective delay =True delay + inverse response time constant (s)
• + half of the largest neglected time constant
• + all smaller higher order time constants
• Time constant:
= the largest time constant + 1/2 the second largest time constant
– 1 = the largest time constant,
– 2 = the second largest time constant + 1/2 the third largest time
constant
Digital PID: Inverse Response
Digital PID: Inverse Response
Example 1: PID Code
• Implement code for the following digital PID:
Example 1: PID Code Version 1
Example 1: PID Code Version 2
Example 1: PID Code with Anti-Windup
Example 2: PID Code
258
Example 4: PID in Motor Control using RTOS
• Note: this example uses a different, integer-based, PID
implementation. As we discussed in ‘Hardware resource
implications’, integer-based solutions impose a lower CPU load
than floating-point equivalents.
262
Example 6: PID using PIC
263
Practical consideration in PID implementation
• Overflow:
– Due to the range that the digital system can present
– E.g., can not present 1.25 as 4-bit fractional number
– Solutions: Use fixed-point representation/operations carefully or use
floating point co-processors (but costly)
Practical consideration in PID implementation
• Anti-Aliasing:
– Solutions: Use high sampling frequency or use pre-filters to remove high
frequency components of signals (noises)
• Computation delay
– Inherent delay in processing
• Actuation occurs later than expected
– Solutions: Need to characterize implementation delay to make sure it is
negligible
• Hardware delay is often easy to characterize
– Synchronous design
• Software delay is harder to predict
– Should organize code carefully so delay is predictable and minimized
– Write software with predictable timing behavior (be like hardware) using timer triggered
architecture or synchronous software language and/or RTOS
Practical consideration in PID implementation
• Hardware resource implications
– Implementation of a PID requires some floating-point or integer
mathematical operations. The precise load will vary with the
implementation used, but a typical implementation requires 4
multiplications, 3 additions and 2 subtractions. With floating-point
operations, this amounts to a total of approximately 2000 instructions
(using the Keil compiler, on an 8051 without hardware maths support). This
operation can be carried out every millisecond on a standard (12 osc /
instruction) 8051 running at 24 MHz, if there is no other CPU-intensive
processing to be done.
– A one-millisecond loop time is more than adequate for most control
applications, which typically require sample intervals of several hundred
milliseconds or longer.
– Of course, if you require higher performance, then many more modern
implementations of the 8051 microcontroller can provide this.
– Similarly, devices such as the Infineon 517 and 509, which have hardware
maths support, will also execute this code more rapidly, should this be
required.
Final words about PID
• PID is suitable for processes with almost monotone step responses provided
that requirements are not too stringent.
• PID control is not suitable for processes that are highly oscillatory or when
the requirements are extreme.
• PI has no phase advance. This means that PI will not work for systems which
have phase lag of 180’or more.
– The double integrator is a typical example. Controller with derivative action can provide
phase advance up to about 50’
– Simple processes can be characterized by the relative time delay τ introduced in the Ziegler-
Nichols tuning procedure. PI control is often satisfactory for processes that are lag dominated,
i.e. when τ close to one. Derivative action is typically beneficial for processes with small
relative delay τ
• The PID controller being linear is not suited for strongly nonlinear systems.
Excellent results can however be obtained by combining the PID controller
with gain scheduling. A particularly attractive feature is the use of auto-
tuning which drastically reduces the effort required to build up the gain
schedule.
Final words about PID
GUIDELINES FOR COMMON CONTROL LOOPS
• Flow and liquid pressure control
– Fast response with no time delay
– Usually with small high-frequency noise
– PI controller with intermediate controller gain
• Liquid level control
– Noisy due to splashing and turbulence
– High gain PI controller for integrating process
– Conservative setting for averaging control when it is used for damping the
fluctuation of the inlet stream
• Gas pressure control
– Usually fast and self regulating
– PI controller with small integral action (large reset time)
Final words about PID
GUIDELINES FOR COMMON CONTROL LOOPS
• Temperature control
– Wide variety of the process nature
– Usually slow response with time delay
– Use PID controller to speed up the response
• Composition control
– Similar to temperature control usually with larger noise and more time
delay
– Effectiveness of derivative action is limited
– Temperature and composition controls are the prime candidates for
advance control strategies due to its importance and difficulty of control
Future of PID
• Quite reasonable to predict that PID control will
continue to be used in the future.
– Feedback has had a revolutionary influence in practically all
areas where it has been used and will continue to do so.
– PI(D) control is perhaps the most basic form of feedback. It is
very effective and can be applied to a wide range of problems.
– The emerging features of automatic tuning have greatly
simplified the use of PID control. More knowledge about PID
control has been available for a long time. Unfortunately, it has
been buried in proprietary information of suppliers. There was a
strong resurgence in the interest in PID control over the last 15
years. Many publications have appeared and it is typical that
IFAC organized a workshop on PID control in the year 2000.
Future of PID
• The alternatives to PID control are:
– RST: Discrete-time linear MISO controllers.
– SFO: State feedback and observers.
– MPC: Model predictive control.
• Fuzzy control is often mentioned as an alternative to PID control, see Passino and
Yurkovich (1998).Most fuzzy controllers used in industry have the same structure
as incremental PI or PID controllers. The parameterization using rules and fuzzy
membership functions makes it easy to add nonlinearities, logic, and additional
input signals to the control law.
• The main advantages claimed by fuzzy control are that it is easy to use and that it
is nonlinear. Many of the comparisons between PID and fuzzy control made in the
literature are, however, very sloppy. A textbook PID with Ziegler–Nichols tuning is
typically used as a reference. Furthermore, if nonlinear behavior is desired gain
scheduling can be added to a PID controller. Many fuzzy controllers are also used
in a cascade structure using PID controllers at the lower level. An advantage of
fuzzy control is that very good software is available.
• Many fuzzy controllers are, however, used in a cascade structure using PID
controllers at the lower level.
Future of PID
• All control method alternatives offer potential improvements in the linear
behavior of the system. This is particularly useful when dealing with systems
having poorly damped oscillatory modes. It is, however, necessary to take
actuator saturation and windup into account. This is done very well for MPC
but it requires special consideration for RST and SFO, particularly in
combination with mode changes.
• The tuning problem is a major difficulty with all alternatives. Much work is
needed in order to develop appropriate tuning tools.
• The RST controller is beginning to appear in applications for motor drives. The
improvements in performance are particularly important for high performance
systems.
• Controllers based on state feedback and observers are used in special
applications where the cost of the modeling effort can be justified.
Future of PID
• MPC is typically used in supervisory mode with PID controllers at the base
level.
– Much of the improvement accredited to MPC in the process industry actually comes from the
improved tuning of the basic loops. The MPC does, however, offer drastic improvements in set
point responses for multivariable systems because of the coordination it provides.
– There are several interesting problems related to the integration of MPC and PID. Tuning of the
PID controller in the inner loop gives valuable modeling information for the MPC. Since the MPC
operates in a supervisory mode it can deal with slow interactions very well.
– The lower level PID loops still have to manage fast interactions.
• Another issue is the general philosophy of approaching design of a complex
system. Top–down approaches to system design will clearly favor SFO and
MPC. A bottom–up approach favors the use of simple building blocks such as
PID controllers. In this context, it is interesting to see how the PID controller
can be augmented. The set point response can be improved substantially by
exploiting a controller structure with two degrees of freedom
• Special considerations have to be given to a PID controller that will be used
effectively in this way. It is particularly important that the controller output is
available for feedforward in such a way that saturation and windup are
handled properly.
Future of PID
• More improvements can be made through proper use of
feedforward. Other possibilities are to add filters and blocks for
dealing with measurement noise and systems having oscillatory
modes.
• There are many good research problems in developing good
approaches to bottom up design techniques. The problem of
exploring system interactions is an important one.
• Even if the applications of other control strategies increase, PID
control will certainly continue to be used.
– When correctly used it is a very effective way of using feedback. Good results can
often be obtained if the performance requirements are not extreme. The PID
controller will also serve as a building block in more complex controllers. Most
DMC controllers in fact deliver set points to PID controllers. Good performance of
these PID controllers are essential. Much commissioning work for DMC control
actually consists of tuning up the underlying PID loops.
– There are also useful augmentations for PID control in the form of Smith
predictors, gain scheduling and filters for oscillatory systems.
Future of PID
• It is important to realize that there is a very wide range of control problems
and consequently also a need for a wide range of tuning techniques.
– There are already many tuning methods available, but a replacement of the Ziegler–Nichols
method is long overdue. It is very easy to demonstrate that any controller with reasonable
tuning will outperform a PID with Ziegler–Nichols tuning. Many strategies proposed can easily
be eliminated if they are compared with a well-tuned PID.
• Development of suitable software is another area that has to be developed.
PID control is quite under-developed in that respect compared, for example, to
fuzzy control. It would be highly desirable to have software so that persons
with a moderate knowledge can experiment with PID control. Tools for
modeling and methods for automatic tuning should be a part of such a
software.
• On the research side, it appears that the development of design methods for
PID control is approaching the point of diminishing returns. There are some
difficult problems that remain to be solved. For example, there is no
characterization of the processes where PID control is useful.
FLC: Fuzzy Membership Set
• A fuzzy membership set, a fuzzy variable and a fuzzy set
– A value/software variable specifying levels of truth
• E.g., Going too slow/Speed is ok/Going too fast
– Collection describes the entire system
(half true)
(half true)
Fuzzification
Fuzzy Rules
• The Fuzzy rules calculate output fuzzy membership
sets.
(half true)
Defuzzification
• The Postprocessor modify crisp outputs into a more
convenient format;
dN (or dU)
• The Actuator System affects the Physical plant based
on these output.
N = N+dN (or U = U+dU)
• Control output N (or U)
• N (U): the duty cycle to motor interface, 100 to 9900
(0.01%)
Fuzzy Logic Controller
Controller Summary
• Incremental
– Simple
– Stable
– Slow response
• PID or PI
– Plant can be described using linear differential equations
– Theory, fast response
– Needs empirical tuning, depends on load
• Fuzzy logic: Maps human intuition into rules
– Execute faster
– Good when there is expert knowledge
– Maps intuition into rules
– Abstractive approach
– Needs empirical tuning
Noise & Noise Reduction
Types of Noise
• Broadband
– i.e., all frequencies, like white noise