240 likes | 246 Views
Understand the process of digital-to-analog conversion in microcomputer systems and how it maps binary numbers to analog voltages. Learn about different types of D/A converters and their design considerations.
E N D
ECE 3430 – Introduction to Microcomputer SystemsUniversity of Colorado at Colorado Springs Lecture #18 Agenda Today: 1) Digital-to-Analog Conversion (D/A conversion) 2) Analog-to-Digital Conversion (A/D conversion) ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog Signals vs. Digital Signals • Despite what you hear in the media, we don’t live in a digital world! • Electricity by its nature is analog! • Analog electrical signals have a continuous voltage and current range. • When analog signals are restricted to one of a series of discrete voltages, we can map each of these voltage levels to one of n numbers. When we do this, we call it digital. • Numbers are made up of digits—hence why it is called digital. • Today, almost all digital systems operate on two discrete voltage levels. This maps nicely into a binary domain. Because of this, people will use the terms binary and digital interchangeably although they don’t technically have to mean the same thing. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog Signals vs. Digital Signals • Different logic families (TTL, CMOS, ECL, et cetera) map different voltages to logic 0 and logic 1: • TTL: 0V = logic 0, +?V = logic 1 • CMOS: 0V = logic 0, +?V = logic 1 • ECL: -?V = logic 0, 0V = logic 1 • When negative logic is employed, the voltages that normally correspond to logic 0 and logic 1 are reversed! • On our breadboard in the lab, we treat +3.3V as a logic 1 and 0V as a logic 0. • Acronyms: TTL = Transistor-to-Transistor Logic CMOS = Complementary Metal Oxide Semiconductor Logic ECL = Emitter-Coupled Logic ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • Digital-to-analog conversion is the process of mapping a number to an analog voltage. • A single binary digit (bit) maps to one of two discrete voltages. • A series of binary digits (bits) maps to series of discrete voltages (resolution/precision): • An n-bit binary number can map to 2n voltage levels. • An 8-bit binary number can map to 256 voltage levels. • A device that takes a series of bits and outputs a voltage is called a digital-to-analog converter, D/A converter, or DAC. • These binary digits can be fed to the D/A converter as a serial bit stream or as a set of parallel inputs. • There are many ways to design D/A converters. The design of the D/A converter determines what range of analog voltages you will get for a set of digital inputs… ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • Assume an 8-bit D/A converter is designed to output an analog voltage between 0 and +5V: 0 = 00000000 -> 0V 63 = 00111111 -> +1.25V 127 = 01111111 -> +2.5V 255 = 11111111 -> +5V • Basic equation: Vout = Din/(2n - 1) * Vmax • The output of a D/A converter can be shifted or amplified using additional analog circuitry. Voltage is proportional to number magnitude. Dividing number by two will divide the output voltage in half. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • Simple example of a serial, pulse-width modulated (PWM) D/A converter: • This D/A converter is simply a low-pass filter with rolloff frequency defined as follows: frolloff = 1/(2*π*R*C) where: R = resistor value (Ohms) C = capacitor value (Farads) ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • The low-pass (RC) filter will be driven with a serial stream of bits (voltage fluctuations between 0V and Vcc/Vdd). • A low-pass filter will pass frequencies below the rolloff frequency and attenuate frequencies above the rolloff frequency. • Rolloff frequency is also sometimes called cutoff or turnover frequency. • To use this kind of serial D/A converter, we must use digital electronics to convert a binary number into a periodic square wave. • If we drive the bits at the filter at a rate much lower than the rolloff frequency, we would expect to see a square wave at the output of the D/A converter (clearly not what we want). • If we drive the bits at the filter at a rate much higher than the rolloff frequency, we would expect to see no oscillation on the output (high frequency is being filtered—what we want). ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • However, the RC filter has a DC offset (due to charge accumulated on the capacitor). When a non-zero voltage is applied to the top terminal of the capacitor, it slowly starts charging to match that voltage. • When a zero voltage is applied to the top terminal of the capacitor, the capacitor starts discharging. • The voltage at the output of the D/A converter is simply the average voltage presented at Vin. • The average voltage of a square wave is proportional to the duty cycle. So, does the frequency matter at all? ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • The frequency must simply stay much greater that the rolloff frequency. We just vary the duty cycle of the input waveform to control the analog output: 0% duty cycle -> 0V 25% duty cycle -> +1.25V 50% duty cycle -> +2.5V 100% duty cycle -> +5V How would you recommend we generate a waveform with fixed frequency and variable duty cycle in the MSP430? ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • We could use output compare to generate a square wave with a programmable duty cycle and fixed frequency. A parallel D/A converter: • Each combination of bits yields a discrete voltage output… • Examples: R-2R Ladder DAC • Vref defines the maximum analog output (mapping to all 1’s). Vref Parallel Digital Input (n-bit input) D/A Analog Output ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) R-2R ladder: • Works well if all resistors (values of R) are “exactly the same”. • Each input is GND or Vcc/Vdd. • Current division (KCL) principles at play here. • Vout is proportional to the binary number provided on a(0)-a(n-1). • “Instantaneous” conversion time. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Digital-to-Analog Conversion (D/A) • 00000000 -> 0V 00000001 -> ~0.02V 00000010 -> ~0.04V 11111111 -> +5V Granularity in the output voltages. What if we needed 0.03V? • Use smaller voltage reference (assign smaller voltage to 11111111). • Use more bits. • With this kind of parallel D/A converter, we don’t need to create a periodic waveform. For the serial, PWM D/A, why not use a large capacitor to establish a low rolloff frequency so we don’t have to generate such a high- frequency square wave? ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) • Analog-to-digital conversion is the process of mapping an arbitrary voltage to one of n discrete numbers. • As with D/A converters, A/D converters are designed to work with a specific number of bits (resolution/precision). • An n-bit A/D converter will map a voltage to one of 2n numbers. • A device that accepts an analog voltage and produces a corresponding number to represent that voltage is called an analog-to-digital converter, A/D converter, or ADC. • The binary output of an A/D converter can be handed to another device in parallel or as a serial bit stream. • As with D/A converters, there are many ways to design A/D converters. • A/D converters use a reference voltage to define what voltage will yield the maximum binary output… ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) • An 8-bit A/D converter with +5V tolerant inputs and a voltage reference set to +5V will produce output as follows: 0V -> 0 = 00000000 +1.25V -> 63 = 00111111 +2.5V -> 127 = 01111111 +5V -> 255 = 11111111 • If the reference voltage were changed to +2.5V, then the digital output for +2.5V would be 11111111. • Some A/D converters have differential inputs (the input voltage is the difference between two input pins). • Some A/D converters have differential voltage references (to establish both a high and low voltage reference). Number magnitude is proportional to input voltage. Dividing voltage in half will yield a binary output half as big. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) • Basic equation (for single input, single voltage reference): Dout = Vin/Vref * (2n - 1) • Basic equation (for differential input, single voltage reference): Dout = (V+in - V-in)/Vref * (2n - 1) • Applied voltages to an A/D converter can be scaled and shifted using additional analog circuitry to meet the requirements of the A/D converter. • A/D converters suffer from a phenomenon known as quantizationerror. A specific voltage will be “rounded” to the nearest whole number. This means that the digital output is not entirely accurate for all voltage inputs. What can be done to reduce quantization error? ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) So how does an analog-to-digital converter work? • One very common technique for doing analog-to-digital conversion is called the successive approximation method. • This method involves the use of an analog comparator, a D/A converter, control logic, and storage for a digital approximation (SAR): ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) • The successive approximation method executes sequentially (it takes a clock cycle for each bit in the final result). An 8-bit A/D would take 8 cycles to calculate the 8-bit result. • The approximation register is first cleared, then the most-significant bit is calculated first…then the others: • Guess bit to be 1. • Provide current value in approximation register to D/A converter. • Analog comparator compares D/A output with externally provided analog input. • Control logic clears the bit that it set if D/A output is larger than externally provided input (the initial guess was wrong). • Repeat above steps for all the other bits. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) • MSP430 ADC10 and ADC12 module use successive approximation. • More specifically, the MSP430 ADC10/12 modules use a switched-capacitor DAC scheme instead of an older R-2R DAC approach. • The MSP430 also has an A/D module based on a Sigma-Delta (sometimes called Delta-Sigma) A/D converter scheme. • Called the SD16_A module. • This A/D scheme is very complicated (w/r/t SAR) and beyond the scope of this course. • This type of converter gives you more precision—but slower to stabilize. • On the MSP430, this module is about 100 times slower than the ADC10/12. • The only A/D converter we have on the G2553 part is the ADC10. ECE 3430 – Intro to Microcomputer Systems Fall 2014
Analog-to-Digital Conversion (A/D) Another alternative… Flash ADC: • Produces digital result “in a flash”! • Instantaneous output change. • Lots of circuitry required however. • Required in multimedia applications or any time rapid conversions are required. ECE 3430 – Intro to Microcomputer Systems Fall 2014
A/D and D/A General Issues A/D and D/A General Issues: • Accuracy • How consistent are repeated conversions with a constant analog or digital input? • Resolution/Precision • If the analog or digital input changes very slightly, will the digital or analog output reflect the change? ECE 3430 – Intro to Microcomputer Systems Fall 2014
A/D and D/A Uses • We live in an analog world, so input from many different sensors are analog in their nature. • Many forms of stimulus that a microcontroller needs to monitor are not electrical in nature: • Temperature • Pressure • Light • Weight • Airflow • Humidity • Et cetera • Transducers are used to transform the non-electrical quantities mentioned above into analog voltages (and vice-versa). • Now if a microcontroller is expected to understand this analog information (i.e. detect the temperature, pressure, amount of light, et cetera) it needs an A/D converter to convert this quantity to a number. ECE 3430 – Intro to Microcomputer Systems Fall 2014
A/D and D/A Uses • Transducers are devices that convert one form of energy to another form of energy. For our purposes we are typically interested in converting non-electrical energy into electrical energy and vice-versa. • Examples of transducers: • Piezoelectric materials • Microphone/speakers • Photoelectric cells/light bulbs/LEDs • Electrical generators/electrical motors • …and the list goes on forever… • If a microcontroller expects to make sound, move an object with a motor, generate light, and so on, the digital information it contains must be translated. First a D/A converter converts digital information into a pure form of electricity (analog voltage). Then a transducer can change electrical energy into some other form of energy. ECE 3430 – Intro to Microcomputer Systems Fall 2014
A/D and D/A Uses • The analog input to an A/D or the analog output of a D/A may not meet the electrical requirements for the transducer. • Signal conditioning (amplification and shifting) can be applied to these analog signals. • Operational amplifier circuits are often used for this. • The A/D or D/A voltage references may need to change for different applications. • Noise can be an issue. • Digital clock lines contain very high frequency components and can “rattle” nearby analog voltages. • AC sources are a common source of 50 or 60 Hz noise. • Noise can be dampened with capacitors and mitigated by decoupling analog and digital voltage rails. ECE 3430 – Intro to Microcomputer Systems Fall 2014
The MSP430 (D/A and A/D) • Some varieties of the MSP430 have a built-in A/D converter. • May have ADC10, ADC12, or SD16_A module. • Can reconfigure port pins to become analog inputs. • Our MSP430 (G2553) has only one ADC10 module. • Some MSP430s (not ours) have a 12-bit D/A converter (DAC12). • If an A/D converter or D/A converter is not built into your microcontroller, then you have to interface one externally (but this generally isn’t a big deal). • There are many standalone A/D and D/A converters on the market to choose from. ECE 3430 – Intro to Microcomputer Systems Fall 2014