Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
.gitignore
Makefile
README.md
cordic.v
mymap.m
pdmdemo.cpp
showspectrogram.m
testb.h
toplevel.v
traditionalpwm.v
vversion.sh

README.md

A demonstration of the Improved PWM waveform

This directory contains the files necessary to build a demonstration of the improved PWM waveform used in this repository. The demonstration is designed to work both in a Verilator based simulation (pdmdemo.cpp), as well as with a board having a single PMod AMP2, switch, LED, and a 100MHz clock input.

The toplevel Verilog file should be easily recognizable as toplevel.v. This contains the cordic.v component to generate a sine wave as the test signal, as well as components to turn this test signal into both a traditional PWM output as well as the improved version found within this repository. The toplevel design will either output a 440 Hz tone, or a swept tone running from 110Hz to about 27.3kHz, depending upon which part of the test sequence is being run.

The DEF_RELOAD parameter within toplevel.v can be used to adjust the PWM interval for the traditional PWM, or sample interval for the improved version. Likewise, when run on actual hardware, the switch input will control which waveform is produced--either the traditional PWM or the improved waveform.

These files can also be composed within a Verilator based simulation. In this case pdmdemo.cpp forms the main simulation component. A boolean value within it, traditional_pwm, can be used to control whether or not the file downsamples and outputs a traditional PWM signal or the improved version. Likewise, there's a commented line that you can use to generate a VCD file which can be used to view traces of the logic within this demo. This demonstration file will also produce a file of 64-bit doubles (overkill, I know) containing downsampled audio samples at 44.1kHz. This audio file, named wavfp.dbl, can be processed within Octave by using showspectrogram, to view a spectrogram of the data.

If you take the time to run the simulation, you'll clearly see that the improved PWM waveform is much cleaner: it doesn't include unwanted harmonics, nor does it include any artificial features (beyond any expected aliasing products, present in both). The traditional PWM waveform, on the other hand, cannot seem to be able to produce a clear tone without also creating unwanted harmonics. This effect is only worsened when the PWM period is within hearing range, such as when the period is the reciprocal of 8kHz.