Skip to content

About

Laboratory design files for digital signal generation with synthesizable code written in Verilog. Allows implementation design for the FPGA DE-10 Lite board.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

digital_lab — DDS Digital Signal Generator (DE‑10 Lite)

A Direct Digital Synthesis (DDS) signal generator in Verilog for the Terasic DE‑10 Lite (Intel MAX 10 10M50DAF484C7G), built to be probed with a Digilent Digital Discovery logic analyzer. Pick a frequency on the board's switches and the FPGA generates a reconstructed sine, a square at the same frequency, two octave divisions, a PWM output, and a pseudo‑random bit stream — all on the GPIO header, all visible at once in WaveForms.

A Paradox Transistor Lab project. The classic teaching question — how do you make a clean, tunable waveform with nothing but logic gates and a clock? — answered with a phase accumulator and a sine table.

What it generates

Everything is driven out of the DE‑10 Lite's JP1 GPIO header:

GPIO Signal Description
GPIO[7:0] Sine bus (8‑bit) Offset‑binary sine samples. Group the 8 lines as a bus in WaveForms to see a reconstructed sine. 256 samples per period at every frequency.
GPIO[8] Square @ f The DDS fundamental (phase accumulator MSB).
GPIO[9] f / 2 Octave divider of the square.
GPIO[10] f / 4 Two octaves down.
GPIO[11] PWM ~3 kHz, duty set by SW[9:6] (0…15⁄16).
GPIO[12] PRBS Pseudo‑random bit stream, 16‑bit maximal LFSR, ~97.7 kHz.

How DDS works

A 32‑bit phase accumulator is incremented every clock by a tuning word (FCW). The top 8 bits address a 256‑entry sine ROM, so the output frequency is set purely by how fast the phase rotates, not by a counter limit:

f_out = f_clk · FCW / 2^32          (f_clk = 50 MHz)

The accumulator's MSB is a square wave at f_out. Because the phase — not the sample count — sets the frequency, the sine always has 256 samples per period.

Frequency presets (SW[3:0])

SW[3:0] Target FCW (hex) Actual Error
0 100 Hz 0x0000218E 100.0008 Hz +7.6 ppm
1 500 Hz 0x0000A7C6 500.0038 Hz +7.6 ppm
2 1 kHz 0x00014F8B 999.996 Hz −4.0 ppm
3 2 kHz 0x00029F17 2000.004 Hz +1.8 ppm
4 5 kHz 0x00068DB9 5000.003 Hz +0.6 ppm
5 10 kHz 0x000D1B71 9999.995 Hz −0.5 ppm
6 20 kHz 0x001A36E3 20000.001 Hz +0.05 ppm
7 50 kHz 0x00418937 49999.997 Hz −0.07 ppm
8 100 kHz 0x0083126F 100000.005 Hz +0.05 ppm
9 500 kHz 0x028F5C29 500000.000 Hz ~0 ppm

The selected frequency in Hz is shown on HEX5…HEX0 (leading zeros blanked).

Controls

Control Function
KEY[0] Reset (active low — held = reset)
SW[3:0] Frequency preset 0…9
SW[9:6] PWM duty cycle
HEX5…HEX0 Selected frequency, Hz
LEDR[3:0] Preset index · LEDR[9] ≈ 0.75 Hz heartbeat

Repository layout

rtl/
  signal_gen_top.v   top level: presets, wiring, 7-seg readout, GPIO out
  dds.v              phase accumulator + sine ROM + square
  pwm_gen.v          counter PWM
  lfsr_prbs.v        16-bit maximal LFSR
  squarediv.v        octave dividers (f/2, f/4)
  bin2bcd.v          binary -> BCD (double dabble) for the display
  seg7.v             BCD digit -> seven-segment (active low)
sim/
  tb_signal_gen.v    smoke-test testbench (Icarus / ModelSim)
sine_rom256x8.hex    256 x 8-bit offset-binary sine table
sin_table_gen.c      generator for the sine table
signal_gen.qpf/.qsf  Quartus project (device + pins)
lab2/                the original 2019 4-bit sine lab (kept for reference)

