Wiki source code of 09 High Speed Counter

Last modified by Wecon on 2025/09/03 21:02

Hide last authors
Wecon 1.1 1 == **High-speed Counter (Encoder axis) Introduction** ==
2
3 ----
4
5 === **High-speed counter axis introduction** ===
6
7
8 ----
9
10 The high-speed counter is implemented in the form of encoder axis in LX6 series PLC, subsequent collectively referred to as the encoder axis. It supports 4-axis 32-bit high-speed counter, AB phase 1/2/4 times frequency, pulse/direction and single-phase counting. The counting signal support external pulse input or internal 100us/1ms/10ms clock counting, and supports touch probe and high-speed comparison output functions.
11
12 === **Create encoder axis** ===
13
14 ----
15
16 Step: "Project Management"->"Motion control axis"->"Right click"->"Add Axis"
17
18 "Axis type" select "Local encoder Axis"
19
20 (% style="text-align:center" %)
21 [[image:1709187654249-285.png]]
22
23
24 === **Encoder axis user unit and conversion** ===
25
26 ----
27
28 The encoder axis decoding the encoder signal by pulse unit, and the encoder axis command uses common measurement units such as millimeters, degrees, inches, etc., which we call it user unit. The number of pulses can be converted into user unit through conversion, and user unit can be defined as equipment-related units (millimeters, revolutions, etc.) according to actual applications.
29
30 The parameters to be set for unit conversion are as follows:
31
32 |=**Parameter name**|=**Function**
33 |Pulses of motor/encoder for one rotation|Set pulses of motor for one rotation according to encoder resolution
34 |With gearbox or not|Specify whether or not to use gearbox
35 |Movement amount of motor/encoder for one rotation|Workpiece movement amount of motor for one rotation without gearbox
36 |Movement amount of worktable for one rotation|Workpiece movement amount of motor for one rotation with gearbox
37 |Gear ratio numerator|Set the gear ratio of workpiece side
38 |Gear ratio denominator|Set the gear ratio of motor side
39
40 In gear drive, the drive axis is usually called input axis, and the driven axis is called output axis. Therefore, the numerator of the gear ratio represents the speed of the input axis (usually also represents the gear driven by the input axis), and the denominator represents the speed of the output axis (usually also represents the gear driven by the output axis). If the gear ratio is a: b, it means that for a revolution of the input axis, the output axis will rotate b revolutions.
41
42 For example, servo motor drives worktable to move by connecting screw rod through reducer, counts encoder to feedback worktable position by PLC controller, and counts encoder pulse by counter, taking pulse as unit; If the counter axis represents the table position, it is in millimeters. Therefore, in the program, the user unit of the counter axis is uniformly expressed in the user unit.
43
44 The conversion relationship between user unit and pulse is as follows:
45
46 (% style="text-align:center" %)
47 [[image:1709187709132-349.png]]
48
49
50 The number of pulses for one revolution of the motor/encoder: In the input box, 16# indicates a hexadecimal number. If the encoder output 10000 pulses per revolution, the corresponding hexadecimal value is 2710, then enter 16#2710.
51
52 Working stroke setting: The working stroke can be set without or with a gearbox.
53
54 Without gearbox:
55
56 When the gearbox is not used, the conversion formula from user unit to pulse unit is as follows:
57
58 (% style="text-align:center" %)
59 [[image:1709187727754-405.png]]
60
61 For example, if the encoder rotates one circle and the corresponding working axis rotates one circle, the user unit is one revolution, then the working stroke of the motor/encoder one circle rotation can be set to 1.
62
63 **·**With gearbox:
64
65 The calculation formula from user unit to pulse unit is as follows:
66
67 (% style="text-align:center" %)
68 [[image:1709187742613-995.png]]
69
70
71 Wherein (1) is a servo motor, (3) is a workpiece, (4) is the gear ratio denominator, and (5) is the gear ratio numerator.
72
73 The calculation formula from user unit to pulse unit is as follows:
74
75
76 For instance: The servo motor drives the worktable to move through the reducer connected by the screw. The working stroke of the screw rotating once is 5mm, and the reduction ratio is 20:10. The corresponding input axis (motor) needs to rotate 20 turns every time the output axis rotates once. Therefore, the gear ratio numerator can be set as 20, and the gear ratio denominator can be set as 10. Before the motor rotation is transmitted to the output axis (screw), the amplification of the gear can ensure the required distance for the worktable to move. The settings are as follows:
77
78 (% style="text-align:center" %)
79 [[image:1709187760060-141.png]]
80
81 (% class="box infomessage" %)
82 (((
83 ✎Note: Besides reduction ratio and gear ratio, the power of the servo motor should be determined according to the performance parameters of the servo motor and the load-characteristic of the worktable, and the required motor speed and torque should be calculated according to the reduction ratio and gear ratio to ensure that the system can work properly.
84 )))
85
86 Typical working condition in rotation mode is shown in the following figure:
87
88 (% style="text-align:center" %)
89 [[image:1709187890751-659.png]]
90
91
92 Wherein (1) is a servo motor, (3) is a workpiece, (4) is the gear ratio denominator, and (5) is the gear ratio numerator.
93
94 The calculation formula from user unit to pulse unit is as follows:
95
96 (% style="text-align:center" %)
97 [[image:1709187908885-363.png]]
98
99 === **Work mode setting** ===
100
101 ----
102
103 **Linear mode**
104
105 The position of the encoder axis changes between the negative limit value and the positive limit value. After the position of the encoder axis reaches the limit value, if continue to input the same direction pulse, the counter axis will report an overflow error, and the position of the counter axis will remain unchanged. After encoder report an overflow error, if input reverse pulse, the encoder axis will reverse count and overflow error removed.
106
107 In linear mode, the negative and positive position limits of the encoder axis can be set in the interface, and the position unit is the user unit. The negative limit value must be less than or equal to 0, and the positive limit value must be greater than or equal to 0.
108
109 Since the high-speed counter is a 32-bit counter, the negative limit value and the positive limit value must be in the 32-bit integer range [-2147483648, 2147483647] after being converted into pulse units.
110
111 (% style="text-align:center" %)
112 [[image:1709187962160-582.png]]
113
114 In linear mode, the high-speed counter works in the closed range of [negative limit value, positive limit value]. When the direction is negative, the count value decreases in the negative direction, and after reaching the negative limit value, the count value no longer decreases; When the direction is positive, the count value increases in the positive direction, and after reaching the positive limit value, the count value no longer increases.
115
116 (% style="text-align:center" %)
117 [[image:1709187988638-794.png]]
118
119 **Forward pulse counting**
120
121 In linear mode, input positive pulse, after the encoder axis position increment count reaches the limit value, if continue to input positive pulse will cause the encoder axis reports a positive overflow error, and the encoder axis position value remains unchanged. Input negative pulse, encoder axis position will count down and positive overflow error will be removed.
122
123 (% style="text-align:center" %)
124 [[image:1709188011111-281.png]]
125
126 **Reverse pulse counting**
127
128 In linear mode, input negative pulse, after the encoder axis position countdown reaches the limit value, if continue to input negative pulse will cause the encoder axis reports a negative overflow error, and the encoder axis position value remains unchanged. Input positive pulse, encoder axis position will count up and negative overflow error will be cleared.
129
130 (% style="text-align:center" %)
131 [[image:1709188047952-617.png]]
132
133 **Rotation mode**
134
135 The position of the encoder axis changes cyclically in the rotation period. When counting up, the position of the encoder axis reaches the maximum of the rotation period and then becomes 0. When counting down, the position of the encoder axis reaches 0 and then decreases from the maximum of the rotation period. In rotation mode, the rotation period of the counter axis can be set in the interface, and the period unit is the user unit.
136
137 Since the high-speed counter is 32-bit counter, the rotation period must be in the 32-bit integer range [-2147483648.2147483647, 2147483647] after being converted into pulse units.
138
139 (% style="text-align:center" %)
140 [[image:1709188065464-440.png]]
141
142
143 === **Setting counter parameters** ===
144
145 ----
146
147 **Overview**
148
149 Local encoder axis supports multiple signal counting modes, A/B phase (1/2/4 times frequency), pulse + direction, single phase counting.
150
151 Signal source: According to different counting modes, user can select different signal sources.
152
153 (% style="text-align:center" %)
154 [[image:1709188107646-539.png]]
155
156 The signal source input ports supported in each counting mode are shown in the following table. Different local encoder axis can select the same signal source input port:
157
158 |=**Counting mode**|=**AB phase**|=**Pulse + Direction**|=**Single phase counting**
159 |X0|A phase|Pulse|Pulse
160 |X1|B phase|Direction|Pulse
161 |X2|A phase|Pulse|Pulse
162 |X3|B phase|Direction|Pulse
163 |X4|A phase|Pulse|Pulse
164 |X5|B phase|Direction|Pulse
165 |X6|A phase|Pulse|Pulse
166 |X7|B phase|Direction|Pulse
167 |100us|×|×|Pulse
168 |1ms|×|×|Pulse
169 |10ms|×|×|Pulse
170
171 When using touch probe or preset function, encoder axis is divided into two groups, namely, X0 ~~ X3 is counting group 1 and X4 ~~ X7 is counting group 2. The same signal source in counting group can only be used in one encoder axis, that is, when the touch probe function of counting group 1 is enabled, X3 is occupied and cannot be used as signal source of other counting modes. Touch probes and preset functions cannot be used by internal signal sources.
172
173 |=**Counting mode**|=**AB phase**|=**Pulse + Direction**|=**Single phase counting**
174 |X0|A phase|Pulse|Pulse
175 |X1|B phase|Direction|×
176 |X2|Touch probe|Touch probe|Touch probe
177 |X3|Preset|Preset|Preset
178 |X4|A phase|Pulse|Pulse
179 |X5|B phase|Direction|Pulse
180 |X6|Touch probe|Touch probe|Touch probe
181 |X7|Preset|Preset|Preset
182 |100us|×|×|Pulse
183 |1ms|×|×|Pulse
184 |10ms|×|×|Pulse
185
186 **A/B phase mode**
187
188 In the A/B phase mode, the encoder generates two quadrature phase pulse signals with a phase difference of 90 degrees, namely A-phase signal and B-phase signal. When the A-phase signal advances the B-phase signal, the counter increases the count; When the B-phase signal advances the A-phase signal, the counter counts down.
189
190 A/B phase pulse can be set to work in 1 time frequency mode, 2 times frequency mode or 4 times frequency mode.
191
192 In A/B phase 1 time frequency mode, only the rising edge of phase A pulse is counted, as shown in the following figure:
193
194 (% style="text-align:center" %)
195 [[image:1709188210848-712.png]]
196
197 In A/B phase 2 times frequency mode, the rising/falling edge of phase A pulse is counted, as shown in the following figure:
198
199 (% style="text-align:center" %)
200 [[image:1709188228254-788.png]]
201
202 In A/B phase 4 times frequency mode, the rising/falling edge of phase A pulse is counted, as shown in the following figure:
203
204 (% style="text-align:center" %)
205 [[image:1709188258206-900.png]]
206
207 **Pulse + direction mode**
208
209 In this mode, when the direction signal is ON, the high-speed counter increases the count of the pulse signal, and when the direction signal is OFF, the high-speed counter decreases the count of the pulse signal, as shown in the following figure:
210
211 (% style="text-align:center" %)
212 [[image:1709188290177-266.png]]
213
214 **Single-phase counting mode**
215
216 In this mode, the high-speed counter increases the count of the pulse signal, on the rising edge of the input pulse, the position count is increased by 1.
217
218 (% style="text-align:center" %)
219 [[image:1709188315094-949.png]]
220
221 **Touch probe setting**
222
223 Each encoder axis supports one external input to latch the current value of the counter to realize the touch probe function. The counting group 1 fixed use terminal X3, and the counting group 2 fixed use terminal X7.
224
225 After the touch probe is enabled, the current count value will be saved after the touch probe is triggered, and the touch probe position of the counter axis will be read through the HC_TouchProbe function block instruction.
226
227 (% style="text-align:center" %)
228 [[image:1709188331214-854.png]]
229
230 **Preset terminal input**
231
232 By checking the preset enable to enable the external input preset counter value, the counting group one fixed use terminal X2, and the counting group two fixed use terminal X6.
233
234 After the preset function is enabled, the encoder axis position is preset by external input through HC_Preset function block instruction.
235
236 (% style="text-align:center" %)
237 [[image:1709188367013-182.png]]
238
239 **Compare output terminal settings**
240
241 After "comparison output enabled" is checked, hardware can output when comparison is equal, which can be realized without software processing, with high real-time performance and output response up to microsecond level.
242
243 ● After the comparison output function is checked and cooperated with function block instruction, the output is controlled to be ON by hardware circuit when the comparison is equal, Y0~~Y7 can be arbitrarily selected as the output terminal, and the pulse width of the output to be ON can be selected as time unit or user unit.
244
245 ● Each local encoder axis is equipped with a comparison output function, which can configure the input terminal and output pulse width according to the demand.
246
247 ● After the configuration is completed, through HC_Compare, HC_ArrayCompare and HC_StepCompare function block instructions, the axis position comparison output is realized.
248
249 ● When ms is selected as the unit, the time setting range is 0.1~~6553.5ms. When Unit is selected, the set value should be in the range of 1~~65535 after being converted into pulse Unit.
250
251 (% style="text-align:center" %)
252 [[image:1709188387009-759.png]]
253
254 The comparison output is directly output through the hardware control port, not through the software processing, so the status of comparison output cannot be displayed through the Y device in the program. The Y device and the comparison output are controlled as OR relationship to the output port. If the Y device is continuously controlled as ON state, the actual port output is kept as ON.
255
256
257 == **HC Axis Control** ==
258
259 ----
260
261 === **HC_COUNTER High Speed Counter Enable** ===
262
263 ----
264
265 (% style="text-align:center" %)
266 [[image:1709188488339-157.png]]
267
268 HC_COUNTER
269
270 This function block is used to control the start or stop of the high speed counter.
271
272 Content, range and data type
273
274 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
275 |(% colspan="1" rowspan="10" %)HC_COUNTER|Enable|BOOL|No|TRUE
276 FALSE|High speed counter enable
277 |Invert|BOOL|Yes|TRUE
278 FALSE|Negative counting
279 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
280 |Valid|BOOL|Yes|TRUE
281 FALSE|Valid status: entering the counting status is ON
282 |Position|LREAL|Yes|-|Current position: user unit
283 |Velocity|LREAL|Yes|-|Current velocity: user unit
284 |Direction|BOOL|Yes|TRUE
285 FALSE|(((
286 Counting direction
287
288 (TRUE: Forward, FALSE: Reverse)
289 )))
290 |CommandAborted|BOOL|Yes|TRUE
291 FALSE|Execute interrupt
292 |Error|BOOL|Yes|TRUE
293 FALSE|Error
294 |ErrorID|DWORD|Yes|Check [ErrorID] for details|Error code
295
296 Device used
297
298 |=**Instruction**|=**Parameter**|=(% colspan="22" %)**Devices**|=**Offset modification**|=**DWORD expansion**|=**Pulse expansion**
299 | | |**X**|**Y**|**M**|**S**|**SM**|**T (Bit)**|**HSC (Bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**DXX**|**XXP**
300 |(% colspan="1" rowspan="10" %)HC_COUNTER|Enable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
301 |Invert|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
302 |Axis| | | | | | | | | | | | | | |●|●| | | | | | | | |
303 |Valid| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
304 |Position| | | | | | | | | | | | | | | | | | | | | | | | |
305 |Velocity| | | | | | | | | | | | | | | | | | | | | | | | |
306 |Direction| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
307 |CommandAborted| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
308 |Error| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
309 |ErrorID| | | | | | | | | | | | | | | | | | | | | | | | |
310
311 Function
312
313 The HC_COUNTER function block can count the current counter axis position, measure the current velocity in real time and display the current counting direction.
314
315 The counter axis position is set only according to the current counting mode and varies within the range of the counter axis mode, and the position unit is Unit.
316
317 (% class="box infomessage" %)
318 (((
319 ✎Note:
320
321 (1) Update the current axis position, velocity and counting direction if and only if the function block Enable is enabled.
322
323 (2) If two function blocks are counting at the same time in the scanning program and the encoder axis parameter Axis is specified to be the same, the execution of the first enabled function block will be interrupted by the second enabled function block. The former CommandAborted is set to True, and the valid status Valid is set to False.
324
325 (3) When Function Block generates an error, Enable must be re-enabled to clear the error. Otherwise, the function block does not execute counting
326 )))
327
328 Invert parameter (Negative counting)
329
330 The counting direction of the counter is set by the Invert parameter. The definition of counting directions for different counting modes are shown in the following figure. When changing the setting of Invert, it will take effect directly if the function block is enabled.
331
332 |=**Invert**|=**Phase A/B**|=**Pulse + Direction**|=**CW/CCW**|=**Single phase counting**
333 |FALSE|(((
334 Phase A is ahead of Phase B to count up.
335
336 Phase B is ahead of Phase A to count down.
337 )))|(((
338 Direction signal Vil count down
339
340 Direction signal VIH count up
341 )))|(((
342 Phase A counting up.
343
344 Phase B counting down.
345 )))|Counting up
346 |TRUE|(((
347 Phase A is ahead of Phase B to count down.
348
349 Phase B is ahead of Phase A to count up.
350 )))|(((
351 Direction signal Vil count up
352
353 Direction signal Vol count down
354 )))|(((
355 Phase A counting down.
356
357 Phase B counting up.
358 )))|Counting down
359
360 Description
361
362 Take the "pulse + direction" mode as an example. When the direction signal = ON/Invert=FALSE or the direction signal = OFF/Invert=TRUE, the counter is counting up, as shown in the following figure:
363
364 (% style="text-align:center" %)
365 [[image:1709188702922-261.png]]
366
367 Take the "pulse + direction" mode as an example. When the direction signal = ON/Invert=TRUE or the direction signal = OFF/Invert=FALSE, the counter is counting down, as shown in the following figure:
368
369 (% style="text-align:center" %)
370 [[image:1709188722265-947.png]]
371
372 Error code
373
374 |=**Error code**|=**Content**
375 |0x00400005|Counting position exceeds the positive limit value.
376 |0x00400006|Counting position exceeds negative limit value.
377 |0x00700005|Axis undefined or invalid axis number
378 |0x00800008|Modify the axis number when the function block is running.
379
380 Example
381
382 Application example
383
384 The counter axis speed is the real-time speed, and the speed unit is Unit/s. The minimum speed that can be measured by the counter axis is the speed corresponding to one pulse of the counter in 1s. For instance, when one pulse of the counter corresponds to 0.01 Unit, the minimum speed that can be measured is 0.01 Unit/s.
385
386 (% style="text-align:center" %)
387 [[image:1709188920597-329.png]]
388
389 For example: When the current function block Enable in the above figure is ON, update the current encoder axis position and velocity, display the counting direction, and measure the current input pulse speed in the AXIS_0 is 100 Unit/s and the current position is 1559.0 Unit.
390
391 === **HC_PRESET High speed counter preset value** ===
392
393 ----
394
395 (% style="text-align:center" %)
396 [[image:1709188994760-194.png]]
397
398 HC_PRESET
399
400 Set the counter value to the preset value according to the preset trigger condition set.
401
402 Content, range and data type
403
404 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
405 |(% rowspan="9" %)HC_PRESET|Enable|BOOL|No|TRUE
406 FALSE|High speed counter preset enabled
407 |TriggerEdge|WORD|Yes|0~~1|(((
408 Trigger edge
409
410 0: Instruction Enable rising edge triggers
411
412 1: External X rising edge triggers
413 )))
414 |Position|LREAL|No|-|Preset position: user unit
415 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
416 |Done|BOOL|Yes|(((
417 TRUE
418
419 FALSE
420 )))|Completed
421 |Busy|BOOL|Yes|(((
422 TRUE
423
424 FALSE
425 )))|Executing
426 |CommandAborted|BOOL|Yes|TRUE
427 FALSE|Execution interrupt
428 |Error|BOOL|Yes|TRUE
429 FALSE|Error
430 |ErrorID|DWORD|Yes|Check "ErrorID" for details|[[Error code>>path:#_8.10_Error_Code]]
431
432 Device used
433
434 |=**Instruction**|=**Parameter**|=(% colspan="21" %)**Devices**|=(% colspan="2" %)**Index modification**|=(% colspan="2" %)**DWORD expansion**|=(% colspan="2" %)**Pulse expansion**
435 | | |**X**|**Y**|**M**|**S**|**SM**|**T (Bit)**|**HSC (Bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|(% colspan="2" %)**[D]**|(% colspan="2" %)**DXX**|**XXP**
436 |(% colspan="1" rowspan="9" %)HC_PRESET|Enable|●|●|●|●|●| | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
437 |TriggerEdge| | | | | | | | | | | | | | |●|●| | | | | | |(% colspan="2" %) |(% colspan="2" %) |
438 |Position| | | | | | | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
439 |Axis| | | | | | | | | | | | | | |●|●| | | | | | |(% colspan="2" %) |(% colspan="2" %) |
440 |Done| |●|●|●|●| | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
441 |Busy| |●|●|●|●| | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
442 |CommandAborted| |●|●|●|●| | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
443 |Error| |●|●|●|●| | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
444 |ErrorID| | | | | | | | | | | | | | | | | | | | | | |(% colspan="2" %) |(% colspan="2" %) |
445
446 Function
447
448 Enable HC_PRESET function block and the counter axis position is assigned according to the preset trigger condition.
449
450 TriggerEdge parameter
451
452 Select the rising edge of instruction enable or external X input to trigger preset function.
453
454 |=**Parameter**|=**Settings**|=**Definition**
455 |TriggerEdge|0|Enable rising edge triggering
456 | |1|External X rising edge trigger
457
458 When selecting external X input trigger as preset condition, it needs to see preset function in counter parameter setting. Select input terminal and trigger condition, X2 and X6 for input terminal and rising edge trigger for trigger condition.
459
460 Description
461
462 The instruction Enable is triggered on the rising edge (TriggerEdge=0), and the instruction sequence diagram is shown in the following figure:
463
464 (% style="text-align:center" %)
465 [[image:1709189216772-118.png]]
466
467 External X interrupt triggers. Take rising edge trigger (TriggerEdge=1) as an example, and the instruction sequence diagram is shown in the following figure:
468
469 (% style="text-align:center" %)
470 [[image:1709189239134-257.png]]
471
472 |=**Error code**|=**Content**
473 |0x007000000|Set the trigger edge to external X edge trigger, but the preset function of axis configuration interface is not enabled
474 |0x00700005|Axis undefined or invalid axis number
475 |0x00700008|High speed counter of local encoder axis is not enabled
476 |0x00800006|Set the preset position out-of-limit value/set the trigger edge parameter out-of-range
477 |0x00800008|Modify the axis number when the function block is running.
478
479 Example
480
481 Application example
482
483 (% style="text-align:center" %)
484 [[image:1709189294858-543.png]]
485
486 Set the preset trigger condition as Enable rising edge trigger (TriggerEdge=0). When the preset condition is met, modify the current HC_COUNTER axis position as the preset position. At this time, the current position read by the HC_COUNTER function block is the preset position.
487
488 === **HC_TOUCHPROBE High speed counter touch probe** ===
489
490 ----
491
492 (% style="text-align:center" %)
493 [[image:1709189352418-319.png]]
494
495 HC_TOUCHPROBE
496
497 According to the set trigger mode and conditions, record the counter value when the signal is triggered.
498
499 Content, range and data type
500
501 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
502 |(% rowspan="12" %)HC_TOUCHPROBE|Enable|BOOL|No|TRUE
503 FALSE|High speed counter preset enable
504 |ProbeID|WORD|No|0|(((
505 Touch probe ID
506
507 0: Touch probe 1
508 )))
509 |TriggerEdge|WORD|No|1~~3|(((
510 Trigger edge
511
512 1: External X rising edge triggers
513
514 2: External X falling edge triggers
515
516 3: External X rising or falling edge triggers
517 )))
518 |TriggerMode|WORD|Yes|0~~1|(((
519 Trigger mode
520
521 0: Single triggers
522
523 1: Continuous triggers
524 )))
525 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
526 |Done|BOOL|Yes|(((
527 TRUE
528
529 FALSE
530 )))|Completed
531 |Busy|BOOL|Yes|(((
532 TRUE
533
534 FALSE
535 )))|Executing
536 |PositivePosition|LREAL|Yes|-|Rising edge latch position: user unit
537 |NegativePosition|LREAL|Yes|-|Falling edge latch position: user unit
538 |CommandAborted|BOOL|Yes|TRUE
539 FALSE|Execute interrupt
540 |Error|BOOL|Yes|TRUE
541 FALSE|Error
542 |ErrorID|DWORD|Yes|Check "ErrorID" for details|Error code
543
544 **~ **Device used
545
546 |=**Instruction**|=**Parameter**|=(% colspan="22" %)**Devices**|=**Offset modification**|=**DWORD expansion**|=**Pulse expansion**
547 | | |**X**|**Y**|**M**|**S**|**SM**|**T (Bit)**|**HSC (Bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**DXX**|**XXP**
548 |(% colspan="1" rowspan="12" %)HC_TOUCHPROBE|Enable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
549 |ProbeID| | | | | | | | | | | | | | |●|●| | | | | | | | |
550 |TriggerEdge| | | | | | | | | | | | | | |●|●| | | | | | | | |
551 |TriggerMode| | | | | | | | | | | | | | |●|●| | | | | | | | |
552 |Axis| | | | | | | | | | | | | | |●|●| | | | | | | | |
553 |Done| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
554 |Busy| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
555 |PositivePosition| | | | | | | | | | | | | | | | | | | | | | | | |
556 |NegativePosition| | | | | | | | | | | | | | | | | | | | | | | | |
557 |CommandAborted| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
558 |Error| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
559 |ErrorID| | | | | | | | | | | | | | | | | | | | | | | | |
560
561 Function
562
563 Enable the HC_TOUCHPROBE function block instruction to latch the counter axis position value when the external input trigger condition is valid.
564
565 Each counter axis only supports one touch probe. When using, it needs to check the corresponding touch probe function in the counter parameter setting. Select the input terminal and trigger mode and condition. The input terminal can be set as X3 or X7.
566
567 Description
568
569 TriggerEdge parameter
570
571 The touch probe trigger edge can be set. The rising edge trigger position is latched in the output parameter PositivePosition. The falling edge trigger position is latched in the output parameter NegativePosition.
572
573
574 |=**Parameter**|=**Settings**|=**Definition**
575 |(% colspan="1" rowspan="3" %)TriggerEdge|1|External X rising edge triggers
576 |2|External X falling edge triggers
577 |3|External X rising or falling edge triggers
578
579 TriggerMode parameter
580
581 Single trigger and continuous trigger modes can be set.
582
583 In single trigger mode, when the function block Enable is valid and external input trigger condition disappears, the counter axis position is latched and the completion signal is output. The touch probe position latches the counter axis position in real time according to the trigger edge, which is not affected by program execution. According to the scan period, the latch position is updated to the instruction output parameter when the program scanning executes to the latch instruction.
584
585 (% style="text-align:center" %)
586 [[image:1709189508613-317.png]]
587
588 Rising edge single trigger mode
589
590 In continuous trigger mode, when the function block instruction Enable is valid and the external input trigger condition disappears, the counter axis position is latched and the completion signal is output. The valid time is 1 scan period. When the completion signal becomes OFF and the external input trigger condition is valid, the counter axis position will continue to be latched, and the completion signal with valid time of 1 scan period will be output. The counter axis position is not latched if an external input trigger condition is valid during the 1 scan period when the completion signal is valid.
591
592 (% style="text-align:center" %)
593 [[image:1709189544740-285.png]]
594
595 Rising edge continuous trigger mode
596
597 When using the dual-edge trigger mode, the completion signal is output when both the rising and the falling edges are triggered to complete the latch. In single trigger mode, the completion signal lasts until the instruction is completed. In continuous trigger mode, the valid time of completion signal is 1 scan period. The trigger latch signal is not responded to within 1 scan period when the completion signal is valid.
598
599 (% style="text-align:center" %)
600 [[image:1709189576108-764.png]]
601
602 Rising and falling edges single trigger mode
603
604 (% style="text-align:center" %)
605 [[image:1709189600902-779.png]]
606
607 Rising and falling edge continuous trigger mode
608
609 Sequence diagram
610
611 External X rising edge trigger (TriggerEdge=1), single trigger mode (TriggerMode=0), and the instruction sequence diagram is shown in the following figure.
612
613 (% style="text-align:center" %)
614 [[image:1709189636057-993.png]]
615
616 External X falling edge trigger (TriggerEdge=2), single trigger mode (TriggerMode=0), and the instruction sequence diagram is shown in the following figure.
617
618 (% style="text-align:center" %)
619 [[image:1709189650326-881.png]]
620
621 External X rising and falling edges triggering (TriggerEdge=3), single trigger mode (TriggerMode=0), and the instruction sequence diagram is shown in the following figure.
622
623 (% style="text-align:center" %)
624 [[image:1709189670934-687.png]]
625
626 External X rising and falling edges triggering (TriggerEdge=3), continuous trigger mode (TriggerMode=1), and the instruction sequence diagram is shown in the following figure.
627
628 (% style="text-align:center" %)
629 [[image:1709189687310-523.png]]
630
631 Error code
632
633 |=**Error code**|=**Content**
634 |0x007000000|Touch probe of axis configuration interface is not enabled
635 |0x00700005|Axis undefined or invalid axis number
636 |0x00800006|Setting errors from trigger edge/trigger mode/touch probe ID
637 |0x00800008|Modify the axis number when the function block is running.
638
639 Example
640
641 Application example
642
643 (% style="text-align:center" %)
644 [[image:1709189734406-954.png]]
645
646 1. In the axis configuration interface, the touch probe is enabled and the configuration pin is X3. Set the trigger mode to single trigger (TriggerMode = 0), and the trigger edge is external X rising and falling edges trigger (TriggerEdge = 3)
647 1. When the function block Enable enables, Busy is set to TRUE.
648 1. When X3 detects the rising edge, latch position to PositivePosition; When X3 detects the falling edge, latch position to NegativePosition. At this time, the execution of this function block is completed, and the Busy status is set to False and Done is set to TRUE.
649
650 === **HC_COMPARE High speed counters comparison** ===
651
652 ----
653
654 (% style="text-align:center" %)
655 [[image:1709189863035-259.png]]
656
657 HC_COMPARE
658
659 The touch probe counter count reaches the specified value.
660
661 Content, range and data type
662
663 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
664 |(% colspan="1" rowspan="10" %)HC_COMPARE|Enable|BOOL|No|TRUE
665 FALSE|High speed counter comparison enabled
666 |Position|LREAL|No|-|Comparison position: user unit
667 |OutputEnable|BOOL|Yes|TRUE
668 FALSE|(((
669 Hardware output enabled
670
671 FALSE: No hardware output
672
673 TRUE: Using hardware output
674 )))
675 |InterruptMap|POINTER|Yes|-|(((
676 Interrupt mapping: interrupts are generated and associated when the comparison value matches the count value.
677
678 The interrupt name can be input directly, for instance:
679
680 IRQ0: associate interrupt IRQ0
681
682 None: not associate interrupt
683 )))
684 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
685 |Done|BOOL|Yes|(((
686 TRUE
687
688 FALSE
689 )))|Completed
690 |Busy|BOOL|Yes|(((
691 TRUE
692
693 FALSE
694 )))|Executing
695 |CommandAborted|BOOL|Yes|TRUE
696 FALSE|Execution interrupt
697 |Error|BOOL|Yes|TRUE
698 FALSE|Error
699 |ErrorID|DWORD|Yes|Check "ErrorID" for details|Error code
700
701 Device used
702
703 |=**Instruction**|=**Parameter**|=(% colspan="22" %)**Devices**|=**Offset modification**|=**DWORD expansion**|=**Pulse expansion**
704 | | |**X**|**Y**|**M**|**S**|**SM**|**T (Bit)**|**HSC (Bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**DXX**|**XXP**
705 |(% colspan="1" rowspan="10" %)HC_COMPARE|Enable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
706 |Position| | | | | | | | | | | | | | | | | | | | | | | | |
707 |OutputEnable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
708 |InterruptMap| | | | | | | | | | | | | | | | | | | | | | | | |
709 |Axis| | | | | | | | | | | | | | |●|●| | | | | | | | |
710 |Done| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
711 |Busy| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
712 |CommandAborted| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
713 |Error| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
714 |ErrorID| | | | | | | | | | | | | | | | | | | | | | | | |
715
716 Function
717
718 Enabling HC_COMPARE to achieve a single position comparison of the counter axis.
719
720 (% class="box infomessage" %)
721 (((
722 ✎Note:
723
724 1. When using this function block, if the InterruptMap parameter specifies the program name of mapping interrupt, the EI instruction should be enabled in the scanning program. Otherwise, the interrupt program cannot be executed.
725 1. If there are two high speed comparation function blocks, whose Axis parameters specify the same local encoder axis, the execution of the former executed function block will be interrupted by the latter function block. The ComandAborted execution interrupt will be set to ON.
726 )))
727
728 Description
729
730 Using hardware output (OutputEnable=TRUE), the instruction sequence diagram is shown in the following figure.
731
732 (% style="text-align:center" %)
733 [[image:1709190153209-254.png]]
734
735 Error code
736
737 |=**Error code**|=**Content**
738 |0x007000000|OutEnable is ON, but axis configuration interface comparison output is not enabled.
739 |0x00700005|Axis undefined or invalid axis number
740 |0x00800006|The set comparison position is out of limit.
741 |0x00800008|Modify the axis number when the function block is running.
742
743 Example
744
745 Application example
746
747 (% style="text-align:center" %)
748 [[image:1709190192505-238.png]]
749
750 1. Set the comparison position as 100, configure the interrupt mapping program (InterruptMap = IRQ0), configure the hardware output enabled (outputEnable = TRUE), and enable the function block (Enable = TRUE);
751 1. When the counter axis position reaches 100, the comparison interrupt is triggered, and the interrupt IRQ0 is called. If the hardware output is enabled at this time, the pulse of set pulse width is output by the corresponding Y output point.
752
753 === **HC_ARRAYCOMPARE High speed counter array comparison** ===
754
755 ----
756
757 (% style="text-align:center" %)
758 [[image:1709190287934-530.png]]
759
760 HC_ARRAYCOMPARE
761
762 Sequentially detect whether the counter count value is equal to the specified array sequence.
763
764 Content, range and data type
765
766 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
767 |(% colspan="1" rowspan="12" %)HC_ARRAYCOMPARE|Enable|BOOL|No|TRUE
768 FALSE|High speed counter comparison enabled
769 |PositionArray|ARRAY OF LREAL|No|-|Comparison position array: user unit
770 |ArrayLength|WORD|No|1~~32|Array length
771 |OutputEnable|WORD|Yes|TRUE
772 FALSE|(((
773 Hardware output enabled
774
775 FALSE: No hardware output
776
777 TRUE: Using hardware output
778 )))
779 |InterruptMap|POINTER|Yes|-|(((
780 Interrupt mapping: when the comparison value matches the count value, an interrupt is generated and associated. Interrupt name can be input directly.
781
782 IRQ0: associate interrupt IRQ0
783
784 None: not associate interrupt
785 )))
786 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
787 |Done|BOOL|Yes|(((
788 TRUE
789
790 FALSE
791 )))|Completed
792 |Busy|BOOL|Yes|(((
793 TRUE
794
795 FALSE
796 )))|Executing
797 |NextIndex|WORD|Yes|0~~32|Next comparison position index
798 |CommandAborted|BOOL|Yes|TRUE
799 FALSE|Execution interrupt
800 |Error|BOOL|Yes|TRUE
801 FALSE|Error
802 |ErrorID|DWORD|Yes|Check "Error code" for details|Error code
803
804 Device used
805
806 |=**Instruction**|=**Parameter**|=(% colspan="22" %)**Devices**|=**Index modification**|=**DWORD expansion**|=**Pulse expansion**
807 | | |**X**|**Y**|**M**|**S**|**SM**|**T (Bit)**|**HSC (Bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**DXX**|**XXP**
808 |(% colspan="1" rowspan="12" %)HC_ARRAYCOMPARE|Enable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
809 |PositionArray| | | | | | | | | | | | | | | | | | | | | | | | |
810 |ArrayLength| | | | | | | | | | | | | | |●|●| | | | | | | | |
811 |OutputEnable|●|●|●|●|●| | | | | | | | | | | | | | | | | | | |
812 |InterruptMap| | | | | | | | | | | | | | | | | | | | | | | | |
813 |Axis| | | | | | | | | | | | | | |●|●| | | | | | | | |
814 |Done| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
815 |Busy| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
816 |NextIndex| | | | | | | | | | | | | | |●|●| | | | | | | | |
817 |CommandAborted| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
818 |Error| |●|●|●|●| | | | | | | | | | | | | | | | | | | |
819 |ErrorID| | | | | | | | | | | | | | | | | | | | | | | | |
820
821 Function
822
823 Enable HC_ARRAYCOMPARE to achieve continuous multi-position comparison of the counter axis.
824
825 Description
826
827 When the function block Enable is valid, the counter axis position is compared with the first position of the array. When the comparison is equal, it is compared with the next position of the array. The ArrayLength parameter in the function block is used to set the array length. When the comparison of all array positions set by the array length is completed, the signal is continuously output and the multi-position continuous comparison is completed.
828
829 The output parameter NextIndex indicates the next comparison position index, namely the number of equal comparisons that have been completed.
830
831 (% class="box infomessage" %)
832 (((
833 ✎Note:
834
835 1. When using this function block, if the InterruptMap parameter specifies the program name of mapping interrupt, the EI instruction should be enabled in the scanning program. Otherwise, the interrupt program cannot be executed.
836 1. When inputting the PositionArray parameter of comparison position array, it must be a monotonically increasing array or a monotonically decreasing array, and two adjacent comparison positions cannot be repeated.
837 1. If there are two high speed comparation function blocks, whose Axis parameters specify the same local encoder axis, the execution of the former executed function block will be interrupted by the latter function block. The ComandAborted execution interrupt will be set to ON.
838 )))
839
840 Sequence diagram
841
842 Compare the three positions (ArrayLength=3), using hardware output (OutputEnable=TRUE), and the instruction sequence diagram is shown in the following figure.
843
844 (% style="text-align:center" %)
845 [[image:1709190479921-297.png]]
846
847 Error code
848
849 |=**Error code**|=**Content**
850 |0x007000000|OutEnable is ON, but axis configuration interface comparison output is not enabled.
851 |0x00700005|Axis undefined or invalid axis number.
852 |0x00800006|The comparison array is not set or the length of the array is set incorrectly.
853 |0x00800008|Modify the axis number when the function block is running.
854
855 Example
856
857 Application example
858
859
860 (% style="text-align:center" %)
861 [[image:1709190529021-826.png]]
862
863 (% style="text-align:center" %)
864 [[image:1709190545801-464.png]]
865
866 Set array parameters of current comparison position and array length n (ArrayLength=32 is allowed at the longest). When the function block Enable is enabled, the current comparison position is set to PositionArray Index 0 position value. When the current count value position is equal to the comparison position, the comparison interrupt is triggered, and the interrupt program IRQ0 specified by InterruptMap parameter is called. If the hardware output is enabled (OutputEnable=TRUE), pulse of a specific width pulse is generated in the corresponding Y point. If the comparison of all positions in the array is completed, Done completion flag will continue to be TRUE.
867
868
869 === **HC_STEPCOMPARE high speed counters equidistant comparison** ===
870
871 ----
872
873 (% style="text-align:center" %)
874 [[image:1709190616605-768.png]]
875
876 HC_STEPCOMPARE
877
878 Sequentially and continuously compares the counter count values with equidistant consecutive values within a specified range.
879
880 Content, range and data type
881
882 |=**Instruction**|=**Parameter**|=**Variable type**|=**Can it be empty**|=**Range**|=**Description**
883 |(% colspan="1" rowspan="13" %)HC_STEPCOMPARE|Enable|BOOL|No|TRUE
884 FALSE|High speed counter comparison enabled
885 |StartPosition|LREAL|No|-|Start position: user unit
886 |EndPosition|LREAL|No|-|End position: user unit
887 |Step|LREAL|No|Positive LREAL|Spacing: user unit
888 |OutputEnable|BOOL|Yes|TRUE
889 FALSE|(((
890 Hardware output enabled
891
892 FALSE: No hardware output
893
894 TRUE: Using hardware output
895 )))
896 |InterruptMap|POINTER|Yes|-|(((
897 Interrupt mapping: when the comparison value matches the count value, an interrupt is generated and associated. Interrupt name can be input directly.
898
899 IRQ0: associate interrupt IRQ0
900
901 None: not associate interrupt
902 )))
903 |Axis|WORD|No|0~~65535|Axis name/axis number: specify the local encoder axis to operate
904 |Done|BOOL|Yes|(((
905 TRUE
906
907 FALSE
908 )))|Completed
909 |Busy|BOOL|Yes|(((
910 TRUE
911
912 FALSE
913 )))|Executing
914 |NextIndex|WORD|Yes|0~~65535|Next comparison position index
915 |CommandAborted|BOOL|Yes|TRUE
916 FALSE|Execution interrupt
917 |Error|BOOL|Yes|TRUE
918 FALSE|Error
919 |ErrorID|DWORD|Yes|Check "Error code" for details|Error code
920
921 Function
922
923 Enable HC_STEPCOMPARE to achieve the comparison between counter axis and equidistant continuous position.
924
925 Description
926
927 When the function block Enable is valid, the counter axis position is compared with the StartPosition position. When the comparison is equal, the comparison continues after increasing or decreasing the Step spacing in the comparison position. When the last comparison position is completed in equidistant comparison, the signal is continuously output.
928
929 Output parameter NextIndex
930
931 Indicate the index of the next comparison position, and the index starts from 0. (0 represents the first comparison position.) Therefore, the index is exactly equal to the number of comparison positions that have been completed.
932
933 (% class="box infomessage" %)
934 (((
935 **✎**Note:
936
937 1. When using this function block, if the InterruptMap parameter specifies the interrupt mapping program, the EI instruction should be enabled in the scanning program. Otherwise, the interrupt program cannot be executed.
938 1. If there are two high speed comparation function blocks, whose Axis parameters specify the same local encoder axis, the execution of the former executed function block will be interrupted by the latter function block. The ComandAborted execution interrupt will be set to ON.
939 )))
940
941 Sequence diagram
942
943 Using hardware output (OutputEnable=TRUE), StartPosition<EndPosition, the instruction sequence diagram is shown in the following figure.
944
945 (% style="text-align:center" %)
946 [[image:1709190801798-356.png]]
947
948 Using hardware output (OutputEnable=TRUE), StartPosition<EndPosition, the instruction sequence diagram is shown in the following figure.
949
950 (% style="text-align:center" %)
951 [[image:1709190820599-265.png]]
952
953 Error code
954
955 |=**Error code**|=**Content**
956 |0x007000000|OutEnable is ON, but axis configuration interface comparison output is not enabled
957 |0x00700005|Axis undefined or invalid axis number
958 |0x00800000|The number of comparison positions exceeds 65535, and the equidistant comparison is not completed.
959 |0x00800006|Setting start position, end position and spacing error
960 |0x00800008|Modify the axis number when the function block is running.
961
962 Example
963
964 Application example
965
966 (% style="text-align:center" %)
967 [[image:1709190866318-894.png]]
968
969 When the function block is enabled, the current comparison position is set to the specified position value of StartPosition. When the current count value position is equal to the comparison position, the comparison interrupt is triggered, and the interrupt program specified by the InterruptMap parameter is called. If the hardware output is enabled (OutputEnable=TRUE), the corresponding Y point will generate a pulse with a specific pulse width. When the current position exceeds the end position, the completion signal is continuously output.