Electronics for Dummies (or biochemists)

How DACs work, By Isabel Bennett, PhD student, UCL


Embarking on the L2N project as a non-engineer I knew I was going to be challenged and learn a great deal. Even as a user of AFM for my PhD, my experience in the electronics that go on “behind the scenes” was limited.

I wanted to be stuck in at the deep end: sink or swim, I thought. So I signed up for the “firmware” stream, which was the team focused on programming an Arduino microprocessor to coordinate the desktop programme interface with the electronics of the AFM. My experience on an Arduino had until then consisted of turning a series of blinking LEDs on and off in response to a switch. Not advanced stuff.

Our first task was to connect up a digital to analogue converter (DAC) which could control the movement of the sample stage by moving some piezos. Well, obviously a SPI was best to use with the DAC so that our SCK from the master would be synchronised with our data when it is sent to the slave.


But by the end of Day 1 I can tell you I understood that sentence.

My first step was to understand what a DAC actually did. Well, it converts binary code to an analogue signal, like when we listen to a cd of music. But how does it do this? How does a series of “0”s and “1”s become Bob Dylan’s gravelly voice, or a voltage for our piezo? With the help of my fellow L2N-ers and the Internet, I found out. And the answer is: magic. Well, almost.

What follows is my explanation of how DACs work.

The signal the Arduino microprocessor receives from the electronics of the AFM is analogue (i.e. a voltage). However the Arduino contains an analogue to digital converter (ADC) which converts the signal to a digital (binary) signal. This can be packaged as bytes of data sent to the interface for visualisation.

In order for the Arduino to “talk” to the AFM stage, information must be converted to an analogue signal because movement is controlled by four piezos under the stage platform. Piezos expand when a voltage is applied to them, and by specifying the voltage, the movement can be controlled. To programme the Arduino to send out our specified voltage, a digital to analogue converter (DAC) is required.

The first step is understanding how an analogue wave (or voltage) is converted into a digital signal by an ADC. ADCs monitor the amplitude of an incoming wave over time, converting the amplitude into a binary value. When binary is used to encode information, a single digit is called a “bit”, and a string of 8 bits describing a piece of information is a “byte”. A string of bytes encodes a series of points along a line, which forms an approximation of the analogue wave.

The quality of the discrete approximation of the smooth analogue wave is determined by two things: how often the ADC measures the amplitude (the sampling rate), and how accurately it can measure the amplitude (the bit depth). For bit depth, more bits are more accurate in the same way increasing the number of decimal places increases accuracy.


So the analogue signal is now encoded in a series of bytes, separated by a known time (sampling rate). A digital signal!

But what happens when we want to convert this string of bytes back into a continuous analogue wave or voltage?

Let’s say the digital signal is written with bytes made up of 4 bits (although in reality it is more complicated). So for example:

0001   0011   0111

Put simply, DACs are able to read the bytes as a series of numbers which correspond to the list of amplitude values taken over time.

This is where the magic comes in.


There are many different types of DACs, but the easiest to understand is the R-2R ladder type. The way these work is by using the high/low status of each bit to open or close a corresponding path into a circuit which consists of a series of resistors. The current can only flow into the circuit through the entrances where the bit status is 1 (high/on). Depending on the number of resistors the current flows through, a certain value of voltage will be measured at the end of the circuit (Vout). Each combination of bits (or on/off combinations) gives a given voltage value. For example

2.3 Vout = 0001

3.7 Vout = 0010

1.8 Vout = 0111

If you know the identity of the string of bytes, you can reconstruct the analogue wave by connecting the points they represent along an axis of time. Et voila! An analogue wave!

So there you have it. My non-expert explanation of a really cool electronic component that not only features in our AFM project, but also in most pieces of technology.

Tomorrow, I tackle the world of GitHub… Is it as fun and friendly as its name sounds?