1 |
4 |
dgisselq |
# A Wishbone Controlled PWM (audio) controller
|
2 |
|
|
|
3 |
|
|
This PWM controller was designed with audio in mind, although it should be
|
4 |
|
|
sufficient for many other purposes. Specifically, it creates a pulse-width
|
5 |
|
|
modulated output, where the amount of time the output is 'high' is determined
|
6 |
|
|
by the pulse width data given to it. Further, the 'high' time is spread out in
|
7 |
|
|
bit reversed order. In this fashion, a halfway point will alternate between
|
8 |
|
|
high and low, rather than the normal fashion of being high for half the time
|
9 |
|
|
and then low. This approach was chosen to move the PWM artifacts to higher,
|
10 |
|
|
inaudible frequencies and hence improve the sound quality.
|
11 |
|
|
|
12 |
|
|
The interface supports two addresses:
|
13 |
|
|
|
14 |
|
|
- Addr[0] is the data register. Writes to this register will set
|
15 |
|
|
a 16-bit sample value to be produced by the PWM logic.
|
16 |
|
|
Reads will also produce, in the 17th bit, whether the interrupt
|
17 |
|
|
is set or not. (If set, it's time to write a new data value ...)
|
18 |
|
|
|
19 |
|
|
- Addr[1] is a timer reload value, used to determine how often the PWM logic
|
20 |
|
|
needs its next value. This number should be set to the number of clock cycles
|
21 |
|
|
between reload values. So, for example, an 80 MHz clock can generate a
|
22 |
|
|
44.1 kHz audio stream by reading in a new sample every (80e6/44.1e3 = 1814)
|
23 |
|
|
samples. After loading a sample, the device is immediately ready to load a
|
24 |
|
|
second. Once the first sample completes, the second sample will start going
|
25 |
|
|
to the output, and an interrupt will be generated indicating that the device
|
26 |
|
|
is now ready for the third sample. (The one sample buffer allows some
|
27 |
|
|
flexibility in getting the new sample there fast enough ...)
|
28 |
|
|
|