You are on page 1of 21

S7-200 Tip

PID

Tip No. 32

SIMATIC
S7-200 Tips
Group
6

Topic
PID Controllers for the S7-200 CPU 214

Overview
This programming example shows a method for programming a Proportional Intergral Derivative
(PID) controller on a CPU 214. The example is already a fully functioning program, needing only
for the user to tie the actual inputs and outputs to appropriate variables to be a working
controller.
To prepare a user to make these programming changes, the text will explain the basics of the
PID controller implemented in the sample code. Below is a brief outline for the rest of this
document:
1. What does the example program do?
2. Where do you use a PID controller?
3. Auto Mode vs. Manual Mode
4. What does a PID controller do, and how?
5. What are the Sample, Gain, Rate, and Reset?
6. How is the Error figured?
7. How is the Proportional term figured?
8. How is the Integral term figured?
9. How is the Derivative term figured?
10. What if the final Output is too high?
11. What should the user add to make the program work for his system?
12. Adjusting the Reset, Rate, Gain, Sample time and Mode during run-time

Hardware Requirements
SIMATIC S7-200 CPU 214
NOTE: PID will only work on a SIMATIC S7-200 CPU 214 that supports real (floating point)
math.

Copyright 1996 by SIEMENS


Status: 10/96

page 1 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

PID Explored
What does the example program do?
This compilable programming example is a skeleton program for a true PID controller and, as
such, requires that the user make a few additions (i.e. read/write input/output variables) before it
is fully functional. Before discussing these, however, lets get a better feel for what a PID
program actually does through a brief example.
Steam
Steam Flow
Turbine
Water Tank

Hot Plate
Temperature
Control

Hot Plate

Figure 32.1 An Example System


When do you use a PID controller?
Figure 32.1 shows a picture of an example system to which a user might connect a PID
controller. The figure shows a water tank sitting atop a hot plate, with a temperature control
device for the hot plate and a small, monitored turbine for measuring the rate of the steam flow.
This is a system that will work with a PID controller because of the relationship between the two
variables: You can directly control the steam flow rate by adjusting the temperature of the hot
plate. Figure 32.2 shows how both variables relate to the PID controller.
Steam Flow
Turbine
Process
Variable
CPU 214

SIEMENS

Output
CPU214 running a
PID program.

Temperature
Control

Figure 32.2 An Example of a PID Controlled System

Copyright 1996 by SIEMENS


Status: 10/96

page 2 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

The variable which represents the state of the system being controlled is called the Process
Variable. In our example above, you can see that the rate at which the steam spins the turbine
is a good indicator of the event that we are trying to control: the speed at which the water is
being boiled off. The output is the variable which, being altered by the controller, can affect the
process variable by different degrees based on its intensity -- By turning the hot plate up, the
water boils more quickly, more steam is produced, and the turbines speed increases.
Therefore, when a variable that accurately reflects the state of the process and an adjustable
control which proportionally affects the process variable, then it is possible to use a PID
controller. Common systems using PID controllers are air conditioning systems, solution mixing,
heaters, etc.
Auto Mode vs. Manual Mode
There are two settings available on our PID controller. Putting a controller in Manual mode
causes the PID loop do nothing, so that the user can directly control the output. The second,
Auto, is the mode in which the PID loop is actually controlling the system. For the rest of this
text, it will be assumed that the controller is in Auto mode.
What does the PID controller do, and how does it do it?
Quite simply, a PID controller adjusts the value of its output to try and balance the value of the
process variable to a given setpoint. To calculate the output value for a given instance, the
controller finds the value of three different terms (using its user defined Sample time, Gain,
Rate, and Reset values along with the calculated Error value): a Proportional term, an Integral
term, and a Derivative term.
2XWSXW 030,0'
Formula 32.1
What are the Sample, Gain, Rate, and Reset, and where do they come from?
The sample rate is the cycle time (in milliseconds) at which the PID loop recalculates the output.
The gain controls the sensitivity of the output calculation by affecting the influence of all the
terms. The reset is a time given in milliseconds which is used to increase or decrease the
influence of the Integral term in the equation. Finally, the rate value is used to control the
influence of the Derivative term in the equation. Each of these values needs to be preset by the
user before the PID controller starts.
If the user does not want integral action (no I in the PID calculation), then a value of infinity
should be specified for the integral time. If the user does not want derivative action (no D in the
PID calculation), then a value of 0 should be specified for the derivative time. If the user does
not want proportional action (no P in the PID), then a value of 0 should be specified for the gain
(gain is normally a multiplier in the integral and derivative coefficient calculation, but is removed
from the coefficient calculation, if gain = 0, to allow I, ID, or D loop control).

