Beruflich Dokumente
Kultur Dokumente
Technology instructions
9.1
Table 9- 1
High-speed counter
CTRL_HSC instruction
LAD / FBD
SCL
"CTRL_HSC_0_DB" (
hsc:=_hw_hsc_in_,
dir:=_bool_in_,
cv:=_bool_in_,
rv:=_bool_in_,
period:=_bool_in_,
new_dir:=_int_in_,
new_cv:=_int_in_,
new_rv:=_dint_in_,
new_period:=_int_in_,
busy:=_bool_out_,
status:=_word_out_);
Description
Each CTRL_HSC instruction uses a structure stored in
a DB to maintain data. You assign the DB when the
CTRL_HSC instruction is placed in the editor.
Table 9- 2
Data type
Description
IN
HW_HSC
HSC identifier
DIR1, 2
IN
Bool
CV1
IN
Bool
RV1
IN
Bool
PERIOD1
IN
Bool
NEW_DIR
IN
Int
NEW_CV
IN
DInt
NEW_RV
IN
DInt
NEW_PERIOD
IN
Int
BUSY3
OUT
Bool
Function is busy
STATUS
OUT
Word
If an update of a parameter value is not requested, then the corresponding input values are ignored.
The DIR parameter is only valid if the configured counting direction is set to "User program (internal direction control)".
You determine how to use this parameter in the HSC device configuration.
For an HSC on the CPU or on the SB, the BUSY parameter always has a value of 0.
337
Technology instructions
9.1 High-speed counter
You configure the parameters for each HSC in the device configuration for the CPU:
counting mode, I/O connections, interrupt assignment, and operation as a high-speed
counter or as a device to measure pulse frequency.
Some of the parameters for the HSC can be modified by your user program to provide
program control of the counting process:
Set the counting direction to a NEW_DIR value
Set the current count value to a NEW_CV value
Set the reference value to a NEW_RV value
Set the period value (for frequency measurement mode) to a NEW_PERIOD value
If the following Boolean flag values are set to 1 when the CTRL_HSC instruction is executed,
the corresponding NEW_xxx value is loaded to the counter. Multiple requests (more than
one flag is set at the same time) are processed in a single execution of the CTRL_HSC
instruction.
DIR = 1 is a request to load a NEW_DIR value, 0 = no change
CV = 1 is a request to load a NEW_CV value, 0 = no change
RV = 1 is a request to load a NEW_RV value, 0 = no change
PERIOD = 1 is a request to load a NEW_PERIOD value, 0 = no change
The CTRL_HSC instruction is typically placed in a hardware interrupt OB that is executed
when the counter hardware interrupt event is triggered. For example, if a CV=RV event
triggers the counter interrupt, then a hardware interrupt OB code block executes the
CTRL_HSC instruction and can change the reference value by loading a NEW_RV value.
The current count value is not available in the CTRL_HSC parameters. The process image
address that stores the current count value is assigned during the hardware configuration of
the high-speed counter. You may use program logic to directly read the count value. The
value returned to your program will be a correct count for the instant in which the counter
was read. The counter will continue to count high-speed events. Therefore, the actual count
value could change before your program completes a process using an old count value.
Condition codes: In the case of an error, ENO is set to 0, and the STATUS output contains a
condition code.
Table 9- 3
STATUS
0
Description
No error
80A1
80B1
80B2
80B3
80B4
80C0
80D0
338
Technology instructions
9.1 High-speed counter
9.1.1
Table 9- 4
HSC
HSC1
HSC2
Single phase
CPU
100 KHz
80 KHz
High-speed SB
200 KHz
160 KHz
SB
30 KHz
20 KHz
CPU
100 KHz
80 KHz
High-speed SB
200 KHz
160 KHz
SB
30 KHz
20 KHz
HSC3
CPU
100 KHz
80 KHz
HSC4
CPU
30 KHz
20 KHz
HSC5
CPU
30 KHz
20 KHz
High-speed SB
200 KHz
160 KHz
SB
30 KHz
20 KHz
CPU
30 KHz
20 KHz
High-speed SB
200 KHz
160 KHz
SB
30 KHz
20 KHz
HSC6
339
Technology instructions
9.1 High-speed counter
Type
Input 1
Input 2
Input 3
Function
Clock
(Optional:
direction)
Count or frequency
Reset
Count
Clock
Direction
Count or frequency
Reset
Count
Clock up
Count or frequency
Reset
Count
Phase A
Count or frequency
Reset1
Count
Clock down
Phase B
340
Technology instructions
9.1 High-speed counter
HSC
HSC 1 1
1-phase
[d]
[R]
[d]
[R]
2-phase
CU
CD
[R]
CU
CD
[R]
[R]
AB-phase
HSC 2 1
HSC 3
HSC 5
[R]
1-phase
[R]
[d]
[R]
[d]
2-phase
[R]
CU
CD
[R]
CU
CD
AB-phase
[R]
[R]
1-phase
[d]
2-phase
CU
CD
AB-phase
2
1-phase
[d]
[R]
2-phase
CU
CD
[R]
[R]
AB-phase
S7-1200 Programmable controller
System Manual, 04/2012, A5E02486680-06
341
Technology instructions
9.1 High-speed counter
HSC
HSC 6 2
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
HSC 1 and HSC 2 can be configured for either the on-board inputs or for an SB.
HSC 5 and HSC 6 are available only with an SB. HSC 6 is available only with a 4-input SB.
An SB with only 2 digital inputs provides only the 4.0 and 4.1 inputs.
The following table shows the HSC input assignments for both the on-board I/O of the CPU
1212C and an SB. (If the SB has only 2 inputs, only 4.0 and 4.1 inputs are available.)
For single-phase: C is the Clock input, [d] is the optional direction input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
For two-phase: CU is the Clock Up input, CD is the Clock Down input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
For AB-phase quadrature: A is the Clock A input, B is the Clock B input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
Table 9- 7
HSC
HSC 1
HSC 3
HSC 5
[d]
[R]
[d]
[R]
CU
CD
[R]
CU
CD
[R]
[R]
[R]
1-phase
[R]
[d]
[R]
[d]
2-phase
[R]
CU
CD
[R]
CU
CD
AB-phase
[R]
[R]
1-phase
[d]
[R]
2-phase
CU
CD
[R]
[R]
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
1-phase
[d]
2-phase
CU
CD
[R]
[R]
AB-phase
HSC 6 2
2-phase
AB-phase
HSC 4
1-phase
AB-phase
HSC 2 1
SB input (4.x) 3
[R]
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
HSC 1 and HSC 2 can be configured for either the on-board inputs or for an SB.
HSC 5 and HSC 6 are available only with an SB. HSC 6 is available only with a 4-input SB.
An SB with only 2 digital inputs provides only the 4.0 and 4.1 inputs.
342
Technology instructions
9.1 High-speed counter
The following two tables show the HSC input assignments for the on-board I/O of the CPU
1214C and for an optional SB, if installed.
For single-phase: C is the Clock input, [d] is the optional direction input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
For two-phase: CU is the Clock Up input, CD is the Clock Down input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
For AB-phase quadrature: A is the Clock A input, B is the Clock B input, and [R] is an
optional external reset input. (Reset is available only for "Counting" mode.)
Table 9- 8
HSC input assignments for CPU 1214C and CPU 1215C (on-board inputs only)
HSC
HSC
1-phase
[d]
[R]
2-phase
CU
CD
[R]
[R]
1-phase
[d]
[R]
2-phase
CU
CD
[R]
1-phase
[R]
C
[d]
[R]
2-phase
CU
CD
[R]
[R]
AB-phase
HSC
21
HSC 3
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
HSC 51
1-phase
[d]
[R]
2-phase
CU
CD
[R]
[R]
AB-phase
HSC 4
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
AB-phase
HSC 61
AB-phase
1
HSC 1, HSC 2, HSC 5 and HSC 6 can be configured for either the on-board inputs or for an SB.
Table 9- 9
HSC 1
HSC 1
1-phase
[d]
[R]
2-phase
CU
CD
[R]
[R]
AB-phase
HSC 2
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
343
Technology instructions
9.1 High-speed counter
HSC 1
HSC 5
1-phase
[d]
[R]
2-phase
CU
CD
[R]
AB-phase
HSC 6
[R]
1-phase
[R]
[d]
2-phase
[R]
CU
CD
AB-phase
[R]
For CPU 1214C: HSC 1, HSC 2, HSC 5 and HSC 6 can be configured for either the on-board
inputs or for an SB.
An SB with only 2 digital inputs provides only the 4.0 and 4.1 inputs.
HSC
Data type
Default address
HSC1
DInt
ID1000
HSC2
DInt
ID1004
HSC3
DInt
ID1008
HSC4
DInt
ID1012
HSC5
DInt
ID1016
HSC6
DInt
ID1020
344
Technology instructions
9.1 High-speed counter
9.1.2
Note
When you enable the high speed counter and select input points for it, the input filter settings
for these points are configured to 800 ns. Each input point has a single filter configuration
that applies to all uses: process inputs, interrupts, pulse catch, and HSC inputs.
WARNING
If the filter time for a digital input channel is changed from a previous setting, a new "0"
level input value may need to be presented for up to 20.0 ms accumulated duration before
the filter becomes fully responsive to new inputs. During this time, short "0" pulse events of
duration less than 20.0 ms may not be detected or counted.
This changing of filter times can result in unexpected machine or process operation, which
may cause death or serious injury to personnel, and/or damage to equipment.
To ensure that a new filter time goes immediately into effect, a power cycle of the CPU
must be applied.
345
Technology instructions
9.2 PID control
After enabling the HSC, configure the other parameters, such as counter function, initial
values, reset options and interrupt events.
For information about configuring the HSC, refer to the section on configuring the CPU
(Page 123).
9.2
PID control
STEP 7 provides the following PID instructions for the S7-1200 CPU:
The PID_Compact instruction is used to control technical processes with continuous
input- and output variables.
The PID_3Step instruction is used to control motor-actuated devices, such as valves that
require discrete signals for open- and close actuation.
Note
Changes that you make to the PID configuration and download in RUN mode do not take
effect until the CPU transitions from STOP to RUN mode.
Both PID instructions (PID_3Step and PID_Compact) can calculate the P-, I-, and Dcomponents during startup (if configured for "pretuning"). You can also configure the
instruction for "fine tuning" to allow you to optimize the parameters. You do not need to
manually determine the parameters.
Note
Execute the PID instruction at constant intervals of the sampling time (preferably in a cyclic
OB).
Because the PID loop needs a certain time to respond to changes of the control value, do
not calculate the output value in every cycle. Do not execute the PID instruction in the main
program cycle OB (such as OB 1).
The sampling time of the PID algorithm represents the time between two calculations of the
output value (control value). The output value is calculated during self-tuning and rounded to
a multiple of the cycle time. All other functions of PID instruction are executed at every call.
346