README.md
1| Supported Targets | ESP32 | ESP32-S2 |
2| ----------------- | ----- | -------- |
3
4# Pulse Count Event Example
5
6(See the README.md file in the upper level 'examples' directory for more information about examples.)
7
8This example uses the pulse counter module (PCNT) to count the rising edges of the PWM pulses generated by the LED Controller module (LEDC).
9
10## How to use example
11
12### Hardware Required
13
14* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
15* A USB cable for power supply and programming
16
17Pin connection:
18
19* GPIO4 is the default output GPIO of the 1 Hz pulse generator.
20* GPIO18 is the default pulse input GPIO. We need to short GPIO4 and GPIO18.
21* 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 GPIO5 is connected to Ground, the value decreases).
22
23### Configure the project
24
25```
26idf.py menuconfig
27```
28
29### Build and Flash
30
31Build the project and flash it to the board, then run monitor tool to view serial output:
32
33```
34idf.py -p PORT flash monitor
35```
36
37(To exit the serial monitor, type ``Ctrl-]``.)
38
39
40See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
41
42## Example Output
43
44
45Run this example, and you can see the following output log on the serial monitor:
46(Here, GPIO5 is connected to Ground)
47
48```
49Current counter value :-1
50Current counter value :-2
51Current counter value :-3
52Current counter value :-4
53Event PCNT unit[0]; cnt: -5
54THRES0 EVT
55Current counter value :-5
56Current counter value :-6
57Current counter value :-7
58Current counter value :-8
59Current counter value :-9
60Event PCNT unit[0]; cnt: 0
61L_LIM EVT
62ZERO EVT
63Current counter value :0
64Current counter value :-1
65...
66```
67
68## Troubleshooting
69
70* program upload failure
71
72 * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
73 * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
74
75For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
76