ESP32 DAC Waveform Generation Distorted
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 DAC Waveform Generation Distorted. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 DAC produces distorted or incorrect sine/triangle waves for signal generation.
Quick Fix
Wrong
for (int i = 0; i < 256; i++) {
dacWrite(25, sin(i * 2 * PI / 256) * 127 + 128);
delay(1); // Inconsistent timing
Waveform is jittery and frequency is inaccurate.
Right
const int freq = 440;
const int tableSize = 256;
uint8_t sineTable[tableSize];
for (int i = 0; i < tableSize; i++) {
sineTable[i] = (sin(i * 2 * PI / tableSize) + 1) * 127;
}
// Use timer or I2S for accurate timing, not delay()
ledcSetup(0, 80000, 8); // 80 kHz PWM -> audio DAC
Clean 440 Hz sine wave on oscilloscope (using I2S DAC).
Prevention
Precompute waveform tables for consistent output. Use I2S peripheral for accurate timing. Use DMA for continuous waveform output. Apply anti-aliasing filter on output. Use timer interrupts for accurate sample rates.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro