Feature: Embedded design
Figure 3: Output waveform, as seen on an oscilloscope
to generate a sine wave with a frequency of 1kHz and an amplitude of 2.5V; see Figure 2. Te program demonstrates the simplicity of generating a waveform using the UNO R4 series together with the built-in DAC. Figure 2 shows the program listing. At the beginning of the
program, AnalogWave header file is included in the program and the frequency is set to 1kHz (100Hz). Te amplitude multiplier is set to 0.5 so that the peak-to-peak amplitude of the generated waveform will be 5 × 0.5 = 2.5V (notice that the DAC reference voltage is not exactly +5V, it is slightly lower). Inside the setup() function, the amplitude is set and sine
waveform is generated. Figure 3 shows the waveform on a digital oscilloscope. In this figure, the vertical scale was 1V/division, and the horizontal scale was 500μs/division. Te frequency is 1kHz, and the amplitude is about 2.5V, as expected.
// ========================================== //
// Tis program generates sine wave with frequency 1 kHz and amplitude 2.5 V //
// Author: Sami Spiteri // File : Sinewave // Date
: July, 2025
//=========================================== #include "analogWave.h"
analogWave wave(DAC); int freq = 1000;
float amplitude = 0.5;
void setup() {
wave.amplitude(amplitude); // Set Amplitude
wave.sine(freq);
} void loop() { }
Figure 2: Program listing
Notice that in the above program, the default DAC resolution of 8 bits was used. Te DAC resolution can be changed to 12 bits to improve the waveform:
void setup() { analogWriteResolution(12); // Change to 12-bits
wave.amplitude(amplitude); // Set Amplitude
wave.sine(freq); }
// Generate sine wave
// Set freq = 1 kHz // Set Amplitude multiplier
// Generate sine wave
www.electronicsworld.co.uk December 2025/January 2026 33
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46 |
Page 47 |
Page 48