Analog-to-Digital Conversion Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff Analog-to-Digital (A/D) Conversion • Sensors measure nonelectric quantities such as temperature, etc • These must be converted into an electric quantity (i.e., voltage) using a transducer • Analog voltages must be converted into digital values so that they can be processed by the computer • A signal conditioning circuit is needed to shift and scale the transducer output to a range suitable for A/D conversion Temperature Pressure Light Weight Airflow Humidity . . . Transducer Voltage Such as a sensor, load cell, photocall, or thermocouple . . Microcomputer Architecture and Interfacing Signalconditioning circuit Voltage A/D converter Digital value Computer (optional) In this unit we focus on the A/D converter Figure 12.1 The A/D conversion process Colorado School of Mines Professor William Hoff 2 Digital codes • Ideally we would want a continuous relationship between input voltage and output digital code value • However, we have only a discrete number of code values – for n bits, we have 2^n codes Output code Digital Code 2n-1 Note the horizontal shift to center the error about ±1/2 bit The area above and below the dotted line is called quantization error Voltage Figure 12.2 An ideal A/D converter output characteristic VDD/2n VDD Voltage Figure 12.3 Output characteristic of an ideal n-bit A/D converter Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 3 Digital-to-analog (D/A) conversion • To understand how A/D conversion works, we first look at digital to analog conversion • D/A is the opposite of A/D – it takes an input digital number and outputs an analog voltage proportional to that number • We’ll look at two methods: – A resistor ladder (used in discrete D/A chips) – A charge-redistribution circuit (this is what is used in the microcontroller) Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 4 Resistor ladder • b3,b2,b1,b0 is a 4-bit binary number • Current in each branch: 3 3 2 2 • Total current: Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 5 Convert current to voltage • Ideal op-amp Ideally, • Ri = ∞ • R0 = 0 • A=∞ • Negative gain amplifier (Vi – V-)/R1 = (V- - V0)/R2 Vi/R1 = -V0/R2 V0 = -Vi/(R2/R1) Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 6 Resistor ladder For n=3 bits: I = (Vref/4R)(4b2 + 2b1 + b0) = (Vref/4R) B R Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 7 Resistor ladder • To avoid large current swings: The current in each branch is constant Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 8 Problem with binary-weighted resistor ladder • It is difficult to make resistor values precise over a wide range • Example: a 12 bit D/A would have resistor values R, 2R, 4R, …, 212 R • Instead we can design a resistor ladder with only two values, R and 2R Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 9 R-2R ladder • What is equivalent resistance? R and R in series is 2R 2R and 2R in parallel is R 2R and 2R in parallel is R • At each step, the equivalent resistance is R • So equivalent resistance of entire network is R Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 10 R-2R ladder Iin = b2(I/2)+b1(I/4)+b0(I/8) = (Vref/8R)(4b2 + 2b1 + b0) Vout = -(Vref/8) B Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 11 A/D Conversion • Strategy: generate a series of analog voltages corresponding to known digital values (using a D/A converter) • Compare unknown voltage to the generated voltages • When a match occurs, we know the corresponding digital value • Voltage comparison – We can use a comparator, which is just an op-amp with a large gain – The output saturates one way if Vunknown > Vknown, and saturates the other way if Vunknown < Vknown Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 12 Successive approximation A/D converter • At each iteration, we generate a voltage and test if the unknown voltage is greater than or less than the known voltage • If less, we try a lower voltage; if greater, we try a higher voltage analog comparator + Vin (analog input) - Clock Successive Control Logic approximation register (SAR) Digital-to-analog converter Output Latch VRH VRL Digital code Figure 12.4 Block diagram of a successive approximation A/D converter Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 13 Successive approximation A/D converter • The converter does a binary search – Let VU = unknown voltage – Let VG(D) = generated voltage for digital value D yes yes VU < VG(64) ? Example: 8 bit A/D converter no VU < VG(128) ? no yes VU < VG(192) ? no : : yes VU < VG(96) ? : yes no VU < VG(112) ? 100 <VU < 101 Microcomputer Architecture and Interfacing no : : the answer is actually a range : Colorado School of Mines the search takes n steps, for n bits Professor William Hoff 14 A/D Converter Specifications • Conversion time – The time required to do one A/D conversion – Determines upper limit on frequency that can be sampled without aliasing: fmax = 1/(2*conversion time) • Resolution – Can express in volts, or #bits • Accuracy – Vresolution/Vsignal (%) • Linearity – Deviation from straight line (best possible is ±1/2 LSB) Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 15 A/D Converter Specifications (continued) • Aperture time – It takes a finite amount of time to sample the input signal – this is called the aperture time – If signal is changing during sampling time, can cause an error – Maximum aperture time to reduce this error to ±1/2 LSB is t AP 1 2 f max 2 N Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 16 Example • A 10-bit A/D converter uses successive approximation, with a 800 KHz clock. Each step in the conversion cycle takes 4 clock cycles – What is the conversion time? – If Vref is 10 volts, what is the resolution? – What is the maximum frequency you can digitize, without aliasing? – Find the aperture time for the sampling error to be less that ±1/2 LSB Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 17 Example • A 10-bit A/D converter uses successive approximation, with a 800 KHz clock. Each step in the conversion cycle takes 4 clock cycles – What is the conversion time? There are 10 steps, each taking 4 clock cycles, so 40 clock cycles Total time is 40 x (1/800 KHz) = 50 microseconds – If Vref is 10 volts, what is the resolution? 10 bits; or in terms of voltage: 10V/(2^10) = 10V/1024 = 0.01 V – What is the maximum frequency you can digitize, without aliasing? fmax = 1/(2 x tconv) = 1/(2x50 us) = 10^4 Hz – Find the aperture time for the sampling error to be less that ±1/2 LSB tAP= 1/(2 pi fmax 2^N) = 1/(2 pi x 10^4 Hz) x 2^10) = 0.016 us the aperture time is much smaller than the conversion time Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 18 Summary / Questions • Why is a “digital-to-analog” element needed in a “analog-to-digital” converter? • Typical specifications for A/D systems are – – – – – Conversion time Resolution Accuracy Linearity Aperture time Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff 19