I'm still fiddling around with the R-2R ladder as a DAC on an Arduino. This time some hardware.
This isn't a project to be built, instead I'm experimenting with analogue stuff; you're looking over
my shoulder as I get some things right and quite a lot of things wrong. What I've ended up with is
messy and not really the way to do it, but if I blog about it at least you'll be forewarned and in a
position to do it better.
I decided that I wanted to be able to control both the frequency and the amplitude of the generated
waveform via SCPI messages. Control of the frequency will be done in the software but there's a limit
to how far I can go with doing the amplitude in software (because the waveform is being generated to
only 8 bits of resolution). So I've come up with a circuit to adjust it in hardware under digital
control. I decided continuous adjustment was too complicated, so I've ended up with a circuit that
uses analogue switches to change the gain of an amplifier. The second bit of hardware I needed was a
filter - this will be a low pass filter that will pass audio frequencies but cut higher frequencies
and have a reasonable level of attenuation by the time we get to the output sample rate (which I'm
provisionally thinking will be something like a few hundred ksps, though the Arduino may not be able
to keep up with that).
Here's the circuit as I have it at the moment (the voltage generator on the left is the output of the DAC):
The first bad decision I made was to keep it as simple as possible and use the Arduino +5V for the
supply and to use a very cheap op-amp, the LM324 for the circuit. There's nothing essentially wrong
with the LM324, but the inputs and outputs don't operate up to the rail so that immediately stops me
from buffering the output of the R-2R DAC with a follower. So, instead, the buffer became an inverting
amplifier with fractional gain. That compromises the input resistance a bit, but it's still high
enough that it doesn't load the DAC and affect the resolution. Originally, I was going to have the
variable attenuation after the filter, but realised that I could change the gain of this amplifier
instead and came up with the circuit above where gain resistors are selectively shorted by analogue
switches (the switches on the circuit diagram are really CD4066 analogue switches controlled by A0 to
A3 used as digital outputs).
The righthand side is a low-pass filter with the cut-off point somewhere around 20kHz. It's a third-
order low-pass Butterworth filter. The response looks like this in the simulator.
Here's how the circuit board looks at the moment - the chips are underneath and the passives on top. A
bit unconventional but it's quite easy to work with, changing and adding bits. (The R-2R DAC is the neat array
at bottom left, the analogue switches are top left, and the op-amps are bottom right).
Unfortunately, when I came to test it, I discovered that the first op-amp was more than happy to
oscillate. I think the reasons for that are twofold - firstly that it was impossible to get the
feedback path compact because of it straggling all around the analogue switch chip and secondly
because the analogue switches add parasitic capacitance (which I'm obviously not modelling in the
simulation). I managed to quieten it down by adding the 22p; that adds to the internal compensation,
but it's still a bit on edge.
Here's an accumulated scope trace that shows the sixteen different gain levels. This is with the
scope's 20MHz filter on (there's quite a lot of high-frequency noise that the output filter doesn't
stop). It works, but if you look just after the point where the traces come together, there's evidence
that the op-amp is on edge and only just holding it.
Anyway, that's where I'm at with the hardware. It's far from perfect - it isn't even something that I
could reasonably present as a project to build - but it will do for the moment and I'm going to go back
to the software and see if I can get the frequency adjustment working under SCPI control. Whilst I'm
doing that I'll consider whether to have another go at the hardware or to call it a day and move on to
Part one: Arduino: R-2R Experiment
Part two: Arduino: R-2R: Sine On You Crazy Diamond
Part three: Arduino: R-2R: Buffer, Attenuate, and Filter
Part five: Arduino: R-2R: "Resistance is..."?
Part eight: Arduino: R-2R: Setting the Signal Amplitude