发布于 2004-09-04 18:04:32
0楼
//
//PROGRAM COMMENTS
//Press F1 for help and example program
//
NETWORK 1 //NETWORK TITLE (single line)
//
//NETWORK COMMENTS
//
LD SM0.1
CALL pid_initial
//
//SUBROUTINE COMMENTS
//Press F1 for help and example program
//
NETWORK 1 //NETWORK TITLE (single line)
//
//NETWORK COMMENTS
//
NETWORK 1 //Instruction Wizard PID (See Properties for more details).
//PID Initialization and control.
//This subroutine initializes the variables used by the PID control logic and starts the PID Interrupt "pid_interrupt".
//routine. The PID interrupt routine is called cyclically based on the PID sample time. For
//a complete des cription of the PID instruction see the S7-200 System Manual.
//Note:
//When the PID is in manual mode the output should be controlled by writing a normalized value
//(0.00 to 1.00) to the PID Output instead of changing the output directly. This will automatically
//provide a bumpless transfer when the PID is returned to automatic mode.
LDN SM0.1
JMP 0
PID VB0, 0
NOT
MOVW +0, VW54 //initialize PID interrupt counter
MOVB 100, SMB34 //Load time for PID interrupt routine
ATCH pid_interrupt, 10 //Set up an interrupt to invoke PID execution
ENI
NETWORK 2
LBL 0
NETWORK 1 //Instruction Wizard PID (See Properties for more details).
//Increment number of times routine is called
LD SM0.0
INCW VW54
NETWORK 2
LDW>= VW54, +10 //Check if time to do PID calculation
MOVW +0, VW54 //if so, clear the counter and continue
NOT
JMP 0 //otherwise, jump to the end of the interrupt routine
NETWORK 3 //Compute the normalized value and load it into the PID PV location
LD SM0.0 //Always
LPS
XORW VW68, VW68 //Clear the working area.
MOVW AIW0, VW70 //read the analog value
A V70.7 //Check the sign bit.
MOVW 16#FFFF, VW68 //Extend the sign.
LRD
DTR VD68, VD68 //and convert it to a real number and load it in the PV
LRD
/R 32000.0, VD68
LPP
MOVR VD68, VD0
NETWORK 4
LD SM0.0 //Always
MOVR VD4, VD4
NETWORK 5 //Clamp the value to a maximum of 1.0.
LDR>= 1.0, VD0
NOT
MOVR 1.0, VD0
NETWORK 6 //Clamp the value to a minimum of 0.0.
LDR<= 0.0, VD0
NOT
MOVR 0.0, VD0
NETWORK 7 //Perform PID calculation
LD SM0.0 //Always
PID VB0, 0 //then perform PID calculation
NETWORK 8 //Scale the PID output and transfer it to the analog output
LD SM0.0 //Always
MOVR VD8, VD68 //load the PID output to workspace
*R 32000.0, VD68 //scale the value
TRUNC VD68, VD68 //convert the value to an integer
MOVW VW70, AQW0 //and transfer it to the analog output
NETWORK 9
LBL 0
//
//DATA BLOCK COMMENTS
//
//Press F1 for help and example data block
//
//
//The following were generated by the S7-200 Instruction Wizard, PID Formula.
//Parameter Table for PID 0.
//
VD0 0.0 //Process Variable
VD4 0.28 //Loop Setpoint
VD8 0.0 //Calculated Loop Output
VD12 2.0 //Loop Gain
VD16 1.0 //Sample Time
VD20 2.0 //Integral Time
VD24 1.0 //Derivative Time
VD28 0.6 //Integral Sum or Bias
VD32 0.0 //Value of Process Variable stored from last execution.
庄生晓梦迷蝴蝶,望帝春心托杜鹃。