|
|
@@ -1,13 +1,13 @@
|
|
|
| Supported Targets | ESP32 |
|
|
|
| ----------------- | ----- |
|
|
|
|
|
|
-# Wave generator Example
|
|
|
+# Wave Generator Example
|
|
|
|
|
|
-(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
|
|
+(See the README.md file in the upper level 'examples' directory for more information about examples)
|
|
|
|
|
|
This example demonstrates how to implement a software controlled signal generator by utilizing the DAC and Timer Group drivers. All waveforms demonstrated in this example are generated by software.
|
|
|
|
|
|
-Users can connect DAC output channel to their devices and use it as an simple analog signal output source.
|
|
|
+Users can connect DAC output channel to their devices and use it as a simple analog signal output source.
|
|
|
|
|
|
## How to use this example
|
|
|
|
|
|
@@ -15,82 +15,76 @@ Users can connect DAC output channel to their devices and use it as an simple an
|
|
|
|
|
|
* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
|
|
|
* A USB cable for power supply and programming
|
|
|
-* A bunch of cables
|
|
|
-* Target device
|
|
|
+* Target device or oscilloscope (not required)
|
|
|
|
|
|
-Make sure DAC output pin which is GPIO25 if channel 1 set, GPIO26 if channel 2 set, be connected to target device correctly.
|
|
|
+Make sure the DAC output pin (which is the GPIO25 if channel 1 set, GPIO26 if channel 2 set) is connected to the target device correctly.
|
|
|
|
|
|
### Configure the project
|
|
|
-Under example folder, right click and select 'open terminal here'
|
|
|
|
|
|
-Execute following statements in terminal:
|
|
|
+Open the project configuration menu (`idf.py menuconfig`).
|
|
|
|
|
|
-```
|
|
|
-idf.py menuconfig
|
|
|
-```
|
|
|
-
|
|
|
-In `Example Configuration`, set the following options:
|
|
|
-
|
|
|
-#### DAC channel Num
|
|
|
+In the `Example Configuration` menu:
|
|
|
|
|
|
-ESP32 DAC contains two channels:
|
|
|
- * **DAC_CHANNEL_1 (GPIO25), selected by default.**
|
|
|
- * DAC_CHANNEL_2 (GPIO26)
|
|
|
-
|
|
|
-#### Wave form
|
|
|
-
|
|
|
-This example demonstrates one of the following waveforms:
|
|
|
-* **Sine, selected by default.**
|
|
|
-* Triangle
|
|
|
-* Sawtooth
|
|
|
-* Square
|
|
|
+* Use `DAC Channel Num` to select the DAC number.
|
|
|
+* Use `Waveform` to select the waveform type.
|
|
|
+ * Select `Sine` (*default*), `Triangle`, `Sawtooth` or `Square` wave type.
|
|
|
+* Select `Wave frequency` from the available range.
|
|
|
+* Set the `Enable output voltage log` if you want to print the log in the terminal.
|
|
|
|
|
|
#### Wave frequency
|
|
|
|
|
|
-About this option:
|
|
|
-
|
|
|
-This signal generator has a range of frequency is 1kHz to 17kHz. **3kHz selected by default.**
|
|
|
+For this example, the range of frequency is from 1 kHz to 17 kHz. **3 kHz is selected by default.**
|
|
|
|
|
|
-Modify the frequency will change the number of DAC output points. That will affect the smoothness of curve as well. Those output points are used to calculate the raw value(0~255) of each output point. All of these raw value are stored in an array.
|
|
|
+If you modify the frequency, you will change the number of DAC output points. This will affect the smoothness of the curve as well.
|
|
|
+Each output point value is calculated by the DAC resolution of 8-bits (0~255). All of these raw values are stored in an array.
|
|
|
|
|
|
-Based on the given frequency, the number of DAC output points for each cycle can be caluculated by following formula:
|
|
|
+Based on the given frequency, the number of DAC output points for each cycle can be calculated through the following formula:
|
|
|
```num_of_output_points = 1000000(us)/(7 us * frequency)```
|
|
|
|
|
|
-For example, with high frequency, 20kHz will results in generating only 10 output points, the curve will be sharp and zigzag.
|
|
|
+For example, with high frequency, 20 kHz will generate only 10 output points; the curve will be edgy.
|
|
|
|
|
|
-On the contrary, 500 Hz, low frequency relatively, will results in many DAC output points and the array cannot stores so many values that it will causes array overboundary.
|
|
|
+On the other hand, 500 Hz, a relative low frequency, will result in many DAC output points and the array will not be able to store all of the generated data.
|
|
|
|
|
|
-In short, there will be less output points per cycle in higher frequency, and more points in lower frequency.
|
|
|
+Thus, there will be less output points per cycle in higher frequency, and more points in lower frequency.
|
|
|
|
|
|
-After got the raw value, the real output voltage can be calculated through following formula (VDD is 3.3V):
|
|
|
+After the raw value calculation, the real output voltage can be converted through the following formula (VDD is 3.3 V):
|
|
|
|
|
|
```points_voltage = (VDD * DAC_OUTPUT / 255)```
|
|
|
|
|
|
-The voltage is in range of 0~3300mV.
|
|
|
+The voltage is within the range of 0~3300 mV.
|
|
|
|
|
|
#### Enable output voltage log
|
|
|
|
|
|
**Disabled selected by default.**
|
|
|
|
|
|
-If enabled, expected voltage of each points will be shown in terminal. It's intuitive for debugging and testing. If output example is needed, read **Example Output** chapter below.
|
|
|
+If enabled, the expected voltage of each point will be printed on the terminal.
|
|
|
|
|
|
### Build and Flash
|
|
|
-After configure step is done, build project and flash it to the board:
|
|
|
|
|
|
-```
|
|
|
-$ idf.py -p PORT flash monitor
|
|
|
-```
|
|
|
+Build the project and flash it to the board, then run the monitor tool to view the serial output:
|
|
|
+
|
|
|
+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.
|
|
|
+See the Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects.
|
|
|
+
|
|
|
+* [ESP-IDF Getting Started Guide on ESP32](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html)
|
|
|
|
|
|
## Example Output
|
|
|
-If oscilloscope is available, the target wave will show on oscilloscope after running this example.
|
|
|
|
|
|
-Additionally, if more specific output voltage information is needed, run menuconfig and set "Enable print output voltage" to "Enabled". Then, more information will show as log in terminal.
|
|
|
+If an oscilloscope is available, the target wave will be displayed in it after running this example.
|
|
|
|
|
|
-For example, set wave frequency, waveform to 3kHz and sine respectively, and also enable print output voltage option. The output information will show in log in terminal as following:
|
|
|
+#### Sine:
|
|
|
+
|
|
|
+#### Triangle:
|
|
|
+
|
|
|
+#### Sawtooth:
|
|
|
+
|
|
|
+#### Square:
|
|
|
+
|
|
|
+
|
|
|
+The output log will be shown in the terminal as the following (if `Enable output voltage log` is enabled):
|
|
|
|
|
|
```
|
|
|
I (318) Wave generator: DAC output channel: 1
|
|
|
@@ -112,4 +106,7 @@ I (1338) Wave generator: Output voltage(mV): 3183
|
|
|
....
|
|
|
|
|
|
```
|
|
|
-`Output voltage` in log means real voltage, in mV, which is output through GPIO by device.
|
|
|
+
|
|
|
+## Troubleshooting
|
|
|
+
|
|
|
+For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|