laitimes

S7-1200 high-speed counter use details (2)

author:A sprouted potato

Other features

The high-speed counter also supports other features, including:

  • Door function
  • Synchronization function
  • Capture function
  • Compare features
  • Event configuration
  • Variable modification

Door function

Many apps need to turn the counter on or off depending on other events. When this happens, the counting is turned on or off via the internal department function. Each high-speed counter channel has two gates: a software gate and a hardware gate. The status of these doors will determine the status of the interior sector, as shown in Table 6.

S7-1200 high-speed counter use details (2)

Table 6. Internal Department Status

If the hardware door is open or has not been configured, and the software door is open or has not been written CTRL_HSC_EXT instructions, the interior door is open. If the internal sector is open, the count begins. If the internal sector is down, the counting pulse is ignored and the counting stops. This is shown in Figure 21.

S7-1200 high-speed counter use details (2)

Figure 21. Internal Sector with Counter Value

The hardware gate configuration, as shown in Figure 22.

S7-1200 high-speed counter use details (2)

Figure 22. Hardware gate configuration

Software gate programming

When using the CTRL_HSC_EXT command, a new variable with data type HSC_Count, HSC_Frequency, or HSC_Period needs to be connected to the CTRL interface of the instruction according to the measurement type, and the software gate is the EnHSC in that variable, as shown in Figure 23, which is the EnHSC of HSC_Count. Refer to Figures 14 and 18 for EnHSCs for HSC_Frequency and HSC_Period.

S7-1200 high-speed counter use details (2)

Figure 23. Software Gate

Note: The hardware gate function can only be used when configuring the HSC in counting mode. In the Cycle and Frequency modes, the state of the interior door is the same as that of the software gate.

The software gate function is only valid when the CTRL_HSC_EXT command is used, and when the command is not used, the software gate is open.

Synchronization function

The synchronization function sets the counter to a starting value via an external input signal. You can change the starting value by executing the CTRL_HSC_EXT command. In this way, the user can synchronize the current count value with the starting value via an external input signal, as shown in Figure 24. This function is only used in count mode. Note: Even if the inner door is not open, it will be the same

S7-1200 high-speed counter use details (2)

Figure 24. Example of synchronization

Hardware configuration, as shown in Figure 25.

S7-1200 high-speed counter use details (2)

Figure 25. Synchronous input configuration

For the software part, there are two cases:

1. Don't invoke CTRL_HSC_EXT directives

At this time, the synchronization signal level meets the configuration conditions, and the count value will be modified to 0, which is the initial count value, but the initial count value cannot be modified.

2. Invoke the CTRL_HSC_EXT directive

You need to create a new variable with data type HSC_Count to connect to the CTRL interface of the command, and the enable EnSync of the synchronization input needs to be set, and then when the synchronization signal level meets the configuration conditions, the synchronization function can be realized, and the count value will be modified to the initial count value, which is 0 by default. The variables are shown in Figure 26.

S7-1200 high-speed counter use details (2)

Figure 26. Synchronous enable signal

If you need to modify the initial count value, you can use CTRL_HSC_EXT to assign a new initial count value to the variable NewStartValue by pinning the variable EN_SV, that is, the initial count value is modified. This synchronizes the count value to the new initial count value, as shown in Figure 27.

S7-1200 high-speed counter use details (2)

Figure 27. Modify the initial value

Note: The value of the first count after CPU boot is the "Initial Counter Value" in the configuration page, as shown in the red box above Figure 5. This Initial Counter Value is only used at this time and is not related to the synchronization function.

Capture function

The capture function can be used to save the current count value by means of an external input signal. This can only be achieved by executing CTRL_HSC_EXT instructions.

This function is only used in count mode.

Figure 28 shows an example of a configuration snap function snapping on a rising edge.

S7-1200 high-speed counter use details (2)

Figure 28. Capture examples

Capture the external input configuration, as shown in Figure 29.

S7-1200 high-speed counter use details (2)
S7-1200 high-speed counter use details (2)

Figure 29. Capture input configuration

When using the CTRL_HSC_EXT command, you need to create a new data type of HSC_Count according to the measurement type connected to the CTRL interface of the command, the enable EnCapture of the capture input needs to be set, and then when the capture signal level meets the configuration conditions, the current count value is captured to the variable CapturedCount to achieve the capture function, as shown in Figure 30.

S7-1200 high-speed counter use details (2)

Figure 30. Snap bits and snap values

Note: The CTRL_HSC_EXT command must be invoked to get the snap count value, and the snapping function will still work after the internal department is turned off. The input point function is only available when configuring the HSC in counting mode.

Compare features

Enabling the Compare output value function generates a configurable pulse that occurs each time a configurable event occurs. If another configured event occurs while the output pulse is being performed, the event does not produce a new pulse. An example of the comparison feature is shown in Figure 31.

S7-1200 high-speed counter use details (2)

Figure 31. Compare feature examples

Compare the function reference value configuration, as shown in Figure 32.

S7-1200 high-speed counter use details (2)

Figure 32. Reference value configuration

Compare the output configuration, as shown in Figure 33.

S7-1200 high-speed counter use details (2)

Figure 33. Compare the outputs

Note: In addition to changing the configuration, you can also change the reference count value through the CTRL_HSC (only reference value 1) and CTRL_HSC_EXT commands, and if you need to change the reference count from reference count 1 to reference count 2, you can only change it through the configuration. The output function can only be used when configuring the counting mode

Event configuration

If you need to react quickly in certain situations with a high-speed counter, you can use the event function of the high-speed counter, which will trigger the corresponding hardware interrupt, and write the relevant process program in the hardware interrupt to achieve a quick response.

The S7-1200 high-speed counter supports three types of events:

  • Count value equal to reference value 1 (count mode only supported)
  • Synchronizing events (only count mode is supported)
  • Direction signal change (only external direction signal in single-phase mode is supported)

The configuration page is shown in Figure 34.

S7-1200 high-speed counter use details (2)

Figure 34. Event configuration

Modify the parameters

If you want to modify the parameters of the high-speed counter, such as modifying the current counting value, you must use the command, CTRL_HSC_EXT the parameters supported by the CTRL_HSC command are different, see Table 7 for details.

S7-1200 high-speed counter use details (2)

Table 7. Parameter modification comparison

For CTRL_HSC commands, it is relatively simple to modify the parameters, and you can control them directly at the command input. Each parameter has two parameters, a value and a control bit, and the parameter value can be modified, and then the relevant parameters can be modified for the control position bit.

As shown in Table 8, the first four parameters are the control bits, and the last four parameters are the corresponding parameter values for the first four. For example, if you modify the count value, you only need to assign the desired modified count value to NEW_CV, and then set the CV to complete the modification, but note that if the CV is always high, the count value will remain the modified count value and cannot be counted, so the control bit is usually triggered along the instruction.

S7-1200 high-speed counter use details (2)

Table 8. CTRL_HSC command to modify the parameters

For the CTRL_HSC_EXT command, you need to create a new variable with data type HSC_Count, HSC_Frequency, or HSC_Period according to the measurement type to connect to the CTRL interface of the directive, and the parameters to be modified are in these three variables.

HSC_Frequency and HSC_Period can only modify the frequency update cycle, as shown in Figure 35. Assign a new frequency update period in the NewPeriod, and then set the EnPeriod to complete the modification, as described above, usually using the EnPeriod bit triggered along the directive.

Note: This value can only be modified to 1000 (for 1000ms), 100 (for 100ms), 10 (for 10ms).

S7-1200 high-speed counter use details (2)

Figure 35. Modify the frequency update period

For HSC_Count, there are many parameters that can be modified, as detailed in Table 9. The idea is the same as the NewPeriod above, modify the variable at the parameter value, and then set the relevant control bits, usually using the along the command to trigger the control bits.

S7-1200 high-speed counter use details (2)

Table 9. Modify the HSC_Count parameter