User Tools

Site Tools


tonegen_design

This is an old revision of the document!


Design Notes for the Verilog Tone Generator

This page is a collection of design notes for the tone generator peripheral. The notes are not in any particular order but the last section is always about current design problems and next steps.

Phase Accumulators

A common digital technique to generate very specific frequencies is to use what is called phase accumulation. The idea of a phase accumulator is to add a fraction of a cycle to the phase on each clock edge such that the accumulated phase reaches one (one full cycle) at the right time.

Let's use an example that is specific to this design. Let's say our audio update rate is 100 KHz. This gives use 10 microseconds per audio sample to the output DAC. The note C0 is 16.35 Hertz. In one sample a C0 note will change its phase by

  (16.35 / 100000) = 0.0001635 cycle

This is 0.000000000000101010110111 as a binary fraction, and this is what we would add to the accumulator every 10 microseconds to get 16.35 Hz output. Showing the phase offset as binary helps get across the idea that a hundredth of a cycle at 16.35 Hertz needs 24 bits of precision.

The FPGA never sees the note C0 or the frequency. All it sees is the phase offset per sample and this is set by a look-up table in the host. Feeding the MSB of the phase accumulator to an output pin is a minimal tone generator.

Wave Tables

A wave table captures a waveform by dividing it into slices and recording the output value for each slice. If the address decoder has N bits then the length of the table is 2^^N. A wave table is usually driven by the N high bits of a phase accumulator.

The number of bits in each word determine the audio fidelity of the output. The values in the table are often a log-base-2 of the desired value. Human hearing is such that perceived volume follows a logarithmic scale, and using log value makes subsequent gain and modulations easier since multiplication in a log scale is just addition. You can get the best fidelity from the least number of bits by making the waveform span the full range of M bits.

There are often more than one wave table and while they may have a default, all can be set from the host. The API is to be determined but might appear something like:

  dpset tonegen table_id 3      # select the table to download
  dpset tonegen table_addr 0    # point to first address in table
  dpset tonegen table_val 00 12 34 56 78 9a 87 56 78 88 99 aa bb cc dd ee
  dpset tonegen table_val ff ee ff ee ff ee ff ee ff ee ff ee ff ee ff ee
  (... for all 2^^N values ...)
tonegen_design.1647059634.txt.gz · Last modified: 2022/03/12 04:33 by dpisuperadmin