Objectives: To introduce the basics of digitaltoanalog and analogtodigital conversion and the sampling theorem. 
Topics covered:
Before moving on to digitaltoanalog converters (DAC) and analogtodigital converters (ADC), let us examine some useful fundamentals of analog amplifiers. In particular, you will observe how the opamp is used to create a DAC and an analog comparator.
With the advent of integrated circuits, the designer of electronic circuits need not be concerned with the inner workings of an IC package, whether digital or analog. Each circuit can be treated as a "black box" and quite often one considers the "ideal" case and ignores the limitations. This is true for analog amplifiers which are also known as operational amplifiers or opamps for short.
The ideal opamp has
These properties mean that the opamp
That's quite a tall order and real opamps come very close to the ideal. Observe that you cannot generate an infinite voltage. There is no such thing as a "free lunch". The voltage output from the opamp will be limited to the supply voltages (called the supply rail). Similarly, the current output will be restricted by the output impedances of the opamp and the power supply.
Here are typical specifications for the popular "741" operational amplifier.
µA741 opamp Data Sheet 11 pages, 162KB pdf
Ideal opamp 
741 opamp 

Voltage Gain 
infinite 
200,000 
Bandwidth 
infinite 
1MHz 
Input Impedance 
infinite 
2M ohms 
Output Impedance 
0 
75 ohms 
What this means is that quite often we can design an analog circuit using idealized circuits and not worry about the limitations of the opamp. The circuits below are some basic ways of using opamps.
The slew rate is another measure of the bandwidth of an amplifier. It is a measure of how quickly the output can change and is recorded in units of voltage/time (usually V/µs). 
We think of positive feedback as having pleasant connotations. In control systems, positive feedback causes unfettered growth, runaway behaviour and sometimes oscillations. In electronics, negative feedback is a desirable thing. With lots of excess gain, the opamp can use negative feedback to limit the overall voltage gain of the circuit. With negative feedback come many benefits such as reduced nonlinearity and lower output impedance. Negative feedback is the control mechanism to keep things in check.
This is the basic circuit from which all others can be derived. All opamps are designed to amplify the voltage difference between the noninverting (+) and inverting () inputs while ignoring any commonmode signal that may be common to both. The ability to reject the common signal while amplifying the differential input is called the commonmode rejection ratio (CMRR).
Lots of negative feedback is used to control the voltage gain of the amplifier.
Recall the simple
DAC circuit in Chapter 7, Problem 8. By adding an opamp to
the circuit any loading effect on the resistor network is virtually eliminated.
An analog or voltage
comparator compares two input voltages and determines which is higher or lower. Since the voltage gain is infinite
the output voltage could have only one of two values, equal to the negative or positive supply rail. Thus an input
signal with a continuous analog range is converted to a digital signal. This is a 1bit ADC.
What is the output of the comparator when the input voltage V_{in} is equal to the reference voltage V_{ref}? 
When an analog waveform is sampled, the voltage signal which is continuous in both amplitude and time is digitized. This digitization process results in quantization effects in both domains which lead to important consequences. In the amplitude domain, the resolution is determined by the number of bits of the ADC. Thus an 8bit ADC can digitize the input signal into 255 voltage steps, equivalent to a precision of 0.4%. The following table shows the effects of various number of ADC bits.
No. of ADC bits 
No. of Steps 
Precision 
8 
255 
0.4 % 
10 
1023 
0.01 % 
12 
4095 
0.02 % 
14 
16383 
0.006 % 
16 
65535 
0.0015 % 
The resolution in the time domain is determined by the sampling rate, that is, how many samples per second are recorded. The sampling or Nyquist theorem states that the sampling frequency must be at least twice the highest frequency being recorded. The corollary to this is that there must be no frequency component in the signal that is greater than onehalf of the sampling frequency.
The sampling theorem can be illustrated graphically. The following diagrams show a sinewave signal being sampled at different sampling rates. The dashed line represents an approximation of the reconstructed waveform for illustrative purposes.
Here the sampling
frequency, f_{s}, is the same as the input sinewave. The reconstructed waveform is a DC value.
When f_{s}
is increased, the reconstructed waveform is a low frequency signal which is an alias of the true input frequency.
When f_{s}
is greater than twice the input frequency, the reconstructed waveform has a frequency component that represents
the input waveform.
The Nyquist limit is the highest frequency component which can be recorded for a given sampling frequency. This limit is equal to onehalf of the sampling frequency. For example, it is generally accepted that the range of human hearing (and highfidelity musical recordings) is 20Hz to 20KHz. The standard sampling frequency for digital recordings (CD) is 44.1KHz. It is interesting to note that increasing the sampling frequency does not improve on the quality of the recorded signal. Only the Nyquist limit is raised to a higher level.
A timevarying signal can be represented graphically in a voltage vs time display in the time domain. The same information can be transformed into amplitude vs frequency in the frequency domain. This conversion from the time domain to the frequency domain is performed by the process called Fourier transformation. It is useful to consider the sampling theorem in frequency space.
If the sampling frequency is f_{s}, then the Nyquist limit is f_{N} = ½ f_{s}.
The input frequency f_{i} must be less than the Nyquist limit f_{N}.
More importantly, the corollary of the Nyquist theorem is that there must be no frequency component in the input
signal which is greater than the Nyquist limit.
(a) Interface the AD558 8bit DAC to a parallel port as shown. Write a simple program to exercise the DAC as follows. Generate a sawtooth ramp by outputting the values from 0 to 255 in a continuous loop. Determine the period and frequency of the output waveform. What information does this reveal about the execution time of your program?
(b) Generate a sine wave and display the waveform on the oscilloscope.
AD558 Data Sheet 8 pages, 335KB pdf
The
tracking ADC is the simplest ADC you can build by adding an up/down counter
and an analog comparator as shown in the block diagram. In this ADC, an incremental
step is made at every clock period in an attempt to get closer to the unknown
input signal. The direction of the desired step is determined by comparing the
output of the DAC with the input signal.
Construct
the LM311 comparator circuit as shown and interface the output to an input pin
of the MCU. This signal is to be interrogated by the computer in order to determine
the direction of the required step.
As an alternative, use the internal analog comparator of the MCU.
What is the sampling frequency of your ADC? What is the Nyquist limit?
The successive approximation algorithm is a classic example of any computer algorithm which may be simple or intricate. In either case, you should always present the solution at first in the form of a flowchart and/or pseudocode before attempting to write programming instructions. The algorithm must be a complete solution, meaning that if it does not work on paper then you cannot expect its implementation to work. Furthermore, the algorithm must be written in plain language or using algebraic nomenclature. In other words, the solution must be devoid of computer jargon or terminology and must be independent of any computer language or processor architecture. 
Use the internal ADC of the MCU and test using a simple program. Use the internal
timer to record samples every 500µs. Digitize an external sinewave input
and generate the reconstructed waveform using the AD558 DAC. Compare the input
wave with the reconstructed wave on the oscilloscope. Playback the reconstructed
wave through an audio amplifier and loudspeaker. You may need a lowpass filter
to remove clock frequencies.
2007.01.04