2018-06-29 06:48:57 -04:00
# PCNT Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
2016-12-21 20:18:15 -05:00
2017-09-22 12:42:17 -04:00
This example uses the pulse counter module (PCNT) to count the rising edges of the PWM pulses generated by the LED Controller module (LEDC).
2016-12-21 20:18:15 -05:00
2018-06-29 06:48:57 -04:00
## How to use example
2016-12-21 20:18:15 -05:00
2018-06-29 06:48:57 -04:00
### Hardware Required
2016-12-21 20:18:15 -05:00
2018-06-29 06:48:57 -04:00
* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A USB cable for power supply and programming
2016-12-21 20:18:15 -05:00
2018-06-29 06:48:57 -04:00
Pin connection:
2016-12-21 20:18:15 -05:00
2018-06-29 06:48:57 -04:00
* GPIO4 is the default output GPIO of the 1 Hz pulse generator.
* GPIO18 is the default pulse input GPIO. We need to short GPIO4 and GPIO18.
* GPIO5 is the default control signal, which can be left floating with internal pull up, or connected to Ground (If GPIO5 is left floating, the value of counter increases with the rising edges of the PWM pulses. If GPIO15 is connected to Ground, the value decreases).
2017-09-22 12:42:17 -04:00
2018-06-29 06:48:57 -04:00
### Configure the project
2017-09-22 12:42:17 -04:00
2018-06-29 06:48:57 -04:00
```
2019-08-01 23:31:20 -04:00
idf.py menuconfig
2018-06-29 06:48:57 -04:00
```
2017-09-22 12:42:17 -04:00
2018-06-29 06:48:57 -04:00
* Set serial port under Serial Flasher Options.
2017-09-22 12:42:17 -04:00
2018-06-29 06:48:57 -04:00
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
2019-08-01 23:31:20 -04:00
idf.py -p PORT flash monitor
2018-06-29 06:48:57 -04:00
```
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
Run this example, and you can see the following output log on the serial monitor:
(Here, GPIO5 is connected to Ground)
2017-09-22 12:42:17 -04:00
```
Current counter value :-1
Current counter value :-2
Current counter value :-3
Current counter value :-4
Event PCNT unit[0]; cnt: -5
THRES0 EVT
Current counter value :-5
Current counter value :-6
Current counter value :-7
Current counter value :-8
Current counter value :-9
Event PCNT unit[0]; cnt: 0
L_LIM EVT
ZERO EVT
Current counter value :0
Current counter value :-1
...
```
2018-06-29 06:48:57 -04:00
## Troubleshooting
* program upload failure
2019-08-01 23:31:20 -04:00
* Hardware connection is not correct: run `idf.py -p PORT monitor` , and reboot your board to see if there are any output logs.
2018-06-29 06:48:57 -04:00
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
For any technical queries, please open an [issue ](https://github.com/espressif/esp-idf/issues ) on GitHub. We will get back to you soon.