How in STEP 7 (TIA Portal) do you save the value of an "HSC" (high-speed counter) for the S7-1200 after STOP mode or after a restart?
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 example below shows how to proceed to retain or save the values of the high-speed counters after a CPU STOP.
- To be able to execute the "Control high-speed counters" [CTRL_HSC] operation you must enable the high-speed counters in the device configuration. In the project navigation you right-click the "PLC_1[CPU...]" folder and in the pop-up menu you open "Properties...".
- In the "General" tab you open the "High-speed counters (HSC)" folder and click "HSC1". The properties of the high-speed counter "HSC1" are displayed in the right window.
- Enable the option "Enable this high-speed counter", to enable High Speed Counter 1.
- Define the functions for the high-speed counter "HSC_1" (Fig. 1) and close the dialog with OK.
- Create a global data block and define the DB variable as shown in Fig. 2.
In this example we have assigned the symbolic name "DBHSCretain" for the DB.
The current counter value for the "Control high-speed counters" [CTRL_HSC] operation is not provided for in the parameters. 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 actual counter value can therefore change before your program has completed a process with an old counter value.
- Create the cyclic interrupt OB entitled "Cyclic interrupt" with a cycle time of 100 ms, for example, and insert the "MOVE" instruction in Network 1.
The runtime of a cyclic interrupt OB must be significantly shorter than its time interval. Otherwise the time interval of the cyclic interrupt might expire before the that cyclic interrupt is processed.
- 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 ED1000 for the high-speed counter HSC_1 is in the CPU properties under "Overview of addresses" (Fig. 3).
- Parameterize the output parameter with the DB variable "DBHSCretain.HSC_1". When the program is executed, the counter value of the high-speed counter "HSC_1" is transferred to the DB variable every 100 ms.
Create the start OB "Startup" and insert the "MOVE" instruction in Network 1.
Parameterize the input parameter of the "MOVE" instruction with the DB variable "DB HSCretain.HSC_1" and the output parameter with the defined variable "DBHSCretain.NEW_CV1". When you do a restart the counter value in the DB variable is transferred as initial value to the variable "DBHSCretain.NEW_CV1" and used by the high-speed counter to start counting again.
To enable the counter value, insert the "Set output" [S] instruction in another network and parameterize the operands with the defined variable "DBHSCretain.CV1".
Now call the instruction "Control high-speed counters" [CTRL_HSC] in the block "Main [OB1]". The "CTRL_HSC" instruction is to be found in the instructions palette under "Technology > Count".
Parameterize the "HSC" parameter with the system constant of the hardware ID (HW ID). For this you open the dialog "Show all variables" and select the "System constants" tab.
If you split the editor area and have both the "Main [OB1]" dialog and the "System constants" dialog next to each other on the screen, you can drag-and-drop the constant "Local~HSC_1" to the parameter "HSC".
Parameterize the inputs of the "CTRL_HSC" instruction with the DB variables and define the two variables for the output parameters (Fig. 5).
Insert the "Reset output" [R] instruction in another network and parameterize the operands with the variable "DBHSCretain.CV1". Once the current counter value has been enabled with the variable "DBHSCretain.CV1", the parameter "CV" has to be reset again.
Save and compile the project and download the station into the CPU.
More information is also available in the STEP 7 (TIA Portal) Online Help by marking the "CTRL_HSC" instruction and pressing the "F1" button.
The screens in this FAQ response were created with STEP 7 (TIA Portal) V13 SP1.
- You have a technical question / problem: Ask the Technical Support
- You want to discuss in our forum and exchange experiences with other users
- You want to create CAx data for one or more products
- You would like to send us feedback on this Entry