Skip to content

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.
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

### Can ESP32 generate audio waveforms?

Yes. Use the I2S peripheral with DAC for audio output. ESP32 can generate up to 44.1 kHz sample rate with 8-bit resolution.

What is the maximum DAC update rate?

Software dacWrite() is limited to ~100 kHz. Use I2S + DMA for up to 5 MHz effective update rate.

Do I need a low-pass filter?

Yes. The DAC output has high-frequency switching noise. A simple RC low-pass filter (1 kOhm + 100 nF) cleans the signal.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro