This example demonstrates basic usage to configure and control the waveform generation process. Specifically, it shows how to set up the waveform generation system, initialize parameters, start the waveform output, and stop it. The methods demonstrated include configure(), start(), stop() and reset().
Before running this example, ensure you have:
- An ESP32 development board.
- ESP-IDF development environment set up (version 5.4 or later).
- Familiarity with the ESP-IDF DAC Continuous Signal Generator Example.
- An oscilloscope to visualize the waveform output.
-
Clone the repository:
git clone https://github.com/tinyalg/waveu.git
-
Change to this directory:
cd waveu/examples/start_n_stopAlternatively, open this directory in VSCode with the ESP-IDF extension for easier navigation and editing.
-
Run menuconfig:
In VSCode, open the ESP-IDF Terminal.
idf.py menuconfig
In
menuconfig, configure the following settings under[Component config > Waveu Configuration]:- Select active DAC channels:
- CH0 and CH1: Output to both channels.
- CH0 only: Output to DAC Channel 0.
- CH1 only: Output to DAC Channel 1.
To reproduce the figure in A Hands-On Approach to Designing Waveforms with Microcontrollers – Your Spare Oscilloscope in Action, ensure the following options are enabled:
- Enable debug output for waveform data generation on GPIO.
- Enable debug output for DAC transfer on GPIO.
- Select DAC channel working mode as Alternate mode (CH0 and CH1 alternate data from buffer)
- Select active DAC channels:
-
Flash the example:
idf.py build flash
-
Monitor the output:
idf.py monitor
You should observe messages in the console confirming the start and stop of waveform generation.
I (294) Waveu-ESP32Config: waveformDataOutputTask to on core 0 at priority 10. I (294) Waveu: LEN_DATA_BUFFER=16000, SAMPLE_RATE=1000000, TIMER_PERIOD=16000 I (294) Waveu: Started waveformDataGenerationTask on core 1 at priority 5. I (304) UserWaveConfig: Frequency set to 312.50Hz I (20374) UserWaveConfig: reset() called I (20374) UserWaveConfig: Waveform generation finished. I (20374) Waveu-ESP32Config: Stopping waveformDataOutputTask... I (20374) Waveu: Stopping waveformDataGenerationTask... -
Connect your oscilloscope: Attach the oscilloscope to the DAC output channel as configured in
menuconfig. Runidf.py monitoragain to see the output.
This example consists of the following key parts:
The example begins by initializing the Waveu instance.
tinyalg::waveu::ESP32Waveu<UserWaveConfig> waveu;Next, prepare arguments for configuration. In this example, a frequency value of 312.5 Hz is used.
UserWaveArgs waveArgs(312.5f);Then, configure Waveu with necessary arguments.
waveu.configure(waveArgs);Now, the start() method begins the waveform generation process.
waveu.start();The stop() method gracefully halts the waveform generation, ensuring output of the current data buffer.
waveu.stop();- Ensure the channel configuration is correctly set in
menuconfig. - Adjust the frequency parameter as needed to fit your application or testing scenario.