Wiki source code of 5-5 Counter

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

Hide last authors
Wecon 1.1 1 = **Counter** =
2
3 Counter performs counting function, it contains coil, contact and count value register. The current value of the counter increases each time coil C0 is turned ON. The output contact is activated when count value reach to preset value.
4
5 Counters which are latched are able to retain their status information, even after the PLC has been powered down. This means on re-powering up, the latched counters could immediately resume from where they were at the time of the original PLC power down.
6
7 Devices numbered in: Decimal, i.e. C0 to C9, C10 to C19
8
9 Table 1
10
11 (% border="2" %)
12 |(% rowspan="2" %)**PLC**|(% colspan="2" %)(((
13 **16bit UP Counters**
14
15 **0 – 32,767**
16 )))|(% colspan="2" %)(((
17 **32bit Bi-directional Counters  -2,147,483,648 - +2,147483647**
18 )))
19 |**General**|**Latched**|**General**|**Latched**
20 |LX1S|16 (C0 – C15) ※3|16 (C16 – C31) ※3|-|-
21 |LX2N|100 (C0-C99) ※1|100(C100 – C199) ※2|20 (C200 – C219) ※1|15 (C220 – C234) ※2
22 |LX3V|100 (C0-C99) ※1|100(C100 – C199) ※2|20 (C200 – C219) ※1|15 (C220 – C234) ※2
23
24 ※1, Non-latched area, it could be changed to latched area by parameter setting.
25
26 ※2, Latched area, it could be changed to non-latched area by parameter setting.
27
28 ※3, The non-latched or latched feature couldn’t be changed.
29
30 == 16bit up counter ==
31
32 16bit counters: 1 to +32,767, as below picture shows, the current value of the counter increases each time coil C0 is turned ON by X2. The output contact is activated when the coil is turned ON for the tenth time.
33
34 After this, the counter data remains unchanged when X2 is turned ON. The counter current value is reset to ‘0’ (zero) when the RST instruction is executed by turning ON X1 in the example. The output contact Y0 is also reset at the same time.
35
36 [[image:Counter_html_6a9de07b6f12e71d.jpg]]
37
38 Figure 2
39
40
41 == 32bit bi-directional counter ==
42
43 32bit bi-directional counters: -2,147,483,648 to +2,147,483,647. C200- 219 are general, C220- 234 are latched.
44
45 The counting direction is designated with special auxiliary relays M8200 to M8234. When the special auxiliary relay is ON, it is decremented; otherwise, it is counting up.
46
47 = **High speed counter** =
48
49 Although counters C235 to C255 (21 points) are all high speed counters, they share the same range of high speed inputs. Therefore, if an input is already being used by a high speed counter, it couldnot be used for any other high speed counters or for any other purpose, i.e as an interrupt input.
50
51 The selection of high speed counters is not free, they are directly dependent on the type of counter required and which inputs are available.
52
53 * Available counter types
54
55 1. 1 phase with user start/reset: C235 to C240
56 1. 1 phase with assigned start/reset: C241 to C245
57 1. 2 phase bi-directional: C246 to C250
58 1. A/B phase type: C251 to C255
59
60 Different types of counters could be used at the same time but their inputs must not coin-cider. Inputs X0 to X7 couldnot be used for more than one counter.
61
62 Table 3
63
64 [[image:1648190996682-895.png]]
65
66 U: up counter input
67
68 D: down counter input
69
70 R: reset counter (input)
71
72 S: start counter (input)
73
74 A: A phase counter input
75
76 B: B phase counter input
77
78 * (((
79 === 1 phase ===
80 )))
81
82 [[image:Counter_html_20e36c879544fdc9.jpg]]
83
84 Figure 4
85
86
87 As above program shows, C244 is 1 phase high speed counter with start, stop and reset functions. From the table, X1~~X6 are for start and reset. C244 start counting when X12 and X6 are turned ON, the counter input terminal is X0, set value for C244 is determined by D0 (D1), so C244 could be reset by X0 or X11.
88
89 * (((
90 === 2 phase ===
91 )))
92
93 [[image:Counter_html_7a74379be7238b88.jpg]]
94
95 Figure 5
96
97 C251~~C255 are 2 phase (AB phase) high speed counter. As above (b) picture shows, C251 counts according from X0 (A phase) and X1 (B phase), when X14 is turned ON. C251 is reset when X13 is turned ON.
98
99 While A phase is turned ON, if B changes state from OFF to ON, C251 executes up count operation. While A phase is turn ON, if B changes state from ON to OFF, C251 executes down count operation. According to this principle, C251 executes up count operation while machine forward, and C251 executes down count operation while machine reverse. The M8251 monitors the C251's up / down counting status, OFF is for up counting, ON is for down counting.
100
101 === Output Y: high speed pulse output transistor ===
102
103 * It supports up to 4 channels, and each channel maximum output frequency is 200K;
104 * The output frequency could be used for controlling inverter, stepper and servo motors and so on;
105
106 === Input X: one phase ===
107
108 * X0, X1 hardware counters (C235, C236, C246), could support 200K pulse input at the same time;
109 * X0, X1 software counters (C241, C244, C247, C249), could support the input of 100K pulses at the same time;
110 * The hardware counter could be switched to software counting using HSCS, HSCR, HSZ instructions;
111 * The last four X points are software counting, which could support the input of 10K pulses at the same time.
112
113 === Input X: A/B phase ===
114
115 * X0, X1 hardware counter (C251), can support 100K pulse input;
116 * X0, X1 software counters (C252, C254) support the simultaneous input of 50K pulses at the same time;
117 * Hardware counter can be switched to software counter, using HSCS, HSCR, HSZ instructions;
118 * The remaining X points are counted by software, and each 5K pulse frequency can be input at the same time;
119 * There are two frequency modes for 2 phase 2 input, one is 2 times, and the other is 4 times, as following table shows, users select mode in D8200;
120
121 Table 6
122
123 |**Value in D8200**|**Count icon**
124 |(((
125 K2
126
127 (two times)
128 )))|[[image:Counter_html_a597a62d6ef2ee7a.jpg]]
129 |(((
130 K4 or others
131
132 (four times)
133
134 (default)
135 )))|[[image:Counter_html_9dd3228118070445.jpg]]
136
137 //**Note:**//
138
139 //**HSCS, HSCR and HSCZ couldn’t be used with Frequency multiplication**//
140
141 //**Program example1:**//
142
143
144 If X0 input pulse number >=800,The Y0 will set ON.
145
146 X6 means reset C235.
147
148 X7 means reset Y0.
149
150 You also could use M register instead of X registers.(M is a auxiliary register
151
152 (% class="box errormessage" %)
153 (((
154 Note:Wecon PLC X input need power DC24V signal.X0 and X1 support upto 200KHZ.X2~-~-~-~--X5 upto 10K.
155 )))
156
157 [[image:1626431834491-106.png]]
158
159
160 //**Program example2: AB encoder**//
161
162 [[image:1626432301371-762.png]]
163
164
165 [[image:1626432106931-488.png||height="354" width="745"]]
166
167 [[image:1626431992356-361.png]]