PID Instruction Timing
The PID instruction and the sampling of the process variable need to be updated at a periodic rate. This update time is related to the physical process you are controlling. For very slow loops, such as temperature loops, an update time of once per second or even longer is usually sufficient to obtain good control. Somewhat faster loops, such as pressure or flow loops, may require an update time such as once every 250 ms. Only rare cases, such as tension control on an unwinder spool, require loop updates as fast as every 10 ms or faster.
Because the PID instruction uses a time base in its calculation, you need to synchronize execution of this instruction with sampling of the process variable (PV ).
The easiest way to execute the PID instruction is to put the PID instruction in a periodic task. Set the loop update time (.UPD) equal to the periodic task rate and make sure that the PID instruction is executed every scan of the periodic task.
The easiest way to execute the PID instruction is to put the PID instruction in a periodic task. Set the loop update time (.UPD) equal to the periodic task rate and make sure that the PID instruction is executed every scan of the periodic task.
Relay Ladder
TIP:
To avoid locking up the PID with invalid internal floating point values, ensure the PV is not INF or NAN before invoking the instruction such as:
XIC (PC_timer.DN)
MOV(Local:0:1.Ch0Data, Local:0:1.Ch0Data)
XIO(S:V)
PID(...)
Structured Text
PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data, Local:1:O.Ch4Data,0,Local:1:I.Ch4InHold, Local:1:I.Ch4Data);
When using a periodic task, make sure that the analog input used for the process variable is updated to the processor at a rate that is significantly faster than the rate of the periodic task. Ideally, the process variable should be sent to the processor at least five to 10 times faster than the periodic task rate. This minimizes the time difference between actual samples of the process variable and execution of the PID loop. For example, if the PID loop is in a 250 ms periodic task, use a loop update time of 250 ms (.UPD = .25), and configure the analog input module to produce data at least about every 25 to 50 ms.
Another, somewhat less accurate, method of executing a PID instruction is to place the instruction in a continuous task and use a timer done bit to trigger execution of the PID instruction.
Relay Ladder
TIP:
To avoid locking up the PID with invalid internal floating point values, ensure the PV is not INF or NAN before invoking the instruction such as:
XIC (PC_timer.DN)
MOV(Local:0:1.Ch0Data, Local:0:1.Ch0Data)
XIO(S:V)
PID(...)
Structured Text
PID_timer.pre := 1000
TONR(PID_timer);
IF PID_timer.DN THEN PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data,
Local:1:O.Ch0Data,0,Local:1:I.Ch0InHold,
Local:1:I.Ch0Data);
END_IF;
TIP:
To avoid locking up the PID with invalid internal floating point values, ensure the PV is not INF or NAN before invoking the instruction such as:
XIC (PC_timer.DN)
MOV(Local:0:1.Ch0Data, Local:0:1.Ch0Data)
XIO(S:V)
PID(...)
In this method, the loop update time of the PID instruction should be set equal to the timer preset. As in the case of using a periodic task, you should set the analog input module to produce the process variable at a significantly faster rate than the loop update time. You should only use the timer method of PID execution for loops with loop update times that are at least several times longer than the worst-case execution time for your continuous task.
The most accurate way to execute a PID instruction is to use the real time sampling (RTS) feature of the 1756 analog input modules. The analog input module samples its inputs at the real time sampling rate you configure when you set up the module. When the real time sample period of the module expires, it updates its inputs and updates a rolling timestamp (represented by the .RollingTimestamp member of the analog input data structure) produced by the module.
The timestamp ranges from 0 to 32,767 ms. Monitor the timestamp. When it changes, a new process variable sample has been received. Every time a timestamp changes, execute the PID instruction once. Because the process variable sample is driven by the analog input module, the input sample time is very accurate, and the loop update time used by the PID instruction should be set equal to the RTS time of the analog input module.
To make sure that you do not miss samples of the process variable, execute your logic at a rate faster than the RTS time. For example, if the RTS time is 250 ms, you could put the PID logic in a periodic task that runs every100 ms to make sure that you never miss a sample. You could even place the PID logic in a continuous task, as long as you make sure that the logic would be updated more frequently than once every 250 ms.
An example of the RTS method of execution is shown below. The execution of the PID instruction depends on receiving new analog input data. If the analog input module fails or is removed, the controller stops receiving rolling timestamps and the PID loop stops executing. You should monitor the status bit of the PV analog input and, if it shows bad status, force the loop into software manual mode, and execute the loop every scan. This lets the operator still manually change the output of the PID loop.
Relay Ladder
Structured Text
IF (Local:0:I.Ch0Fault) THEN TIC101.SWM [:=] 1;
ELSE TIC101.SWM := 0; END_IF;
IF (Local:0:I.RollingTimestamp<>PreviousTimestamp) OR (Local:0:I.Ch0Fault) THEN
PreviousTimestamp := Local:0:I.RollingTimestamp; PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data,
Local:1:O.Ch0Data,0,Local:1:I.Ch0InHold,
Local:1:I.Ch0Data);
END_IF;
Provide Feedback