From cc52029d14a623922a8622eade9bd53f20e71458 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Thu, 27 Sep 2018 17:55:29 +0800 Subject: [PATCH 1/2] Updated sigma-delta example description to the latest template --- examples/peripherals/sigmadelta/README.md | 72 +++++++++++++++++-- .../sigmadelta/main/sigmadelta_example_main.c | 2 +- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/examples/peripherals/sigmadelta/README.md b/examples/peripherals/sigmadelta/README.md index 669e65a0e5..ab830f83ca 100644 --- a/examples/peripherals/sigmadelta/README.md +++ b/examples/peripherals/sigmadelta/README.md @@ -1,7 +1,71 @@ -# Example: sigma_delta modulation +# Sigma Delta Modulation Example -This example uses the sigma-delta driver to generate modulated output on a GPIO. +(See the README.md file in the upper level 'examples' directory for more information about examples.) -By default the GPIO output is 4, however you can edit this in the `sigmadelta_init()` function inside `main/sigmadelta_test.c`. +This example uses the sigma-delta driver to generate modulated output on a GPIO. If you connect a LED to the output GPIO, you will see it slowly brightening and dimming. -If you connect a LED to the output GPIO, you will see it blinking slowly. + +## How to use example + +### Hardware Required + +Besides the ESP32 board you need a LED and a resister to limit the LED current. Connect them as below: + +``` + 330R LED +GPIO4 +----/\/\/\----+------|>|-----+ GND +``` + +A resistor in range from 100 Ohm to 1 kOhm should usually be fine. + +By default the GPIO output is 4. To change it, edit the line with `GPIO_NUM_4` in `sigmadelta_init()` function inside `main/sigmadelta_test.c`. For example to use GPIO 25, modify the line to contain `GPIO_NUM_25` instead. + + +### Configure the project + +``` +make menuconfig +``` + +Set serial port under Serial Flasher Options and save the configuration. + + +### 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-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +Once the upload is complete and the board is reset, the program should start running. This is reported on the monitor as below: + +``` +... +I (275) cpu_start: Pro cpu start user code +I (293) cpu_start: Starting scheduler on PRO CPU. +I (0) cpu_start: Starting scheduler on APP CPU. +``` + +Immediately after that the LED should start brightening and dimming. + + +## Troubleshooting + +If you are using [ESP-WROVER-KIT](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) then this board has a RGB LED already installed. GPIO4 is driving blue color of the LED. The brightening and dimming effect of the blue LED may not be distinctly visible because red and green LEDs are not actively driven and will slightly lit. To resolve this issue you can switch both diodes off by adding the following code at the end of `sigmadelta_example_init()` function: + +```c +gpio_pad_select_gpio(GPIO_NUM_0); +gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT); +gpio_set_level(GPIO_NUM_0, 0); + +gpio_pad_select_gpio(GPIO_NUM_2); +gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT); +gpio_set_level(GPIO_NUM_2, 0); +``` diff --git a/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c b/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c index 594dbdb0c4..38bf2c0991 100644 --- a/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c +++ b/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c @@ -26,7 +26,7 @@ static void sigmadelta_example_init(void) .channel = SIGMADELTA_CHANNEL_0, .sigmadelta_prescale = 80, .sigmadelta_duty = 0, - .sigmadelta_gpio = 4, + .sigmadelta_gpio = GPIO_NUM_4, }; sigmadelta_config(&sigmadelta_cfg); } From bce5d7ba0195b2a17f259f184f058bca95546140 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Fri, 28 Sep 2018 10:41:46 +0800 Subject: [PATCH 2/2] Implemented the first round of review comments --- examples/peripherals/sigmadelta/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/peripherals/sigmadelta/README.md b/examples/peripherals/sigmadelta/README.md index ab830f83ca..23af6cf8de 100644 --- a/examples/peripherals/sigmadelta/README.md +++ b/examples/peripherals/sigmadelta/README.md @@ -9,14 +9,14 @@ This example uses the sigma-delta driver to generate modulated output on a GPIO. ### Hardware Required -Besides the ESP32 board you need a LED and a resister to limit the LED current. Connect them as below: +Besides the [ESP32 development board](https://www.espressif.com/en/products/hardware/development-boards) you need a LED and a resistor to limit the LED current. Connect them as below: ``` 330R LED GPIO4 +----/\/\/\----+------|>|-----+ GND ``` -A resistor in range from 100 Ohm to 1 kOhm should usually be fine. +A resistor in range from 100 Ohm to 1 kOhm should usually be fine. You may use ESP32 development board by other vendors as well, provided they have at least one GPIO output pin exposed. By default the GPIO output is 4. To change it, edit the line with `GPIO_NUM_4` in `sigmadelta_init()` function inside `main/sigmadelta_test.c`. For example to use GPIO 25, modify the line to contain `GPIO_NUM_25` instead. @@ -58,7 +58,7 @@ Immediately after that the LED should start brightening and dimming. ## Troubleshooting -If you are using [ESP-WROVER-KIT](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) then this board has a RGB LED already installed. GPIO4 is driving blue color of the LED. The brightening and dimming effect of the blue LED may not be distinctly visible because red and green LEDs are not actively driven and will slightly lit. To resolve this issue you can switch both diodes off by adding the following code at the end of `sigmadelta_example_init()` function: +If you are using [ESP-WROVER-KIT](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) then this board has an RGB LED already installed. GPIO4 is driving blue color of the LED. The brightening and dimming effect of the blue LED may not be distinctly visible because red and green LEDs are not actively driven by this example and will slightly lit. To resolve this issue you can switch both diodes off by adding the following code at the end of `sigmadelta_example_init()` function: ```c gpio_pad_select_gpio(GPIO_NUM_0);