Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 333 of 9364. Peripheral Interfacing and ControlFree lesson

Generating Periodic Waveforms via Lookup Table Techniques

Students will populate memory-mapped lookup tables to efficiently synthesize sine, triangle, and sawtooth signals through sequential digital-to-analog data updates.

Generating Periodic Waveforms via Lookup Table Techniques

In this lesson, you will learn how to synthesize complex, periodic analog signals by pre-calculating waveforms into memory-mapped arrays and streaming them to a DAC.

Calculating trigonometric functions like sin() or complex slope math in real-time is computationally expensive and can introduce jitter if your execution time varies. Instead, we use a Lookup Table (LUT)—a fixed array stored in memory that contains the pre-calculated digital values representing one full cycle of a waveform.

The Mechanism

To generate a waveform, you create an array of integers where each element corresponds to a specific point on the signal's amplitude curve. For a sine wave, you would store values representing 0 to 2π radians. To output the signal, your program simply iterates through this array index-by-index and writes the value to the DAC’s data register.

Because you have already mastered DMA (Direct Memory Access), you can offload this task entirely. Instead of using the CPU to step through the array, you configure the DMA controller to continuously transfer data from your memory-mapped LUT to the DAC peripheral register at a fixed frequency set by a hardware timer.

Example: Defining a Sine LUT

If your DAC has a 12-bit resolution (0–4095), you might define a 64-sample sine LUT like this:

// Pre-calculated 12-bit sine values
const uint16_t sine_lut[64] = {
    2048, 2248, 2447, 2642, 2831, 3011, 3180, 3336, 
    // ... remaining 56 values
};

By pointing your DMA controller to the start address of sine_lut, the peripheral will automatically pulse the DAC at the rate dictated by your hardware trigger. Changing the frequency of your waveform is as simple as adjusting the frequency of the trigger source (e.g., a timer’s update event), rather than changing the table itself. This technique provides a perfectly stable, high-fidelity signal without taxing your processor.

Key Takeaway: By pre-calculating waveform data into a memory-mapped lookup table and automating the transfer via DMA, you shift the burden of signal synthesis from the CPU to the hardware, ensuring jitter-free, periodic output.