Share this

Accelerate production cycles and achieve faster delivery: High-speed comparison output function gives you a helping hand.

2026-04-06 04:20:32 · · #1

The comparison output function based on a high-speed counter can open/close the output port for a specified time or output a specified level signal after the count value reaches a set value. The advantage of the high-speed comparison output function is that the response is much faster than that of ordinary output, which can quickly meet the application scenarios with higher real-time requirements, such as aerial photography technology.

This article uses the Leadshine medium-sized PLC MC532 controller (LC and SC series are used similarly) as an example to introduce the usage of the comparison output function.

Firmware version: 20230801 and above

FPGA version: 16777216 and above

Library versions: MC_HSIO 1.0.2.3, LS_BasicModule 1.0.0.5 and above

01. Compare output hardware port configurations

① Double-click High_Speed_IO_Module to open the IO configuration interface;

② Click on high-speed input settings;

③ Select the counter and check "Enable";

④ Select the hardware port for the comparison output signal. OUT0-OUT11 can be used as the comparison output ports. As shown in Figure 1.

Note: The purpose of using a counter is to use the counter value as a comparison reference position.

Figure 1. Counter Comparison Output Function Configuration Steps

02. Introduction to Comparison Output Commands

The comparison output instructions are shown in Table 1. The MC500 has a total of 3 comparison output instructions. Only one comparison output instruction can be used at a time. If multiple comparison output instructions are executed, only the first instruction executed is valid, and the subsequent instructions will report an error.

Table 1 Comparison Output Instruction Table

Before using these commands, the corresponding hardware port functions and parameters must be configured in High_Speed_IO_Module, and the use of system-specific addresses %MW50000-%MW59999 should be avoided to prevent functional abnormalities due to address conflicts.

The output state of the high-speed compare output port is controlled by the hardware layer. The software layer does not monitor this bit state and it is not reflected in the output port mapping address (consistent with the high-speed pulse output). In other words, the compare output instruction controls OUT2 to output a high level. In software monitoring, the value of the mapping address %QX0.2 corresponding to OUT2 will not become TRUE.

▇ 2.1 Single-point mode high-speed comparison instruction LS_Compare

This command is used to set parameters for the high-speed one-dimensional comparison output in single-point mode. It allows you to turn the output port on/off for a specified time when the count value equals the comparison value. Turning the output port on indicates a high-level output; turning the output port off indicates a low-level output, i.e., no output.

Input variable description

Output variable description

As shown in Figure 2, the LS_Compare instruction sets the comparison value of counter 0 to 10000. When the comparison values ​​are equal, the comparison output port is opened for 2 seconds. Figure 3 shows the relationship curve between the count value, output port level and time when this instruction is executed.

Figure 2 LS_Compare command

Figure 3. Relationship curves between count value, output port level, and time.

Figure 3 shows that when the count value of counter 0 is equal to 10000, the comparison output port is opened and starts to output a high level. After 2 seconds, it becomes a low level and the output port is closed.

▆ 2.2 High-speed comparison instruction LS_CompareFIFO in FIFO mode

This instruction is used to set the parameters of the one-dimensional comparison output in FIFO mode. The FIFO can store up to 1000 comparison points and can dynamically push comparison points in. When the count value equals the comparison value, the output state of the specified output port is changed according to the output mode set by the instruction. When the instruction is triggered, the output state of the specified output port will be reversed first; that is, before the instruction is triggered, the output port is closed (low level), and after the instruction is triggered, the output port is open (high level).

Input variable description

Output variable description

The FIFO can hold a maximum of 1000 points. Before each comparison begins, one point is taken out of the FIFO, which decrements the number of points in the FIFO, uiFIFOSize. After xPush triggers a rising edge, it pushes uiCmpNum points stored in fCmpPos into the FIFO. The number of points pushed into the FIFO must be carefully controlled. If the number of points in the FIFO, uiFIFOSize, exceeds 1000, the instruction will fail and terminate.

