Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Computer System Applications: Design and Development Laboratory Manual Dr Mohammad Jahangir Ikram Department of Computer Science Lahore University of Management Sciences Laboratory 3 Contents: 1. The A/D and D/A Conversion 1.1. Introduction 1.2. The Digital to Analog Conversion 1.2.1. The Basic Conversion and Study of Quantization Error 1.2.2. Waveform Generation 1.3. The Analog to Digital Conversion 1.3.1. Study of Basic Conversion 1.3.2. Basic DSP Techniques 1.4. Programming Project: FFT Analysis Analog to Digital and Digital to Analog Conversion What is digital? Digital comes from the word digit, which in the world of computers means binary numbers. Computers on their on can deal with digits like adding, subtracting, at very high speed. Our daily life, on the other hand, is not really digital. Shades of Gray: An Example We not only see black and white but we also see shades between black and white, that is, gray. When you look at a gray color, you probably never think about the percentage of black and white that has been mixed to make that gray color, unless someone asks. As an example take a look at the following Diagram. This shows a gradient (slow increase) of white color to black color. In between those two colors, it can said that there are infinite number of shades of gray and it is not so easy to tell the exact ratio of black and white at, say, point A. It can be 1:1 or 1:1.1 or 1:1.234 or 1:1.234567 depending on how good you can measure. White Black Point A This kind of ambiguity is not good in the world of computers. So we need to ‘digitize’ the colors. Now look at the following Diagram. It has four shades including black and white. Now for the following four shades with equal steps from white to black, we can exactly tell the ratio of black and white. Either we can tell that from the ratio table used to make these shades (3:0, 2:1, 1:2, 0:3) or we can simply number them, 0 (00) 1 (01) 2 (10) 3 (11) ‘0’, ‘1’, ‘2’, ‘3’, with ‘0’ being the whitest and ‘3’ being the blackest. A binary number or count can also be associated to represent the shade as shown in the Diagram below. It is important to know that the numbers associated with shades are mere representation for our reference. We could have called them a,b,c,d or majha, sajha, goga, boota, or anything we like. A representation tells about the reality, Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Experiment 3 Page 1 an ‘a’ (or ‘majha’) would then mean white and so on. As we know from the knowledge of digital numbers, two binary numbers can only represent 4 different shades including white and black. What if we had three binary digits to represent the shades? The new Diagram will look like below. This shows that by increasing the representation numbers we can now show more shades of gray. If someone ask about shade 4 in a range 0-7, we call exactly tell about the ratio of black and white. 0 (000) 1 (001) 2 (010) 3 (011) 4 (100) 5 (101) 6 (110) 7 (111) Using 4 binary numbers (0001) (0011) (0101) (0111) (1001) (1011) (1101) (1111) to represent each shade as 1 5 9 13 11 3 15 7 shown below can further increase the ‘resolution’ of shades between black and white. Now a shade 5 on range 0 to 15 is perfectly understood and there is no 0 4 2 6 8 10 12 14 ambiguity in it. In binary (0000) (0100) (0010) (0110) (1000) (1010) (1100) (1110) language, we can say a shade 0101 between 0000 1111 is perfectly understood. Now it can be said that the shades of gray has been ‘digitized’. A further increase in steps between shades will require more numbers to represent a shade. An 8-bit binary number can represent 256 gray shades and a 24-bit binary number can represent 16777216 or 16 million gray shades. Remember, the more are the steps in shades, more is the resolution of the color and more we get closer to figure 1, that is, infinite number of shades, the real thing. Another Example: Another useful example is to represent a voltage. Say we have a variable voltage source of 0-9 volts and we randomly set the output voltage near the center. Now we use a ‘needle’ voltmeter to measure the voltage and suppose the meter gives the following observation. What can you say about the reading, is it 4.95, 4.98, 4.94, 4.9394, 4.953467V? Yes, again there is some ambiguity. Leave the voltmeter aside and let us think about ‘digitizing’ the voltage. If we divide the voltage between 0-9V in 0 four steps, we have 0V, 3V, 6V, 9V. Again we can choose some other numbers (or letters) to represent these voltages. It can be: I. ‘0’,’1’,’2’,’3’ II. ‘00’, ‘01’,’10’,’11’, III. ‘a’,’b’,’c’,’d’, IV. ‘majha’, ‘sajha’, ‘goga’, ‘boota’ 4 Saad Jamal Instruments 8 Volts A ‘1’ or ‘01’ or ‘b’ or sajha would mean exactly 3.0000V. Since computers play with binary numbers, we choose binary numbers to represent our voltage as shown in the table below. Lahore University of Management Sciences CS324 Voltage Binary Representation 0V 00 3V 01 6V 10 9V 11 Dr Mohammad Jahangir Ikram Experiment 3 Page 2 This means 00 represent 0V, 01 represent 3V and so on. This can also be shown in a Diagram as below. 6V (10) 3V (01) 0V (00) 9V (11) Now if we chose three binary numbers to represent a voltage, the table will be: The above table is created by the fact that there are 8 steps between 0 to 9V, so each step will 9/8 = 1.125V. 0V (000) 9V (101) Can you show this on the following Diagram? Similarly, using four binary numbers, we can build the following table (shown . This time step size is 9/16 = 0.5625, even smaller than before. Again write the representations on the above Diagram. Voltage Binary Representation of voltage 0.000V 000 1.125V 001 2.250V 010 3.375V 011 4.500V 100 6.750V 101 7.875 110 9.000V 111 When we use four binary numbers to (0000) represent a voltage between 0-9V we get a step size of 0.5625V or nearly ½ V. Which is not very good. If we use 8-bits to Binary Voltage represent a voltage between 0 – 9V, we get a step size of 9V/256 = Representation of 0.03515625 or nearly 35mV. That means a ‘00000000’ would mean 0V and voltage ‘11111111’ would mean 9V. A ‘00000001’ would mean 0.03515625V 0.0000V 0000 precisely, and hence no ambiguity at all. A ‘10110011’, which is 179 in 0.5625V 0001 decimal would represent 9V/256 X 179 = 6.29296875V to be precise. 9V (1111) 0V Review Questions: 1) 8 bit are used to represent voltage between 0-9, what voltage is 1001111? ___________ 2) Repeat above for 11110000 ___________, 11101010 ________, 11001100 __________ . 3) If 12 bits are used to represent a voltage between 0-9V what will be the step size? 4) If 12 bits are used to represent a voltage between 0-5V what will be the step size? 0 Analog to Digital Converter (ADC) VIN (0- VMAX) 1 2 3 N-Bit Digital Output representation. (000 --- 0 = 0V and 111 … 1 = VMAX) N 5) If 12 bits are used to represent a voltage between 0-1V what will be the step size? Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram 1.1250V 0010 1.6875V 0011 2.2500V 0100 2.8125V 0101 3.3750V 0110 3.9375V 0111 4.5000V 1000 5.0625V 1001 6.1875V 1010 6.7500V 1011 7.3125V 1100 7.8570V 1101 8.4375V 1110 9.0000V 1111 Experiment 3 Page 3 Now all we need is a device that has analog (real) voltage input and an n-binary-number output as digital representation. Such a device is called analog to digital converter (as shown in the diagram on the previous page). The symbol of such a device is shown below: Thousands of types of ADC are available in the market in the form of integrated circuits. As designer most people do not need to study the actual mechanism of analog to digital conversion and they use these ICs as such according the application notes available from the manufacturer. National Semiconductors is one of the companies that makes ADCs and part search on national website: www.national.com can give you a lot of information on ADCs along with application notes. The Anatomy of ADCs Almost all ADCs are made of one or more of the following components: 1) 2) 3) 4) Comparator Digital to Analog Converter (DAC) A Digital Counter An AND gate. Voltage Comparator Circuit Figure 7-4 shows the connections to a basic operational amplifier comparator. The comparator has two input terminals, V1 and V2, and a single output technical, V0. The voltage comparator compares two analog input voltages and produces a digital output signal. The output is high if V1 is more positive than V2; otherwise, the output is low (if V1 is less than V2). This circuit is used in analog to-digital (A/D) converters to determine if an analog input signal (V1) is greater than or less than a reference voltage (V2). Digital-to-Analog A digital-to-analog (D/A) converter is a circuit that produces an analog Figure 7-4 Voltage output voltage that is a function of a weighted parallel binary input. The output comparator voltage varies in steps, with the smallest possible step being controlled by the least significant bit (LSB) of the input. For example, a four-bit D/A converter would have 42, or 16, possible output levels. The output might range from 0 to 15 mV, the difference between any two adjacent levels being 1 mV. If the input were stepped sequentially through all 16 possible binary combinations (i.e., 0 through 15), the output voltage would look like a staircase increasing in 1-mV steps from 0 to 15 mV. Figure 7-5 Operational amplifier R-2R resistive ladder D/A converter Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Experiment 3 Page 4 Most D/A converters use a weighted resistive ladder network in the form of ~n integrated circuit combined with an operational amplifier, like that of Figure 7-5, to convert binary inputs to an equivalent analog output voltage. The output voltage is incremented in steps of –1/2N times the voltage corresponding to a logic 1 of any of the, binary inputs, where N is the number of bits. For example, if a 4-bit weighted resistor network is used, and the 4-bit inputs are set at b0 = 1, b1 = 0, b2 = 1, and b3 = 0 (01012 = 510), then the output voltage of the D/A converter of Figure 7-5 equals –5/16 times the logic 1 voltage of the logic family used. If TTL devices are used, then the logic 1 voltage is nominally 5 V. Thus this 4-bit D/A converter has voltage increments of (–1/16)(5 V) = – 312.5 mV over the output range from 0 (all inputs at logic 0) to-5 V (all inputs at logic 1). If the binary inputs are 01012, as above, the output voltage is – 1.5625 V. The Analog to Digital Converter 1. Staircase Ramp A/D Converter Figure 7-8 A 4-bit staircase ramp A/D converter. (a) Block Diagram (b) The binary counter stops when VR exceeds Vin One of the simplest A/D converters uses the staircase ramp technique illustrated in Figure 7-8. The principle is similar to the ramp A/D converter discussed earlier in this chapter, but the ramp generator is replaced in this case with a D/A converter. The output of the D/A converter is a 'staircase serving the same purpose as the analog ramp in the ramp converter. At the start of a conversion cycle, the Counter is reset to zero; the output of the D/A converter is also zero. At this point, the output of the comparator is high, and the clock pulses go through the gate to the counter. As the count increases, the staircase waveform proceeds in increments towards Vin. When the staircase voltage level exceeds Vin, the output of the comparator goes low, and the count stops. The count is converted in decimal, term, and is used to update the display. The cycle then repeats itself. Successive Approximation A/D Converter The two major drawbacks of the A/D converters like dual-slope and staircase ramp A/D converters are that (1) they are relatively slow and (2) the conversion time is a function of the magnitude of Vin. The successive approximation A/D converter overcomes both these problems to a considerable degree. It makes conversions in microseconds rather than the several milliseconds required by the ramp, dual-slope, staircase converters. Although the block diagram for the successive approximation A/D Converter in Fig. 7-9 looks very much like that of a staircase ramp A/D converter, it differs in the control logic section. Instead of allowing the staircase to climb from zero through all sequential steps up to Vin it first tries a step equivalent to the most significant bit of the converter. If this step does not exceed the value of Vin, it is retained in the storage register. Otherwise, the storage register is set to zero. Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Figure 7-9 A 4-bit successive approximation A/D converter Experiment 3 Page 5 The next largest bit is then tried and so on until all bits have been tried in order of decreasing size. A significant feature system is that it takes only N steps to produce an N-bit output, regardless of the magnitude of the input signal. The conversion time of the successive approximation converter is a constant and is given by N/f, where N is the number of bits in the converter, and f is the clock frequency. Thus, a 10-bit converter with a 1-MHz clock makes a conversion every 10s. Flash Converter As the name applies, this ADC is the fastest ADC but at the same time, it is very expansive. It uses almost 2N operational amplifiers to give N-bit output. Further detail is beyond the scope of this course. Experiment 3: Analog to Digital Conversion In this experiment, we will study the working of Integrated Circuit Analog to Digital Converter (ADC). Pin Description of this IC is as follows: CS (chip Select) is coming from the port decoder (big AND gate). Note that the IC has internal output Latch as well as a buffer. RD is to read the output. WR is start conversion INTR is end of conversion CLK In, CLK R are used for external clock generation. Vin (+) and Vin(-) are pins where you apply external ANALOG input. DB0 to DB7 are Digital 8-bit output. VREF/2 is used to set the input analog range. A 2.5V on this pin will set range to 0 (output 00000000) to +5V(output 111111112). Analog and Digital GND are usually common. Self Running Mode. Usually, ADC are interfaced with computers though Interrupts. If you are polling, then ADC are usually used in Self-running mode. In self running mode Interrupt(end of conversion) output of the IC is tied with RD (start Conversion), making the IC to continuously do conversions with out the intervention of a CPU. However, a kick-start switch is required at power-up. Following is the diagram used in this experiment. Note that you have to press the kick start button ONLY 10K +5V once at power-up time. Question 1: Why do we need kick start button? Question 2: What is the step size of the ADC shown in figure. Analog Input Digital Output Kick Start 30pF Digital Output Vary the input voltage and measure it on the analog multimeter. Read the corresponding digital output using computer and fill the following table for a number of readings. 0-5V Variable Difference 2.5 Volt Switch Programming Assignment For LAB 3 Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Experiment 3 Page 6 Write a software for digital voltmeter as explained in the LAB. Laboratory Fill the blanks for the following and get it signed by the TA 1. The maximum out put in binary is __________ 2. The maximum analog input for that output is _________ 3. What is digital output for 3.000 Volts input 4. What is step size in millivolts.___________ 5. Using digital meter find the digital output values for closest following voltages: a. 3.12 V _________ b. 2.5 V __________ c. 3.6 Volts ________ 6. In all the above cases what is maximum difference between required output and the output that can be achieved. ___________________ 7. How can you relate results in 4 and 5 ____________________________ ____________________________________________________________________ ____________________________________________________________________ Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Experiment 3 Page 7 Computer System Applications: Design and Development Laboratory Manual Dr Mohammad Jahangir Ikram Department of Computer Science Lahore University of Management Sciences Read Laboratory Notes carefully before you come to the class. Laboratory 4 Digital to Analog Conversion Connect the circuit as you will connect for the 8-bit DIP switch status Repeat the above experiment part 1 in reverse order, that is for an digital input find a analog output and make table as big as possible. What is step size of the DAC_____________________ What is the minimum and maximum analog output.____________ , ___________ What would have been the step size if the DAC had 12-bit input _______________ Can you find the conversion time of DAC __________________ Fill the blanks for the following and get it signed by the TA 1. The maxim out put in Volts is __________ 2. The maximum digital input for that input is _________ 3. What is digital input for 3.000 Volts (Use digital meter) 4. What is step size in millivolts.___________ 5. Using digital meter find the digital input values for closet following voltages: 6. 3.12 V _________ 7. 2.25 V __________ 8. 1.76 Volts ________ 9. In all the above cases what is maximum difference between required output and the output that can be achieved. ___________________ 10. How can you relate results in 1.2.1.8 and 1.2.1.10 ____________________________ ____________________________________________________________________ Lahore University of Management Sciences CS324 Dr Mohammad Jahangir Ikram Experiment 3 Page 8 ____________________________________________________________________ 1.2.1.1 For the plot of following sinusoidal waveform find approximate voltage level after each mSec and write a software that will generate a ‘stepped’ simusoidal at the DAC output. 4Volts 0 Volts Lahore University of Management Sciences CS324 Time in mSec Dr Mohammad Jahangir Ikram Experiment 3 Page 9