In motion control equipment, we often encounter situations where high-speed input signals need to be counted, with input frequencies much higher than the sampling frequency of ordinary I/O. This necessitates the use of a PLC's high-speed input function. The Leadshine MC500 series has six built-in high-speed counting input ports, which can be directly used to acquire high-speed input signals. This example uses the MC500 PLC's built-in high-speed output port to generate pulses and directly connects them to the high-speed input ports on the main unit to demonstrate the application of the high-speed counting function.
Figure 1 Hardware connection diagram
02. Operating Procedures
1) In the LeadSys Studio software interface, select the counter and high-speed output port to be used, and set the counting mode, input counting direction, and high-speed output mode, as shown in Figures 2 and 3. ① Double-click "High_Speed_IO_Module" (High Speed IO Module) with the left mouse button; ② Left-click "Axis Parameter Settings" to enter the high-speed output port configuration interface, select "Axis 0", check "Enable", set the pulse output mode to "AB phase", and use the default parameters for the rest; ③ Left-click "High-Speed Input Settings" to enter the high-speed input port configuration interface, select "Counter 0", check "Enable", set the working mode to "A/B phase 1x frequency", the counting direction to "Forward", the counting mode to "Linear Mode", and use the default maximum counting range for the upper and lower limits.
Figure 2 High-speed output port settings
Figure 3 High-speed output port settings
2) Create the variables shown in Figure 4.
Figure 4 Creating variables
3) Write the counter preset and counter counting function blocks, as shown in Figure 5. ① Counter preset function block (clearing the counter will preset it to "0". The clearing and preset functions are used in the same way, only the preset values are different). ② Counter counting function block.
Figure 5. Counter preset function block and counter counting function block
4) The functions of the modules marked in Figure 6 for the pulse output port are as follows: ① MC516 and MC532 pulse axis binding function (must be called when using pulse axes). When an error occurs within the module, MC_Reset must be called first to clear the axis error status, and then xClearRrr must be triggered to clear the error within the module. ② Axis enable ③ Axis relative motion function block. The functions of the modules marked in Figure 7 are as follows: ④ Clear axis error function block ⑤ Axis stop motion function block.
Figure 6. Function blocks for pulse axis binding, axis enable, and axis relative motion.
Figure 7. Axis reset and axis stop function blocks
5) Write the logic control program. Figure 8 shows the logic control program. The program annotations in the figure are explained as follows: ① Call the pulse output program segment and the counting program segment under PRG; assign the address of the port pointer variable of stAxis in the LS_MotionControl_P function block; ② Reset all function blocks; ③ Clear the counter before counting (Note: the counter can only be cleared when LS_Counter_Enable is TRUE and then LS_PresetValue is triggered; the usage of the preset value and the clear function is the same, only the preset value is different); ④ Turn on the counter; ⑤ Trigger the pulse output function block to output pulses; ⑥ Reset after pulse output is completed.
Figure 8 Logic Control Program
-END-