[sdiy] PWM DAC techniques

Olivier Gillet ol.gillet at gmail.com
Mon Aug 2 17:46:28 CEST 2010


Hi,

> One thing I see with the low cost approach is DACs done via PWM.  But with CVs, to avoid stepping we want probably 10 bits or better and this puts the PWM freq down in the audio range, which then requires heavy filtering and that of course limits the slew rates and settling times.

The fact that most micros can control the PWM duty cycle with an 8 bit
value should not make you forget that the output is really 1 bit, and
that what's really happening is a trade-off between time and
resolution.

Why do you want 10 bits of resolution in the first place?
- If you want it because you believe that there'll be some
stepping/zipping in the envelopes, this is a non-problem - just put a
lowpass filter on the output and steps will be turned into exponential
branches.
- But if you really need to address a range of 1024 increments (for
example for precise pitch control), you'll really need those 10 bits.
You can do it by some multiplexing in the time domain.

For example, if you want 0 = 0V, 1024 = 5V, and if your PWM output
register is 8 bits:
* to write 256 you write: 64, 64, 64, 64
* to write 257 you write: 65, 64, 64, 64
* to write 258 you write: 65, 65, 64, 64
* to write 259 you write: 65, 65, 65, 64
* to write 260 you write: 65, 65, 65, 65

In a way, it's PWM within PWM, and the cost of doing that is that
you're dividing your bandwidth by 4. On an AVR, the max PWM speed in
phase correct mode is 39kHz (with a 20MHz), so this gives you a
bandwidth of 10kHz, and you have a margin of one decade to filter the
high frequency crap if you want to keep a decent response time of 1ms.

PWM within PWM sounds like what you meant by your idea number 1, but
in your example you use 2^5 = 32 samples for a single value, and
you're hurting your bandwidth. You'll need a low-pass at 39 / 32 =
1.2kHz to remove the high frequency crap, so don't expect a response
time in the ms range.

Here we did PWM of PWM. But you can also do a Sigma-delta like thing
to get a few more bits out of the 8-bits PWM counter, and this won't
hurt your bandwidth as much.

Those things are extremely evil, and I'm sorry to have somehow
encouraged you on this sloppy path. Indeed, there are two
motivations for using internal PWM instead of a DAC:
1/ Get rid of the overhead of chitchatting with the DAC (packet
formatting, SPI, mini state machine to do a round-robin on several
control signals to output...), which can amount to 20 cycles.
2/ Cost

PWM of PWM will have some overhead, so if you do PWM for reason 1/,
you'll be in trouble anyway. If you factor out the pain of filtering
your output signals, 2/ is not a very valid reason.

Olivier



More information about the Synth-diy mailing list