You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
explicitESP32HWEncoder(int pinA, int pinB, int32_t ppr, int pinI=-1);
32
+
33
+
voidinit() override;
34
+
intneedsSearch() override;
35
+
inthasIndex();
36
+
floatgetSensorAngle() override;
37
+
voidsetCpr(int32_t ppr);
38
+
int32_tgetCpr();
39
+
voidsetStepDirMode();
40
+
voidsetQuadratureMode();
41
+
bool initialized = false;
42
+
43
+
Pullup pullup; //!< Configuration parameter internal or external pullups
44
+
45
+
46
+
47
+
protected:
48
+
49
+
50
+
void IRAM_ATTR indexHandler();
51
+
52
+
bool indexFound = false;
53
+
54
+
int _pinA, _pinB, _pinI;
55
+
56
+
pcnt_config_t pcnt_config;
57
+
58
+
int16_t angleCounter; // Stores the PCNT value
59
+
int32_t angleOverflow; // In case the PCNT peripheral overflows, this accumulates the max count to keep track of large counts/angles (>= 16 Bit). On index, this gets reset.
60
+
int32_t angleSum; // Sum of Counter and Overflow in range [0,cpr]
61
+
62
+
int32_t cpr; // Counts per rotation = 4 * ppr for quadrature encoders
This encoder driver uses the ESP32´s dedicated pulse counter hardware to efficiently count the AB(I) signals of an encoder. It also supports a Step/Dir-type mode.
4
+
5
+
Because most of the counting is done by the peripheral, it should support much higher speeds in comparison to the generic interrupt-based encoder implementation provided in the main library.
6
+
The PCNT peripheral can count at several MHz and should not be a limiting factor here.
7
+
8
+
You can use encoders with cpr of up to 31 bits. (At this resolution, you would get about 100 counts per second if you mounted such a sensor on the earths rotational axis. Thats plenty ;-) )
9
+
10
+
11
+
## Status
12
+
13
+
Seems to work fine! Step/Dir mode is untested.
14
+
15
+
## Hardware Setup
16
+
17
+
You can connect the encoder to any digital input pin of the ESP32, as they all support the PCNT peripheral.
18
+
19
+
## Configuration
20
+
21
+
This is a near drop-in replacement for the standard encoder class:
0 commit comments