Entry type: FAQ, Entry ID: 41995947, Entry date: 02/20/2012
(5)
Rate

How in STEP 7 V11 do you save the value of an "HSC" (high-speed counter) for the S7-1200 after STOP mode or after a restart?

  • Entry
  • Associated product(s)

Instructions
With the "Control high-speed counters" [CTRL_HSC] operation you can call and parameterize the high-speed counters supported by the CPU in your program. These high-speed counters are used to count the pulses generated by a rotary transducer, for example.

After changing from STOP to RUN mode or after switching the power supply off and on again, the high-speed counters "HSC" are reinitialized and the counters are reset to zero. The table below explains how to proceed to retain or save the values of the high-speed counters after a CPU STOP.
 

No. Procedure
1 To execute the "Control high-speed counters" [CTRL_HSC] operation, you must enable the high-speed counters "HSC" in the device configuration.
  1. In the project navigation, open the device configuration in the mark the "PLC_1..." folder.
  2. In the device configuration, open the "Properties" of the CPU and open the "High-speed counters (HSC)" folder in the area navigation. The properties of the high-speed counters are displayed in the right window.
  3. To enable the high-speed counter "(HSC)1", you activate the "Enable this high-speed counter for use" option.
  4. For the high-speed counter (Name: "HSC_1") you define the functions as shown in the example in Fig 01.


Fig. 01

2 Create a global data block with the symbolic name "DB HSC retain", for example, and define the variable "HSC_1" of data type "DInt" in the DB. The counter value is saved in this DB variable.


Fig. 02

Note
The current counter value is not provided for in the parameters for the "Control high-speed counters" [CTRL_HSC] operation. The address for the process image is assigned to the high-speed counter in the hardware configuration and includes the current counter value. You can read out the counter value directly via the program logic. The value output in your program is a correct counter value for the moment in which the counter was read. The counter continues counting high-speed results. The actual counter value can therefore change before your program has completed a process with an old counter value.

3 Create a time interrupt OB (OB201) with a cycle time of 10 ms, for example, and insert the "MOVE" instruction in Network 1.
  1. Parameterize the input parameter of the "MOVE" instruction with the initial address of the high-speed counter "HSC_1" and define a symbolic variable for this ("HSC1_CV", for example). The initial address for the high-speed counter HSC_1 is ED1000 by default.
  2. Parameterize the output parameter with the DB variable "DB HSC retain.HSC_1".

When the program is executed, the counter value of the high-speed counter "HSC_1" is transferred to the DB variable every 10 ms.


Fig. 03

4
  1. Create a start OB (OB100) and insert the "MOVE" instruction in Network 1.
  2. Parameterize the input parameter of the "MOVE" instruction with the DB variable "DB HSC retain.HSC_1" and the output parameter with the defined variable "NEW_CV1" (MD24). The "NEW_CV1" variable is also assigned to the "NEW_CV" parameter of the "Control high-speed counters" [CTRL_HSC] operation.
  3. Now do a restart. The counter value in the DB variable is transferred as start value to the "NEW_CV1" variable with which the high-speed counter begins to count again.
5 To enable the counter value, insert the "Set output" [S] instruction in another network and parameterize the operands with the defined variable "CV1" (M10.1).


Fig. 04

6 Now, call the "Control high-speed counters" [CTRL_HSC] operation in a block (OB1, for example) and parameterize the input and output parameters. Once the current counter value has been enabled with the variable "CV1" (M10.1), the parameter "CV" is reset again. Insert the "Reset output" [R] instruction in another network and parameterize the operands with the variable "CV1" (M10.1).


Fig. 05

7 Compile your program by right-clicking on the "PLC_1..." folder in the project navigation and executing the menu command "Compile > All" from the pop-up menu. Then save your project.

More information is available in the STEP 7 (TIA Portal) V11 Online Help under "CRTL_HSC: Control high-speed counters (S7-1200)".

Creation environment
The screens in this FAQ response were created with STEP 7 (TIA Portal) V11.