1 |
4 |
dgisselq |
# A demonstration of the Improved PWM waveform
|
2 |
|
|
|
3 |
|
|
This directory contains the files necessary to build a demonstration of the
|
4 |
|
|
[improved PWM](../rtl/wbpwmaudio.v) waveform used in this repository. The
|
5 |
|
|
demonstration is designed to work both in a Verilator based simulation
|
6 |
|
|
(pdmdemo.cpp), as well as with a board having a single PMod AMP2, switch, LED,
|
7 |
|
|
and a 100MHz clock input.
|
8 |
|
|
|
9 |
|
|
The [toplevel Verilog file](toplevel.v) should be easily recognizable as
|
10 |
|
|
[toplevel.v](toplevel.v). This contains the [cordic.v](cordic.v) component to
|
11 |
|
|
generate a sine wave as the test signal, as well as components to turn this
|
12 |
|
|
test signal into both a [traditional PWM](traditionalpwm.v) output as well as
|
13 |
|
|
the [improved version](../rtl/wbpwmaudio.v) found within this repository.
|
14 |
|
|
The [toplevel design](toplevel.v) will either output a 440 Hz tone, or a swept
|
15 |
|
|
tone running from 110Hz to about 27.3kHz, depending upon which part of the
|
16 |
|
|
test sequence is being run.
|
17 |
|
|
|
18 |
|
|
The `DEF_RELOAD` parameter within toplevel.v can be used to adjust the PWM
|
19 |
|
|
interval for the [traditional PWM](traditionalpwm.v), or sample interval for
|
20 |
|
|
the [improved version](../rtl/wbpwmaudio.v). Likewise, when run on actual
|
21 |
|
|
hardware, the switch input will control which
|
22 |
|
|
waveform is produced--either the
|
23 |
|
|
[traditional PWM](traditionalpwm.v) or the
|
24 |
|
|
[improved waveform](../rtl/wbpwmaudio.v).
|
25 |
|
|
|
26 |
|
|
These files can also be composed within a
|
27 |
|
|
[Verilator](https://www.veripool.org/wiki/verilator) based simulation. In this
|
28 |
|
|
case [pdmdemo.cpp](pdmdemo.cpp) forms the main simulation component. A boolean
|
29 |
|
|
value within it, `traditional_pwm`, can be used to control whether or not the
|
30 |
|
|
file downsamples and outputs a [traditional PWM](traditionalpwm.v) signal or
|
31 |
|
|
the [improved version](../rtl/wbpwmaudio.v). Likewise,
|
32 |
|
|
there's a commented line that you can use to generate a VCD file which can be
|
33 |
|
|
used to view traces of the logic within this demo. This demonstration file
|
34 |
|
|
will also produce a file of 64-bit doubles (overkill, I know) containing
|
35 |
|
|
downsampled audio samples at 44.1kHz. This audio file, named wavfp.dbl, can
|
36 |
|
|
be processed within
|
37 |
|
|
[Octave](https://www.gnu.org/software/octave)
|
38 |
|
|
by using [showspectrogram](showspectrogram.m), to view a spectrogram of the
|
39 |
|
|
data.
|
40 |
|
|
|
41 |
|
|
If you take the time to run the [simulation](pdmdemo.cpp), you'll clearly see
|
42 |
|
|
that the [improved PWM](../rtl/wbpwmaudio.v) waveform is much cleaner:
|
43 |
|
|
it doesn't include unwanted harmonics, nor does it include any artificial
|
44 |
|
|
features (beyond any expected aliasing products, present in both).
|
45 |
|
|
The [traditional PWM](traditionalpwm.v) waveform, on the other hand, cannot
|
46 |
|
|
seem to be able to produce a clear tone without also creating unwanted
|
47 |
|
|
harmonics. This effect is only worsened when the PWM period is within
|
48 |
|
|
hearing range, such as when the period is the reciprocal of 8kHz.
|