Output mode 0, 1 - Time output mode: When the count value is equal to the comparison value, the specified output port udiOutPara is turned on/off for the time set. After the output time ends, the output port status is restored. The shortest output time is 1us and the longest output time is 20s.

Output Mode 4 – Output Level Mode: When the count value is equal to the nth comparison point, the output port is opened if the nth member of the array parameter axInvert is TRUE, and closed if it is FALSE.

As shown in Figure 4, the LS_CompareFIFO instruction sets the output level mode, and the relationship between the comparison value and the output level is shown in Table 2. Figure 5 shows the relationship curves between the count value, output port level, and time when this instruction is executed.

Figure 4 LS_CompareFIFO instruction

Table 2 Relationship between Comparison Values ​​and Output Levels

Figure 5. Relationship curves between count value, output port level, and time.

Figure 5 shows:

① When LS_CompareFIFO.xExecute triggers a rising edge, the state of the comparison output port is reversed, and a high level is output. The initial number of comparison points is 10. The position comparison begins, and the number of points stored in the FIFO is decremented by 1, becoming 9.

② When the count value equals the first comparison value of 1000, the comparison output port outputs a high level, and the comparison of the next position point begins, decrementing the number of points in the FIFO by 1; when the count value equals the second comparison value of 2000, the comparison output port outputs a low level, and the comparison of the next position point begins, decrementing the number of points in the FIFO by 1, and so on.

③When LS_CompareFIFO.xPush triggers a rising edge, 10 comparison points are pushed into the FIFO, which means the number of points in the FIFO is increased by 10.

▆ 2.3 Linear Mode High-Speed ​​Comparison Instruction LS_CompareStep

This instruction is used to set the parameters of the one-dimensional comparison output in linear mode. When the count value is equal to the initial comparison value, the output state of the output port is changed for a specified time. Thereafter, whenever the count value is equal to the previous comparison value plus the comparison step size, the output state of the output port is changed again for a specified time. The number of comparison outputs can be set in the instruction, up to a maximum of 65535 times.

Input variable description

Output variable description

As shown in Figure 6, the LS_CompareStep instruction sets the initial comparison value of counter 0 to 5000, and each subsequent comparison is incremented by 10000 from the previous comparison value. When a match is found, the output port is opened for 0.1 seconds, and then the output port state returns to normal after the time expires. Ten comparison points are set. Figure 7 shows the relationship curve between the count value, output port level, and time during the execution of this instruction.

Figure 6 LS_Compare command

Figure 7. Relationship curves between count value, output port level, and time.

Figure 7 shows that when the count value of counter 0 is 5000, 15000, 25000, 35000, 45000, 55000, 65000, 75000, 85000, and 95000, the comparison output port outputs a high level for 0.1s each time, for a total of 10 times.

03. Compare Output Routine

This example program implements a counter 0 system where, when the count value of counter 0 is successively 10000, 15000, 25000, and 30000, the comparison output port OUT2 changes from high to low for 0.5 seconds, and then returns to high after 0.5 seconds. The configuration of counter 0 is shown in Figure 8.

Figure 8 Counter 0 Configuration

The program code is as follows:

Figure 9 Program Example

Figure 10 shows the execution result of the above program. When the start signal xExecute of the FIFO mode high-speed comparison instruction changes from FASLE to TRUE, the state of the comparison output port OUT2 is reversed and becomes high. When the count value of counter 0 is equal to 10000, 15000, 25000, and 30000 respectively, the comparison output port OUT2 changes from high to low for 0.5s, and then returns to high after 0.5s.

Figure 10 Comparison of the output routine execution results

Read next

CATDOLL 88CM Bebe Full Silicone Doll

Height: 88cm Silicone Weight: 14kg Shoulder Width: 25cm Bust/Waist/Hip: 49/45/51cm Oral Depth: N/A Vaginal Depth: 3-13c...

Articles 2026-02-22