|
|
4 лет назад | |
|---|---|---|
| .. | ||
| components | 4 лет назад | |
| main | 5 лет назад | |
| CMakeLists.txt | 5 лет назад | |
| Makefile | 5 лет назад | |
| README.md | 5 лет назад | |
| Supported Targets | ESP32 | ESP32-S2 |
|---|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
The PCNT peripheral is designed to count the number of rising and/or falling edges of an input signal. Each PCNT unit has two channels, which makes it possible to extract more information from two input signals than only one signal. This example shows how to make use of the HW features to decode the differential signals generated from a common rotary encoder -- EC11.
The signals a rotary encoder produces (and what can be handled by this example) are based on a 2-bit gray code available on 2 digital data signal lines. The typical encoders use 3 output pins: 2 for the signals and one for the common signal usually GND.
Typical signals:
A +-----+ +-----+ +-----+
| | | |
| | | |
+-----+ +-----+
B +-----+ +-----+ +-----+
| | | |
| | | |
+-----+ +-----+
+--------------------------------------->
CW direction
Connection :
+--------+ +---------------------------------+
| | | |
| A +--------------+ GPIO_A (internal pull up) |
| | | |
+-------+ | | |
| | | GND +--------------+ GND |
+-------+ | | |
| | | |
| B +--------------+ GPIO_B (internal pull up) |
| | | |
+--------+ +---------------------------------+
Run idf.py -p PORT flash monitor to build, flash and monitor the project.
(To exit the serial monitor, type Ctrl-].)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
I (181323) example: Encoder value: 0
I (182323) example: Encoder value: 0
I (183323) example: Encoder value: -12
I (184323) example: Encoder value: -18
I (185323) example: Encoder value: -24
I (188323) example: Encoder value: 4
I (189323) example: Encoder value: 8
I (190323) example: Encoder value: 8
I (191323) example: Encoder value: 8
This example enables the 4X mode to parse the rotary signals, which means, each complete rotary step will result PCNT counter to increase/decrease by 4, depending on the direction of rotation.
For any technical queries, please open an issue on GitHub. We will get back to you soon.