Sie sind auf Seite 1von 9

9

3/28/2005

BAE 3023
1
Expression Of Of A PID Controller Equation As A Difference Equation
Implementation of a PID controller in
BASIC
9

3/28/2005

BAE 3023
2
One of the conventional models used to express a PID controller is:
|
|
.
|

\
|
+ + =
}
=
dt
de
edt e K M
d
t
t
i
c
t
t
0
1
rate Derivitive
rate Reset
signal Error e
gain Controller K
on Manipulati M
d
i
c
=
=
=
=
=
t
t
Time Domain PID
Controller Equation
Where:
9

3/28/2005

BAE 3023
3
Derivitive Form of a PID
Controller
A convenient way to implement this equation in a controller is as the
derivative of manipulation known as the velocity form of the equation
as shown below:
|
|
.
|

\
|
+ + =
2
2
dt
e d e
dt
de
K
dt
dM
d
i
c
t
t
In a practical system this equation will work well, but eliminating the t
i

and t
d
term completely results in:
|
.
|

\
|
=
dt
de
K
dt
dM
c
de K dM
c
=
or,
This equation has no positional reference and error accumulation can
be a problem.
9

3/28/2005

BAE 3023
4
Conversion of the DE to
a Difference Equation
To begin the conversion of the PID equation to a
difference equation, the equation is multiplied by dt.

|
|
.
|

\
|
|
.
|

\
|
+ + =
dt
de
d
edt
de K dM
d
i
c
t
t
Note that since M is a differential and e
ss
is zero,
this equation applies to the absolute variables
as well as the deviation variables.
For small At, the equation can be approximated as:
|
|
.
|

\
|
|
.
|

\
|
A
A
A +
A
+ A = A
t
t
K m
d
i
c
c
t
t
c
c
9

3/28/2005

BAE 3023
5
Representation with
Discrete Time Variables
Each of the differences (A) can be expressed as discrete values of
each of the variables ( m and c ) at the times 0, 1, and 2 as shown
below:
t
0
t
2
t
1
M
c
c
1
c
2
c
0
M
0
M
1
M
2
The equation can be simplified with the assumption that At is
constant:
( )
|
|
.
|

\
|
A A
A
+
A
+ A = A c
t
t
c
c
t
t
K m
d
i
c
9

3/28/2005

BAE 3023
6
Discrete form of PID
controller
Replacement of the differences (A) with the discrete
variables ( m and c ) results in:
( ) ( ) ( )
|
|
.
|

\
|
A A
A
+
A
+ =
1 2
2
1 2 1 2
) ( c c
t
t
c
c c
t
t
K m m
d
i
c
( ) ( ) ( )
|
|
.
|

\
|

A
+
A
+ =
0 1 1 2
2
1 2 1 2
) ( c c c c
t
t
c
c c
t
t
K m m
d
i
c
( )
|
|
.
|

\
|
+
A
+
A
+ =
0 1 2
2
1 2 1 2
2 ) ( c c c
t
t
c
c c
t
t
K m m
d
i
c
Note that At is a constant.
9

3/28/2005

BAE 3023
7
Discrete form of PID
controller
This equation can be solved for the current manipulation, m
2
, in terms
of values known at time t
2
: m
1
, e
2
, e
1
, and e
0
.
The other parameters in the equation are constants.
|
|
.
|

\
|
A
+
|
.
|

\
|
A

|
|
.
|

\
|
A
+
A
+ + =
0 1 2 1 2
2
1 1 c
t
c
t
c
t
t t t t
t
K m m
d d d
i
c
Where C
1
,C
2
, and C
3
are constants and the current manipulation is
expressed in terms of known values, the current and past errors.
( )
0 3 1 2 2 1 1 2
c c c c c c K m m
c
+ + =
or,
9

3/28/2005

BAE 3023
8
Translation of PID
Equation into Algorithm
This equation may be translated directly into a computer language, for
example:

M2 = M1 + K*(C1*E2 C2*E1 + C3*E0)

Within a computer program, the current error
is calculated from the current measurement of
the controlled variable and the setpoint, for example:

E2 = T9 T
Where T9 is the setpoint

The current manipulation M2 is then computed using the previous
controller equation, and finally, at the end of the time step, each of the
variables is shifted forward for the next calculation.


9

3/28/2005

BAE 3023
9
Translation of PID
Equation into Algorithm
For example in BASIC, the code might look like:

90 GOSUB 2000 : REM Measure T
100 E2 = T9 T
110 M2 = M1 + K*(C1*E2 C2*E1 + C3*E0)
120 GOSUB 3000 : REM Manipulate using M2
120 E0 = E1
130 E1 = E2
150 M1= M2
160 GOTO 90

Note that the time step At is controlled by the time required to execute
the loop.

Das könnte Ihnen auch gefallen