Build and program (Quartus Prime)

  1. Open signal_gen.qpf in Quartus Prime (Lite is fine) — device is already set to 10M50DAF484C7G and all pins are assigned.
  2. Processing → Start Compilation.
  3. Tools → Programmer, select the USB‑Blaster (the board's USB), add output_files/signal_gen.sof, and Start to configure the FPGA over JTAG. (.sof is volatile; use Convert Programming File → .pof if you want it to survive a power cycle.)

The sine ROM is read with $readmemh("sine_rom256x8.hex", …), resolved relative to the project directory, so keep sine_rom256x8.hex next to the .qpf.

Wiring to the Digital Discovery

DE-10 Lite JP1 to Digital Discovery wiring: the 8-bit sine bus GPIO0-7 to DIN0-7, square to DIN8, f/2 and f/4 to DIN9 and DIN10, PWM to DIN11, PRBS to DIN12, and GND to GND

Connect the Digital Discovery flywires to the JP1 header and share a ground. Pin balls are the DE‑10 Lite standard; JP1 physical pins follow the Terasic User Manual (confirm against its JP1 diagram).

Signal FPGA pin JP1 header pin Suggested DD channel
Sine GPIO[0] (LSB) PIN_V10 1 DIN 0
Sine GPIO[1] PIN_W10 2 DIN 1
Sine GPIO[2] PIN_V9 3 DIN 2
Sine GPIO[3] PIN_W9 4 DIN 3
Sine GPIO[4] PIN_V8 5 DIN 4
Sine GPIO[5] PIN_W8 6 DIN 5
Sine GPIO[6] PIN_V7 7 DIN 6
Sine GPIO[7] (MSB) PIN_W7 8 DIN 7
Square GPIO[8] PIN_W6 9 DIN 8
f/2 GPIO[9] PIN_V5 10 DIN 9
GND — 12 DD ⏚ (GND)
f/4 GPIO[10] PIN_W5 13 DIN 10
PWM GPIO[11] PIN_AA15 14 DIN 11
PRBS GPIO[12] PIN_AA14 15 DIN 12

Levels: the DE‑10 Lite GPIO is 3.3 V. The Digital Discovery's logic threshold defaults to 1.8 V but is adjustable in WaveForms — set it to ~1.65 V (or the 3.3 V preset) and you're fine. Always connect at least one GND.

Viewing in WaveForms

  1. Logic Analyzer → add DIN 0‑7 and group them as a Bus, format Analog → it draws the reconstructed sine.
  2. Add DIN 8‑12 as single channels (square, f/2, f/4, PWM, PRBS).
  3. Trigger on a rising edge of the square (DIN 8) for a stable sine.
  4. Set the time base to a few periods of the frequency you picked on SW[3:0] and sweep SW[9:6] to watch the PWM duty change live.

Simulation

With Icarus Verilog (or ModelSim), from the repo root:

iverilog -g2005 -o /tmp/sg rtl/*.v sim/tb_signal_gen.v
vvp /tmp/sg          # prints RESULT: PASS and writes /tmp/tb_signal_gen.vcd

The testbench selects the 500 kHz preset and checks the sine bus spans 00…ff and that the square and PWM toggle. Open the VCD in GTKWave to see the waveforms.

Regenerating the sine ROM

cc sin_table_gen.c -o sin_table_gen -lm
./sin_table_gen -P 256 -N 8        # 256 points, 8-bit  -> sintable.hex
mv sintable.hex sine_rom256x8.hex

-P sets samples per period (= ROM depth, must match ADDR_W in dds.v: 2^ADDR_W), -N the amplitude bit width (= DATA_W and the sine bus width).

Bonus: a real analog output

The 8‑bit sine bus is also a DAC input. Wire GPIO[7:0] into an R‑2R ladder (or the board's VGA R‑2R, as the original lab2 did on VGA_R[3:0]) and you get an actual analog sine you can see on an oscilloscope — the digital staircase filtered into a smooth wave.


Built for the Paradox Transistor Lab YouTube channel by @Galaviz1. Hardware: Terasic DE‑10 Lite + Digilent Digital Discovery.

About

Laboratory design files for digital signal generation with synthesizable code written in Verilog. Allows implementation design for the FPGA DE-10 Lite board.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages