Description
You can use the "Lead and lag algorithm" instruction to process signals with an analog tag. The gain value at the GAIN parameter must be greater than zero. The result of the instruction "Lead and lag algorithm" is calculated using the following equation:
The "Lead and lag algorithm" instruction supplies plausible results only when processing is in fixed program cycles. The same units must be specified for the LD_TIME, LG_TIME, and SAMPLE_T parameters. At LG_TIME > 4 + SAMPLE_T, the instruction approaches the following function:
OUT = GAIN * ((1 + LD_TIME * s) / (1 + LG_TIME * s)) * IN
When the value of the GAIN parameter is less than or equal to zero, the calculation is not performed and an error information is output on the ERR_CODE parameter.
You can use the instruction "Lead and lag algorithm" in conjunction with loops as a compensator in dynamic feed-forward control. The instruction consists of two operations. The "Lead" operation shifts the phase of the OUT output so that the output leads the input. The "Lag" operation, on the other hand, shifts the output so that the output lags behind the input. Because the "Lag" operation is equivalent to an integration, it can be used as a noise suppressor or as a low-pass filter. The "Lead" operation is equivalent to a differentiation and can therefore be used as a high-pass filter. The two instructions together (Lead and Lag) result in the output phase lagging behind the the input at lower frequencies and leading it at higher frequencies. This means that the "Lead and lag algorithm" instruction can be used as a band pass filter.
Parameters
The following table shows the parameters of the "Lead and lag algorithm" instruction:
|
Parameter |
Declaration |
Data type |
Memory area |
Description |
|---|---|---|---|---|
|
EN |
Input |
BOOL |
I, Q, M, D, L, T, C or constant |
Enable input |
|
ENO |
Output |
BOOL |
I, Q, M, D, L |
Enable output |
|
IN |
Input |
REAL |
I, Q, M, D, L, P or constant |
The input value of the current sample time (cycle time) to be processed. |
|
SAMPLE_T |
Input |
INT |
I, Q, M, D, L, P or constant |
Sample time |
|
OUT |
Output |
REAL |
I, Q, M, D, L, P |
Result of the instruction |
|
ERR_CODE |
Output |
WORD |
I, Q, M, D, L, P |
Error information |
|
LD_TIME |
Static |
REAL |
I, Q, M, D, L, P or constant |
Lead time in the same unit as sample time. |
|
LG_TIME |
Static |
REAL |
I, Q, M, D, L, P or constant |
Lag time in the same unit as sample time |
|
GAIN |
Static |
REAL |
I, Q, M, D, L, P or constant |
Gain as % / % (the ratio of the change in output to a change in input as a steady state). |
|
PREV_IN |
Static |
REAL |
I, Q, M, D, L, P or constant |
Previous input |
|
PREV_OUT |
Static |
REAL |
I, Q, M, D, L, P or constant |
Previous output |
ERR_CODE parameter
The following table shows the meaning of the values of the ERR_CODE parameter:
|
Error code* |
Explanation |
|---|---|
|
0000 |
No error |
|
0009 |
The value at the GAIN parameter is less than or equal to zero. |
|
*The error codes can be displayed as integer or hexadecimal value in the program editor. You can find information on switching the display formats under "See also". |
|
Example
The following example shows how the instruction works:
|
Note You can initialize static parameters in the data block. |
The following tables show how the instruction works using specific values.
Before processing
In this example the following values are used for the input parameters:
|
Parameters |
Operand |
Value |
|---|---|---|
|
IN |
Tag_Input |
2.0 |
|
SAMPLE_T |
Tag_InputSampleTime |
10 |
The following values are saved in the "LEAD_LAG_DB" instance data block of the instruction:
|
Parameters |
Address |
Value |
|---|---|---|
|
LD_TIME |
DBD12 |
2.0 |
|
LG_TIME |
DBD16 |
2.0 |
|
GAIN |
DBD20 |
1.0 |
|
PREV_IN |
DBD24 |
6.0 |
|
PREV_OUT |
DBD28 |
6.0 |
After processing
The following values are written to the output parameters after the instruction has been executed:
|
Parameters |
Operand |
Value |
|---|---|---|
|
OUT |
Tag_Output_Result |
2.0 |
The following values are saved in the instance data block "LEAD_LAD_DB" of the instruction:
|
Parameters |
Operand |
Value |
|---|---|---|
|
PREV_IN |
DBD24 |
2.0 |
|
PREV_OUT |
DBD28 |
2.0 |