Chapter Four
Analog to Digital and
Digital to Analog conversion
4.1. Analog to Digital Conversion.
4.1.1. Definition.
An analog-to-digital converter (abbreviated ADC, A/D or A to D) is an electronic
circuit that converts continuous signals to discrete digital numbers in binary form.
A/D converters are used to transform analog information, such as audio signals or
measurements of physical variables (for example, temperature, force, or shaft
rotation) into a form suitable for digital handling, which might involve any of these
operations:
a) Processing by a computer or by logic circuits, including arithmetical
operations, comparison, sorting, ordering, and code conversion.
b) Storage until ready for further handling.
c) Display in numerical or graphical form, and
d) Transmission.
4.1.2. Why the A/D is needed.
a) Microprocessors can only perform complex processing on digitized signals.
b) When signals are in digital form they are less susceptible to the deleterious
effects of additive noise.
c) ADC Provides a link between the analog world of transducers and the digital
world of signal processing and data handling.
4.1.3. ADC process
There are two basic steps to convert an analog signal to digital form, (figure 1):
Sampling and Holding (S/H).
Quantizing and Encoding (Q/E), is the conversion the sampled value to its
corresponding digital value.
Figure 1. ADC processing steps.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -83-
4.1.3.1. Sampling and Holding
Sample and hold (S/H) circuit is an analog device that samples (captures,
grabs) the voltage of a continuously varying analog signal and holds (locks, freezes)
its value at a constant level for a specified minimum period of time. See figure 2.
The minimum sampling rate should be at least twice the highest data frequency of the
analog signal.
Figure 2. Sampling and Holding process.
4.1.3.2. Quantizing and Encoding
Resolution: The smallest change in analog signal that will result in a change in the
digital output.
Vr = Reference voltage range.
N = Number of bits in digital output.
2N = Number of states.
ΔV = Resolution.
The resolution represents the quantization error inherent in the conversion of the
signal to digital form.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -84-
Quantizing:
Is the dividing of the reference signal range into a number of discrete level, then
matching the input signal to the correct quantum.
Quantization: also is the procedure of constraining something from a continuous set
of values (such as the real numbers) to a relatively small discrete set (such as
the integers).
The process of converting, or digitizing an analog waveform to one of a finite series
of discrete levels.
Encoding:
Encoding is a process of converting information into a specific code. In digital, the
encoding means convert the information is binary code (base of 2).
Let us clarify the above parameters by an example;
If we have 5 V maximum analog signal ( = reference voltage) and we like to divide it
into 8 levels ( is the no. of quantizing, this is the quantization) then the value of each
level is 5/8.
The levels are :0, 1*5/8, 2*5/8, 3*5/8, 4*5/8, 5*5/8, 6*5/8, 7*5/8.
The 8 levels can be representing (encoding ) in binary form as 3 bits and the binary
numbers are : 000, 001, 010, 011, 100, 101, 110, 111.
You can notice that when the binary number is 111 (which is the maximum value)
then the corresponding value in 7*5/8 which is less than the maximum value of
analog value which is 5 V. This is an error in conversion process, this error will
discussed later and how to minimize this error. This note is just to call the attention.
4.1.4. A/D Specifications (parameters).
4.1.4.1. Resolution.
The resolution of the converter indicates the number of discrete values it can produce
over the range of voltage values. It is usually expressed in bits. For example, an
ADC that encodes an analog input to one of 256 discrete values (0255) has a
resolution of eight bits, since 28 = 256.
Also the resolution can also be defined electrically, and expressed in volts. The
voltage resolution of an ADC is equal to its overall voltage measurement range
divided by the number of discrete values.
Example1.
o Full scale measurement range = 0 to 10 volts
o ADC resolution is 12 bits: 212 = 4096 quantization levels
o ADC voltage resolution is: (10-0)/4096 = 0.00244 volts = 2.44 mV
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -85-
Example2.
o Full scale measurement range = -10 to +10 volts
o ADC resolution is 12 bits: 212 = 4096 quantization levels
o ADC voltage resolution is: (10-(-10))/ 4096 = 20/4096 = 0.0048828 volts =
4.8828 mV
o And if 14 bit ADC is considered, the resolution is 20/16384 = 1.22 mV.
4.1.4.2. Accuracy.
Accuracy is the total error with which the A/D converter can convert a known
voltage, including the effects of quantization error, gain error, offset error, and
nonlinearities.
The accuracy of an A/D converter can be calculated as;
Accuracy = 1/(2^no. of bits of A/D) * 100%
For example the accuracy of 8 bit A/D converter = 1/(2^8) *100% = 0.4 %.
The accuracy of 10 bit A/D converter = 1/(2^12) *100% =.00024414= 0.024414 %.
4.1.4.3. Range.
Device range: minimum and maximum analogue signal levels that the A/D can
convert.
The device range should be matched to the range of the analogue input signal to best
take advantage of the available resolution.
Example3.
If a 3-bit ADC (having 8 divisions) is used over a range of 0 to 10 volts, voltage
changes of 1.25V can be measured. However, if the range is increased to -10 to 10V,
then the smallest voltage change which can be measured rises to 2.5V
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -86-
4.1.4.4. Smallest detection voltage range (∆V).
Can be defined as the minimum value A/D converter can be detected.
𝑟𝑎𝑛𝑔𝑒
∆𝑉 = 2𝑛𝑜.𝑜𝑓 𝑏𝑖𝑡𝑠 𝑜𝑓 𝐴/𝐷
4.1.7. Types of A/D converter.
The most known types of A/D converter are:
4.1.7. 1 Dual Slope A/D Converter.
Refer to figure 3, the main components of this converter are:
Integrator.
Electronically Controlled Switches.
Counter.
Clock.
Control Logic.
Comparator.
Figure 3. Block diagram of Dual Slope A/D converter.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -87-
How does it works.
A dual-slope ADC (DS-ADC) integrates an unknown input voltage (Vi) for a fixed
amount of time (TINT), then "de-integrates" (TDEINT) using a known reference voltage
(VREF) for a variable amount of time.
The key advantage of this architecture over the single-slope is that the final
conversion result is insensitive to errors in the component values. That is, any error
introduced by a component value during the integrate cycle will be cancelled out
during the de-integrate phase.
At t<0, S1 is set to ground, S2 is closed, and counter=0.
At t=0 a conversion begins and S2 is open, and S1 is set so the input to the
integrator is VIN.
S1 is held for TINT which is a constant predetermined time interval.
When S1 is set (to Vref) , the counter begins to count clock pulses, the counter
resets to zero after TINT.
Vout of integrator at t=TINT is VIN*TINT/RC is linearly proportional to VIN.
At t=TINT S1 is set (to Vref), so Vref is the input to the integrator which has
the voltage VIN*TINT/RC stored in it.
The integrator voltage then drops linearly with a slop -Vref/RC.
A comparator is used to determine when the output voltage of the integrator
crosses zero
When it is zero the digitized output value is the state of the counter.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -88-
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -89-
Advantages Disadvantages
1. Conversion result is insensitive to 1. Slow.
errors in the component values. 2. Accuracy is dependent on the
2. Fewer adverse affects from “noise” use of precision external
components.
3. High Accuracy 3. More Cost.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -90-
4.1.7. 2. Successive Approximation A/D converter (SAR).
Uses a n-bit DAC to compare DAC and original analog results.
Uses Successive Approximation Register (SAR) supplies an approximate digital
code to DAC of Vin.
Comparison changes digital output to bring it closer to the input value.
Uses Closed-Loop Feedback Conversion.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -91-
Successive Approximation Example
10 bit ADC
Vin= 0.6 volts (from analog device)
Vref=1 volts
Find the digital value of Vin
MSB (bit 10)
Divided Vref by 2.
Compare (V) = Vref /2 = 1/2 V =0.5 V with Vin
If Vin is greater than Vref /2 , turn MSB on (1)
If Vin is less than Vref /2 , turn MSB off (0) N=2n = 210 (N of possible states)
Vin =0.6V and V=0.5 V
N=1024
Since Vin>V, MSB = 1 (on)
One step = 1 Volt(Vref)/1024
= 0.0009765625V (resolution)
Next Calculate MSB-1 (bit 9)
Compare Vin=0.6 V to V=Vref/2 + Vref/4= 0.5+0.25 =0.75V
Since 0.6<0.75, MSB-1 is turned off.
Calculate MSB-2 (bit 8)
Go back to the last voltage that caused it to be turned on (Bit 10) and add it to
Vref/8, and compare with Vin
Compare Vin with (0.5+Vref/8)=0.625
Since 0.6<0.625, MSB is turned off.
Calculate the state of MSB-3 (bit 7).
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -92-
Go to the last bit that caused it to be turned on (In this case MSB-1) and add it
to Vref/16, and compare it to Vin.
Compare Vin to V= 0.5 + Vref/16= 0.5625.
Since 0.6>0.5625, MSB-3=1 (turned on).
This process continues for all the remaining bits.
Advantages Disadvantages
1. Capable of high speed and 1. Higher resolution successive
reliable approximation ADC’s will be
2. Medium accuracy compared to slower.
other ADC types 2. Speed limited to ~5Msps
3. Good tradeoff between speed
and cost
4. Capable of outputting the
binary number in serial (one bit
at a time) format.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -93-
4.2. Digital to Analog Conversion.
4.2.1. What is the digital to analog converter?
In electronics, a digital-to-analog converter (DAC or D-to-A) is a device for
converting a digital (usually binary) code to an analog signal (current, or voltage).
The output current or voltage proportional to the digital input quantity ( binary).
Today microcontrollers are widely used for industrial control. The output of the
microcontroller is a digital quantity in many applications the digital output of the
microcontroller has to be converted into analog quantity which is used for the control
of relay, small motor, actuator, etc.
In communication system digital transmission is faster and convenient but the digital
signals have to be converted back to analog signal at the receiving terminal. DAC
converter is also used as a part of the circuitry of several ADC converters.
4.2.2. Advantages of Digital Representation:
• Values are limited to specific discrete segments.
• Not subject to the same distortions as an analog signal.
• Can be easily copied and stored.
4.2.3. Calculation DAC Output Voltage
If Vo is the output, Vref if the fixed reference voltage, then for n bits:
b n -1 2 n -1 ... b 2 2 2 b1 21 b 0 2 0
Vo Vref
2n
b0 is the LSB and bn-1 is the MSB.
The maximum output voltage = Vref * (2^n ) -1) ) / (2^n)
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -94-
Maximum output voltage when the input is 1 1 1 1 1 1 1 1 = 5 * ((2^8)-1) / 2^8 =
5*255/256 = 4.98046875 V ( note that it is less than 5 V).
4.2.4. DAC Types
There are several ways of making a digital to analog converter. The main types are:
4.2.4.1. Binary weighted resistor DAC.
Referring to figure below, the weighted resistance DAC consists of the following
major components (for n-bit DAC):
a. n switches one for each bit applied to the input.
b. A weighted resistor ladder, (no. of resistances = n-1) network, where the
resistance are inversely proportional to the numerical significance of the
corresponding binary digit. i.e.
Resistance in bi is Ri = (2^(n-1-i))*R ; (i=0, 1, 2, ….., n-1. )
c. A reference voltage Vref.
d. Summing Op. Amp.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -95-
When all such currents from different weighted resistors get added at summing point
(which is also known as virtual ground) of operational amplifier it will produce
proportional voltage as its output.
For a 4 bit DAC the output V0 is given as follows
Where S3, S2, S1 and S0 represents the status of the switches i.e. on or off (1 or 0).
If resistors are in binary weights i.e. R3=R, R2=2R, R1=4R and R0=8R, with Rf=
R/2, the above equation can be written as,
Example:
For example if a DAC of 4 bits (n=4) is considered, then,
No. of resistances = n-1, the resistances are ( for i=0, 1, 2, 3)
In bo input resistance = (2^(4-1-0)) * R = 2^3 * R = 8R
In b1 input resistance = (2^(4-1-1)) * R = 2^2 * R = 4R
In b2 input resistance = (2^(4-1-2)) * R = 2^1 * R = 2R
In b3 input resistance = (2^(4-1-3)) * R = 2^0 * R = R
Rf = R/2
If we assumed that Vref = 5 V, R=10 K, then R1=10K, R2=20k, R3=40K, R4=80K,
and Rf = 5K. The circuit is shown below.
Note : You can increase the output voltage by increasing Rf, if Rf = R for
example the output voltages are doubled than that at Rf=R/2.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -96-
V1 4-bit Weighted DAC circuit
5V
( R1=10 K, R2= 20K, R3=40 K R4=80K, and Rf=R1/2 = 5 K),
bo
XMM1
R4 RF
Key = A 80kΩ 5kΩ
U1
b1
R3
40kΩ OPAMP_3T_VIRTUAL
Key = B
b2
R2
Key = C 20kΩ
b3
R1
Key = D 10kΩ
The filename is : weighted dac
Advantage of weighted DAC
As only one resistance value is used in the network, so it is an economical D/A
converter.
Disadvantages of weighted DAC
1. Resistors used in the network have a wide range of values, so it is very difficult
to ensure the absolute accuracy and stability of all the resistors.
2. It is very difficult to match the temperature coefficients of all resistors. This
factor is important in D/A converters and cause error in conversion.
3. When n is so large, the resistance corresponding to LSB can assume large
value, this cause problem in operation of Op.Amp and cause error.
4. As the switch represent a finite impedance ( not infinite as theoretically) this
means some leakage current passes in Op.Amp. (not zero) and cause error in
conversion.
5. It is limited for only 4-bits D/A.
4.2.5. DAC performance (Characteristics).
DACs are very important to system performance. The most important characteristics
of these devices are:
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -97-
Resolution
Normally expressed in no. of bits. Resolution indicates the smallest increment
of its output corresponding to a 1 LSB input code change. For example for 10
bit DAC, 2^10 = 1024 codes, so the resolution is 1/1024 of the output range.
Least Significant Bit (LSB)
In a binary number, the LSB is the least weighted bit in the group. Typically,
the LSB is the furthest right bit. For an ADC or DAC, the weight of an LSB
equals the full-scale voltage range of the converter divided by 2 N, where N is
the converter's resolution. For a 12-bit ADC with a unipolar full-scale voltage
of 2.5V, 1LSB = (2.5V/212) = 610µV.
Most Significant Bit (MSB)
In a binary number, the MSB is the most weighted bit in the number.
Typically, the MSB is the left-most bit.
Quantized level: is no. of levels DAC can produce = 2^n ( n no of bits of a
DAC).
Full scale range (FSR) - maximum output signal for the DAC, specified as
current or voltage can be negative, positive or both.
Dynamic Range - A measurement of the difference between the largest and
smallest signals the DAC can reproduce expressed in decibels
Maximum sampling rate
A measurement of the maximum speed at which the DACs circuitry can
operate and still produce the correct output.
Conversion time - a time in which the expected analog output change results
from the digital input change.
nput voltage range - The input voltage range of an ADC is determined by the
reference voltage (VREF) applied to the ADC.
Settling time is the time required for the outputs to switch and settle within ½
LSB when the input switches form all 0s to all 1s.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -98-
4.2.7. Choosing the D/A Converter
There are six main parameters that should be considered when choosing a DAC for a
particular project.
Reference Voltage
Resolution
Linearity
Speed
Settling time
Error
Reference Voltage
To a large extent the output properties of a DAC are determined by the
reference voltage.
Multiplier DAC – The reference voltage is constant and is set by the manufacturer.
Non-Multiplier DAC – The reference voltage can be changed during operation.
Resolution
The resolution is the amount of voltage rise created by increasing the LSB of
the input by 1. This voltage value is a function of the number of input bits and the
reference voltage value.
- Increasing the number of bits results in a finer resolution
- Most DACs in the 12-18 bit range
Resolution = Vref / 2^N ( N no. of bits of D/A)
Linearity
The linearity is the relationship between the output voltage and the digital
signal input.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -99-
Speed
Usually specified as the conversion rate or sampling rate. It is the rate at which
the input register is cycled through in the DAC.
High speed DACs are defined as operating at greater than 1 millisecond per
sample (1MHz).
Some state of the art 12-16 bit DAC can reach speeds of 1GHz
The conversion of the digital input signal is limited by the clock speed of the
input signal and the settling time of the DAC.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -100-
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -101-
4.2.8. The connection of DAC to the microcontroller.
In digital control system, the analog signal from the analog sensor is fed to the
microcontroller which contains analog input. In the microcontroller the control
algorithm is executed and the final control is generated from the microcontroller in
digital form. Since the actuator (or driver) requires an analog signal so the
microcontroller output must be converted into analog signal using DAC. Some
microcontroller types contain DAC inside.
The classical control system used arduino shield is shown below.
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -102-
Biomedical Engineering - Digital Electronics II - Fourth year – Prof. Dr. Mahmoud Alshemmary -103-