@@ -14,8 +14,8 @@ Example usage::
14
14
from machine import Pin, Encoder
15
15
16
16
qe = Encoder(Pin(0), Pin(1)) # create Quadrature Encoder object
17
- qe.position() # get current counter values
18
- qe.position (0) # Set all counters to 0
17
+ qe.value() # get current counter values
18
+ qe.value (0) # Set value and revolution to 0
19
19
qe.init(cycles=128) # Specify 128 cycles/revolution
20
20
qe.init(index=Pin(3)) # Specify Pin 3 as Index pulse input
21
21
qe.deinit() # turn off the Qudrature encoder
@@ -60,7 +60,6 @@ Constructors
60
60
value up to init + cycles - 1, and then reset to the init value and increase
61
61
the revolution counter by one. The default is: no cycles set. In that case the
62
62
position counter overflows at 2**32 - 1.
63
- - *init *\= value. Sets the init value. The defaults value is 0.
64
63
- *compare *\= value. Sets a position counter compare value. When the counter matches
65
64
this value, a callback function can called and the match output will get a high level.
66
65
@@ -78,20 +77,25 @@ Methods
78
77
Stops the Encoder, disables interrupts and releases the resources used by the encoder. On
79
78
Soft Reset, all instances of Encoder and Counter are deinitialized.
80
79
81
- .. method :: Encoder.position ([value])
80
+ .. method :: Encoder.value ([value])
82
81
83
- Get or set the current counters of the Encoder as unsigned integers, with the position
84
- counter being a 32 bit item, and the revolution and difference counters being 16 bit
85
- items.
82
+ Get or set the current position counter of the Encoder as unsigned 32 bit integer.
86
83
87
- With no arguments the actual counter values are returned. If a cycles value is set,
88
- the values are returned as a tuple consisting of the position counter, the
89
- revolution counter and the difference of the position counter since
90
- the previous reading. If a cycles values not set, the position is returned as an
91
- 48 bit unsigned integer of the total event count as **revolution \* 2\*\* 32 + position **.
84
+ With no arguments the actual position counter value is returned.
92
85
93
- With a single *value * argument the position counter is set to that value. If a cycles value
94
- is set, the revolution counter and difference counter are cleared.
86
+ With a single *value * argument the position counter is set to that value and the
87
+ revolution counter is cleared.
88
+
89
+ .. method :: Encoder.revolution([value])
90
+
91
+ Get or set the current revolution counter of the Encoder as signed 16 bit integer.
92
+
93
+ With no arguments the actual revolution counter value is returned.
94
+
95
+ W
8000
ith a single *value * argument the revolution counter is set to that value. The
96
+ position counter is not changed. A total position can be caluclated as
97
+ revolution() * cycles + position() + init. If the total position range is still
98
+ too small, you can create your own revolution counter using the irq() callback method.
95
99
96
100
.. method :: Encoder.compare([value])
97
101
@@ -161,8 +165,8 @@ Example usage::
161
165
from machine import Pin, Counter
162
166
163
167
counter = Counter(Pin(0)) # create Counter object
164
- counter.values() # get current counter value
165
- counter.values (0) # Set all counters to 0
168
+ counter.value() # get current counter value
169
+ counter.value (0) # Set the counter to 0
166
170
counter.deinit() # turn off the Counter
167
171
counter.init(compare=1000) # Set create a compare match event at count 1000
168
172
counter.irq(Counter.COMPARE, handler) # Call the function handler at a compare match
@@ -214,13 +218,26 @@ Methods
214
218
Stops the Counter, disables interrupts and releases the resources used by the encoder. On
215
219
Soft Reset, all instances of Encoder and Counter are deinitialized.
216
220
217
- .. method :: Counter.count ([value])
221
+ .. method :: Counter.value ([value])
218
222
219
- Get or set the current counter value of the Counter. The value is returned as a unsigned 48 bit
220
- integer.
223
+ Get or set the current event value of the Counter. The value is returned as an
224
+ unsigned 32 bit integer.
221
225
222
226
With a single *value * argument the counter is set to that value.
223
227
228
+ .. method :: Encoder.overflow([value])
229
+
230
+ Get or set the current revolution counter of the counter as signed 16 bit integer.
231
+ The value represents the overflow or underflow events of the 32bit basic counter.
232
+ A total count can be calculated as overflow() * 0x100000000 + count().
233
+ If the total count range is still too small, you can create your own overflow
234
+ counter using the irq() callback method.
235
+
236
+ With no arguments the actual overflow counter value is returned.
237
+
238
+ With a single *value * argument the overflow counter is set to that value. The
239
+ event counter is not changed.
240
+
224
241
.. method :: Counter.compare([value])
225
242
226
243
Get or set the counter compare value.
0 commit comments