doc(pcnt): Update pcnt example README.md file.

This commit is contained in:
hou wen xiang 2018-06-29 18:48:57 +08:00 committed by kooho
parent ff71ea9202
commit 062c64fca0
2 changed files with 44 additions and 20 deletions

View file

@ -1,32 +1,48 @@
# Example: pcnt
# PCNT Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example uses the pulse counter module (PCNT) to count the rising edges of the PWM pulses generated by the LED Controller module (LEDC).
The examples is setting up and then using the following GPIO pins:
* GPIO18 - output pin of a sample 1 Hz pulse generator,
* GPIO4 - pulse input pin,
* GPIO5 - control input pin.
## How to use example
The configuration parameters of this example (pin numbers, etc.) may be modified at the top of the `main/pcnt_test.c` file.
### Hardware Required
## Run the Test
* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A USB cable for power supply and programming
1, Compile and load the example.
2. Open a serial port monitor to view the message printed out on your screen.
3. Connect GPIO18 with GPIO4.
4. GPIO5 is the control signal, you can leave it floating with internal pull up, or connect it to ground. If left floating, the count value will be increasing. If you connect GPIO5 to GND, the count will be decreasing.
Pin connection:
* 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).
### Configure the project
```
make menuconfig
```
* Set serial port under Serial Flasher Options.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
make -j4 flash monitor
```
(To exit the serial monitor, type ``Ctrl-]``.)
## Check Functionality
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
The example will print out the current counter values and events.
## Example Output
An interrupt will be triggered when the counter value:
* reaches 'thresh1' or 'thresh0' value,
* reaches 'l_lim' value or 'h_lim' value,
* will be reset to zero.
A sample output on the serial monitor:
Run this example, and you can see the following output log on the serial monitor:
(Here, GPIO5 is connected to Ground)
```
Current counter value :-1
@ -47,5 +63,12 @@ Current counter value :0
Current counter value :-1
...
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
* program upload failure
* Hardware connection is not correct: run `make monitor`, and reboot your board to see if there are any output logs.
* 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.

View file

@ -111,6 +111,7 @@ static void ledc_init(void)
ledc_channel.intr_type = LEDC_INTR_DISABLE;
ledc_channel.gpio_num = LEDC_OUTPUT_IO;
ledc_channel.duty = 100; // set duty at about 10%
ledc_channel.hpoint = 0;
ledc_channel_config(&ledc_channel);
}