Copyright 1996 by SIEMENS


Status: 10/96

page 3 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

How is the Error figured?


Error is figured as the difference between the normalized values of the setpoint and the process
variable. The controller calculates this value in three steps. The first two steps are to change
both the setpoint and the process variable into values that are based on a 0 to 1 (normalized)
scale. This is done using the formulae:
63 UDZB63PD[BYDO

39 UDZB39PD[BYDO

Formulae 32.2 & 32.3


In the above formulae, the raw_SP and raw_PV values are the actual values that come into the
controller, and the max_val term is the maximum value that either can take on. For example, if
the values of raw_SP and raw_PV were being read in as values from 0 to 32,000, then the
max_val term would have the value 32,000.
After these two values have been calculated, the error term is figured as follows:
(UURU 6339

Formula 32.4
How is the Proportional term calculated?
The proportional term, MP, is calculated using the following equation:

*DLQ (UURU

03 

Formula 32.2

Going back to our earlier example with the water tank, the proportional term says that as the
speed of the turbine increases further above the setpoint, the heat is decreased proportionally to
bring the speed down. As the turbine slows below the setpoint, the heat is increased to
proportionally to bring the speed up.
How is the Integral Term calculated?
The integral term, MI, is calculated using the following equation:

,

(UURU

%LDV &, 

Formula 32.3

In this equation, two new terms are introduced. The first, CI, is the coefficient of the Integral
term, and is calculated from the Reset:
&, *DLQ  6DPSOH5HVHW

Formula 32.4
Both the Sample and Reset terms were introduced earlier, but in this equation their uses
become apparent. The larger the Reset value is, the less impact the integral term will have on
the output, while larger Sample times give it a bigger influence (Sample time also affects the
Derivative term, which will be explained later).

Copyright 1996 by SIEMENS


Status: 10/96

page 4 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

The Bias term in Formula 32.3 represents (technically speaking) the area under the curve of a
graph plotting the Error vs time.
Abstractly, however, the Bias value (ideally) grows to an output level that keeps the system
stable, letting the Proportional and Derivative terms handle any small fluctuations. In relation to
our water tank example from earlier, this means that eventually the Bias portion of MI would be
the only significant contribution to the final output value, and the MP and MD terms would only be
active (non-zero) when a fluctuation occurred.
At a time n the equations for , and the Bias term are:

,Q

%LDVQ &, (UURU


%LDVQ 0,Q

Formula 32.5
How is the Derivative term calculated?
The derivative formula for a given time n is calculated with the following equation:
0' &'  39Q39Q

Formula 32.6
This formula only introduces 1 new term, CD, which is calculated using Formula 32.7.

&'

*DLQ  5DWH6DPSOH

Formula 32.7

The Sample term (which is also used in figuring CI) is the sample time from earlier. In the
Derivative term, the Sample time is indirectly proportional to the derivative component, while the
Rate is directly proportional.
What if the final output value is too high?
During many processes (such as the water tank example earlier), the Process variable doesnt
respond immediately to a change in the value of the output -- if the water in the tank were ice
cold, then even an output of 100% is not going to cause an instantaneous increase in steam
flow. Likewise, setting the output to 0% when the water is boiling doesnt provide an immediate
reduction in steam production.
Because of this system inertia, the output value for a give time could take on a value greater
than 100% or less than 0%. In response to this, the PID program implements Output Clamping.
If the output is greater than 100%, then it is clamped to 100%. If the output falls lower than 0%,
then it is held to 0%.

Copyright 1996 by SIEMENS


Status: 10/96

page 5 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

The only problem left to solve lies with the Bias portion of the Integral term. When the output for
a system remains at 100% for a long period of time (such as when heating up cold water in our
tank from earlier), the integral sum (which the Bias term represents) can grow to extremely large
values. This means that when the variable starts responding, the Bias term will be keeping the
calculated output well over 100% until it can be wound down. This generally results in the output
swinging wildly from one limit to the other, but can be avoided using Bias Clamping.
There are a few different types of Bias Clamping, but the only pertinent one here is the one used
in the program. There are two different conditions which cause Bias clamping to occur and two
formulae as well:
,I2XWSXW!
%LDV  030'

Formula 32.8

,I2XWSXW
%LDV  030'

Formula 32.9

As the formulae show, when the Output grows to be greater than 1, the value of the Bias is
adjusted so that the sum of MP, MD, and the Bias will be 1. Likewise, when the Output slips
below 0, the value of the Bias is adjusted so that the above sum will be 0. The adjusted Bias
value is then clamped such that its maximum value is 1 and its minimum value is 0.
What should be added to make the program work for the system?
1. Read in the Process Variable
2. Write the Output
3. Set the Setpoint
4. Adjust the scale for the Input and Setpoint
5. Adjust the scale for the Output
6. Adjust the Reset, Rate, Gain, and Sample time values.

Read in the Process Variable


The Process variable (the variable which accurately reflects the state of the system to be
controlled) should be read into VW3002 by the users code.
Write the Output
The PID loop places the Output value into VW3006 where it can be accessed by the users
code.
Set the Setpoint
The Setpoint value is to be placed in VW3004 by the users code.

Copyright 1996 by SIEMENS


Status: 10/96

page 6 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

Adjust the scale for the Process Variable and Setpoint


Near the beginning of each call to the PID routine (immediately after LBL 0) the program
converts the raw_PV value into a normalized (0-1) value based on a scale of 0 to 32,000. If the
value that the user is reading in is on a different scale, the user has to change the 32,000s
between LBL 0 and LBL20 to the new value. For example, if the scale were 0 to 100, you would
change the 32,000s to 100s.
Adjust the scale for the Output
In the network immediately preceding the RETI instruction at the end of the program, the Output
value is changed from a normalized value (0-1) into a scaled number (0-32,000). As in the
above section, to change the scale of the output, simply change the 32,000 into the new
maximum value.
Adjust the Reset, Rate, Gain, and Sample time values
The final thing that the users code needs to implement is the setting of the Reset, Rate, Gain,
and Sample time values. This could be done in a subroutine that is called only during the first
cycle. The values should be placed as follows:
Reset
Rate
Gain
Sample

VD3020 (real)
VD3016 (real)
VD3008 (real)
VD3012 (real)

Adjusting the Reset, Rate, Gain, and Sample time, and Mode during run-time
The Reset, Rate, Gain, and Sample time values are all set during the first cycle through the PID
loop, and any subsequent changes to the values in VD3008-VD3020 will not be reflected in the
programs operation unless the update bit of the control byte is set. The control byte is VB3001,
and the update bit is bit 7. When V3001.7 is 1, then on the next cycle through the PID loop, all of
the above values will be updated.
The control byte can also be used to change the PIDs mode. When the update bit is set, the
value in V3001.0 indicates the new mode. A value of 1 indicates Auto, while a 0 indicates
Manual.
The program size is 335 words.

Copyright 1996 by SIEMENS


Status: 10/96

page 7 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

Main Program
// Description:
// This S7-200 user program is intended to implement a simple PID loop. The body of the PID loop is
// embedded in a user interrupt routine attached to a timed interrupt. A block of V memory is reserved for
// the use of the PID algorithm, starting at VB3000. This loop data area is divided into 2 sections, user area
// and a working variable area, as shown below:
//
//
VB3000
-> control_byte
[bit field, described below]
//
VB3001
-> status_byte
[bit field, described below]
//
VW3002
-> raw_PV
[signed integer, range 0-32000]
//
VW3004
-> raw_SP
[signed integer, range 0-32000]
//
VW3006
-> raw_OUTPUT
[signed integer, range 0-32000]
//
VD3008
-> raw_GAIN
[real]
//
VD3012
-> raw_SAMPLE time[real, in msec intervals]
//
VD3016
-> RATE time
[real, in msec]
//
VD3020
-> RESET time
[real, in msec]
//
VD3024-3029
-> user reserved
//
// working VB3030
-> internal_status
[bit field, described below]
//
VD3031
-> PV
[real, scaled 0.0-1.0]
//
VD3035
-> SP
[real, scaled 0.0-1.0]
//
VD3039
-> OUTPUT
[real, scaled 0.0-1.0]
//
VD3043
-> ERROR
[real]
//
VD3047
-> BIAS
[real]
//
VD3051
-> PV_OLD
[real]
//
VD3055
-> I_COEF
[real]
//
VD3059
-> D_COEF
[real]
//
VD3063
-> GAIN (shadow)
[real]
//
VD3067
-> SAMPLE
[real]
//
// The PID routine will use the current PV and setpoint values stored in the raw_PV and raw_SP fields
// of the user area each time the loop calculation is performed. The control byte must be used to assert
// changes in mode, gain, sample time, and rate/reset time. First, the desired data values must be
// written to the fields of the user area and the control byte. Then the most significant bit of the
// control byte must be set to direct the PID routine to accept the new values. The PID routine will clear the
// MSB when the new values have been processed.
//
bit
7 6 5 4 3 2 1 0
//
x 0 0 0 0 0 0 x
//
^
^
//
|
|
//
|
--- mode (1=auto, 0=manual)
//
|
//
---- update values (1=update)
//
// The status byte is used to feed back current configuration of the loop to the user. The format of the
// status byte is as follows:
//
//
bit 7 6 5 4 3 2 1 0
//
0 0 0 0 0 0 0 x
//
^
//
|
//
--- mode (1=auto, 0=manual)
//

Copyright 1996 by SIEMENS


Status: 10/96

page 8 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

//
// The internal status byte in the working data area is used by the PID routine for "private" flags. The
// format of this byte is as follows:
//
//
bit 7 6 5 4 3 2 1 0
//
x 0 0 0 0 0 0 x
//
^
^
//
|
|
//
|
--- mode (1=auto, 0=manual)
//
---- first cycle flag (1=first cycle)
//

60),//B1
(1

.,12879:
.1

029B%
(1

.,128760%


$7&+
(1

.,17
.(97


 (1,

LD
FILL
MOVB
ATCH

SM0.1
0,
100,
100,

VW3000,
SMB34
10

ENI

36

//
// clear user area of V memory
// test code - setup for 100 msec
// sample time (the same value should used for the
// PID raw_SAMPLE time (VD3012)
// Enable interrupts

60029B5
(1

.5,12879'


029B5
(1

.5,12879'



Copyright 1996 by SIEMENS


Status: 10/96

page 9 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

029B5
(1

.5,12879'


029B5
(1

.5,12879'


029B%
(1

.+,12879%


// The user program must load the user fields and operate the PID.
// The user program would replace the following demo program.
// ***** Start of demo program *****
LD
SM0.1
MOVR
100.0,
VD3012
MOVR
MOVR
MOVR
MOVB

1.0,
0.0,
60000.0,
16#81,

VD3008
VD3016
VD3020
VB3000

// On the first scan set up the PID routines


// raw_SAMPLE time [real, in msec] must be the
// same value that is loaded into SMB34
// raw_GAIN [real]
// RATE time [real, in msec] = 0 minute
// RESET time [real, in msec] = 1 minute
// Put PID in Auto mode and set first cycle flag

60029B:
(1

$,:,12879:


029B:
(1

9:,1287$4:


LD
MOVW

SM0.0
AIW0,

VW3002

MOVW

VW3006,

AQW0

// Every scan
// Transfer Analog Input value to the raw_PV
// [signed integer, range 0-32000]
// Transfer raw_OUTPUT to Analog Output
// [signed integer, range 0-32000]

// The Set Point raw_SP (VW3004 signed integer, range 0-32000] must be loaded from an operator interface
// device.
// ***** End of demo program *****

Copyright 1996 by SIEMENS


Status: 10/96

page 10 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32


 0(1'

MEND

// End of main program

,17

9
 -03

// INT 100 - PID routine
// Check for active indication to update loop values. If the bit is asserted, recalculate new integral and
// derivative coefficients and perform any required mode changes.
INT
LDN
JMP

100
V3000.7
0

//
// If (control_byte.update_values = TRUE)
//

60029B5
(1

9',12879'


029B5
(1

9',12879'


029B5
(1

9',12879'


029B5
(1

9',1287$&


',9B5
(1

9',12879'
$&,1

',9B5
(1

9',12879'
9',1


Copyright 1996 by SIEMENS


Status: 10/96

page 11 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip
MOVR
MOVR
MOVR
MOVR
/R
MOVR
/R

VD3008,
VD3012,
VD3067,
VD3020,
AC0,
VD3016,
VD3067,

PID
VD3063
VD3067
VD3055
AC0
VD3055
VD3059
VD3059

Tip No. 32

// GAIN = raw_GAIN
// SAMPLE = raw_SAMPLE
// I_COEF = SAMPLE / RESET

// D_COEF = RATE / SAMPLE

.59'08/B5
 5127(1

9',12879'
9',1

08/B5
(1

9',12879'
9',1

LDR=
NOT
*R
*R

0.0,

VD3063

// If (GAIN <> 0.0)

VD3063,
VD3063,

VD3055
VD3059

// I_COEF = I_COEF * GAIN


// D_COEF = D_COEF * GAIN
// End if

999.
 6

9.
 5

9.
 5


 -03

LDN
A
S
R
R
JMP

V3000.0
V3030.0
V3030.7,
V3030.0,
V3001.0,
1

1
1
1

Copyright 1996 by SIEMENS


Status: 10/96

// If (control_byte.mode = MANUAL AND


// internal_status.mode = AUTO)
// internal_status.first_cycle = TRUE
// internal_status.mode = MANUAL
// status_byte.mode = MANUAL
// Endif

page 12 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

999.
 6

9.
 6

9.
 6

029B5
(1

9',12879'


029B:
(1

9:,12879:


LD
AN
S
S
S
MOVR
MOVW

V3000.0
V3030.0
V3030.7,
V3030.0,
V3001.0,
VD3039,
VW3002,

1
1
1
VD3047
VW3004

// Else If (control_byte.mode = AUTO AND


// internal_status.mode = MANUAL)
// internal_status.first_cycle = TRUE
// internal_status.mode = AUTO
// status_byte.mode = AUTO
// BIAS = OUTPUT
// raw_SP = raw_PV

/%/

609.
 5

LBL
LD
R

1
SM0.0
V3000.7,

// control_byte.update_values = FALSE

/%/

9:.029B5
! :(1

.5,12879'



 -03


Copyright 1996 by SIEMENS


Status: 10/96

page 13 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

LBL

LDW>=
MOVR
JMP

VW3002,
1.0,
10

// Scale the raw process variable value to generate the


// PV value used in the PID calculation.
// If (raw_pv > 32000)
// PV = 1.0

32000
VD3031

Tip No. 32

9:.029B5
 :(1

.5,12879'



 -03

LDW<=
MOVR
JMP

VW3002,
0.0,
10

0
VD3031

// Else if (raw_pv <= 0)


// PV = 0.0

6068%B',
(1

$&,1287$&
$&,1

029B:
(1

9:,1287$&


',B5($/
(1

$&,12879'


',9B5
(1

9',12879'
.5,1

LD
-D
MOVW
DTR
/R

SM0.0
AC1,
VW3002,
AC1,
32000.0,

// Else
AC1
AC1
VD3031
VD3031

Copyright 1996 by SIEMENS


Status: 10/96

//

PV = DTR(raw_pv)/32000.0

page 14 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

/%/

9:.029B5
! :(1

.5,12879'



 -03

LBL

10

LDW>=
MOVR
JMP

VW3004,
1.0,
20

32000
VD3035

// Scale the raw setpoint value to generate the


// SP value used in the PID calculation.
// If (raw_sp > 32000)
// SP = 1.0

9:.029B5
 :(1

.5,12879'



 -03

LDW<=
MOVR
JMP

VW3004,
0.0,
20

0
VD3035

// Else if (raw_sp <= 0)


// SP = 0.0

6068%B',
(1

$&,1287$&
$&,1

029B:
(1

9:,1287$&


',B5($/
(1

$&,12879'


',9B5
(1

9',12879'
.5,1


Copyright 1996 by SIEMENS


Status: 10/96

page 15 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip
LD
-D
MOVW
DTR
/R

SM0.0
AC1,
VW3004,
AC1,
32000.0,

PID

Tip No. 32

// Else
AC1
AC1
VD3035
VD3035

// SP = DTR(raw_sp)/32000.0

/%/

9
 -03

LBL
LDN
JMP

20
V3030.0
30

// Calculate error, if loop is in AUTO mode


// If (loop is in AUTO mode)

6068%B5
(1

9',12879'
9',1

LD
MOVR
-R

SM0.0
VD3035,
VD3031,

VD3043
VD3043

//

ERROR = SP - PV

/%/

9
 -03

LBL

30

LDN
JMP

V3030.0
40

Copyright 1996 by SIEMENS


Status: 10/96

// Calculate output value, if loop is in AUTO mode.


// In this section, the following definitions apply:
// AC1 = first contains term Mp, then Ma later
// AC2 = contains Mi
// AC3 = contains Md
// If (loop is in AUTO mode)

page 16 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

6008/B5
(1

9',1287$&
9',1

08/B5
(1

9',1287$&
9',1

$''B5
(1

9',1287$&
$&,1

029B5
(1

.5,1287$&


LD
MOVR
*R
MOVR
*R
+R
MOVR

SM0.0
VD3063,
VD3043,
VD3055,
VD3043,
VD3047,
0.0,

AC1
AC1
AC2
AC2
AC2
AC3

// Mp = GAIN * ERROR
// Mi = BIAS + (I_COEF * ERROR)

// Md = 0.0

.59'968%B5
 5127(1

9',1287$&
9',1

08/B5
(1

$&,1287$&
9',1

LDR=
NOT
AN
MOVR
-R
*R

0.0,

VD3059

V3030.7
VD3051,
VD3031,
VD3059,

AC3
AC3
AC3

Copyright 1996 by SIEMENS


Status: 10/96

// If (D_COEF <> 0.0 AND


//
//

not int_status.first_cycle)
Md = D_COEF * (PV_OLD - PV)

page 17 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

60029B5
(1

9',12879'


$''B5
(1

$&,1287$&
$&,1

$''B5
(1

$&,12879'
$&,1

LD
MOVR
+R
MOVR
+R

SM0.0
VD3031,
AC3,
AC1,
AC2,

VD3051
AC1
VD3039
VD3039

// PV_OLD = PV
// Ma = Mp + Md
// OUTPUT = Ma + Mi

9'.568%B5
 5127(1

.5,1287$&
$&,1

029B5
(1

.5,12879'



 -03

LDR<=
NOT
MOVR
-R
MOVR
JMP

VD3039,

1.0

//

If (OUTPUT > 1.0)

1.0,
AC1,
1.0,
41

AC2
AC2
VD3039

//

Mi = 1.0 - Ma

//

OUTPUT = 1.0

Copyright 1996 by SIEMENS


Status: 10/96

page 18 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

9:;25B':
(1

$&,1287$&
.+,1

029B5
(1

.5,12879'


LD
MOVR
XORD
MOVR

V3039.7
AC1,
AC2
16#80000000,
0.0,
VD3039

//
//

Else If (OUTPUT < 0.0)


Mi = -Ma

AC2
//

OUTPUT = 0.0

/%/

.59'
 5 -03

LBL
LDR=
JMP

41
0.0,
42

VD3055

//

If (I_COEF <> 0)

$&.5029B5
 5127(1

.5,1287$&



 -03

LDR<=
NOT
MOVR
JMP

AC2,

1.0

//

1.0,
43

AC2

//

If (Mi > 1.0)


Mi = 1.0

.+$&029B5
 '(1

$&.5.5,1287$&
! 5127


Copyright 1996 by SIEMENS


Status: 10/96

page 19 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip
LDD=
LDR>=
NOT
OLD
MOVR

PID

16#80000000,
AC2,
0.0

0.0,

AC2

AC2

//
//

//

Tip No. 32
Else If (Mi = -0.0) OR
(Mi < 0.0)

Mi = 0.0

/%/

60029B5
(1

$&,12879'


LBL
LD
MOVR

43
SM0.0
AC2,

VD3047

//
//

Endif
BIAS = Mi

/%/

/%/

609.
 5

LBL
LBL
LD
R

42
40
SM0.0
V3030.7,

// Endif
// Endif
1

// int_status.first_cycle = FALSE

6008/B5
(1

9',1287$&
.5,1

7581&
(1

$&,1287$&


029B:
(1

$&,12879:



 5(7,

Copyright 1996 by SIEMENS


Status: 10/96

page 20 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

S7-200 Tip

PID

Tip No. 32

//
Convert scaled output value back into signed integer value from 0 to 32000.
//
LD
SM0.0
// raw_output = TRUNC(OUTPUT * 32000.0)
MOVR
VD3039,
AC0
*R
32000.0,
AC0
TRUNC
AC0,
AC1
.
MOVW
AC1,
VW3006
RETI
// END INT 100

Conversion Notes
To Convert from IEC STL to S7-Micro/DOS STL:

z
z
z
z

Add a K before all non-Hex numerical constants (i.e. 4 K4)


Replace 16# with KH for all Hex constants (i.e. 16#FF KHFF)
Commas denote field divisions. Use arrow or TAB keys to toggle between fields.
To convert an S7-Micro/DOS STL program to LAD form, every network must begin
with the word NETWORK and a number. Each network in this Application Tip
program is designated by a number on the ladder diagram. Use the INSNW
command under the EDIT menu to enter a new network. The MEND, RET, RETI,
LBL, SBR, and INT commands each receive their own networks.
Line-Comments denoted by // are not possible with S7-Micro/DOS, but NetworkComments are possible.

General Notes
The SIMATIC S7-200 Application Tips are provided to give users of the S7-200 some indication
as to how, from the view of programming technique, certain tasks can be solved with this
controller. These instructions do not purport to cover all details or variations in equipment, nor do
they provide for every possible contingency. Use of the S7-200 Application Tips is free.
Siemens reserves the right to make changes in specifications shown herein or make
improvements at any time without notice or obligation. It does not relieve the user of
responsibility to use sound practices in application, installation, operation, and maintenance of
the equipment purchased. Should a conflict arise between the general information contained in
this publication, the contents of drawings or supplementary material, or both, the latter shall take
precedence.
Siemens is not liable, for whatever legal reason, for damages or personal injury resulting from
the use of the application tips.
All rights reserved. Any form of duplication or distribution, including excerpts, is only permitted
with express authorization by SIEMENS.

Copyright 1996 by SIEMENS


Status: 10/96

page 21 / 21

S72_32e.doc
Version 2.0

SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.

You might also like