Lecture 4
Lecture 4
Lecture #4
ADC and DAC Interfacing
SPRING 2022
Instructor:
Dr. Hesham H. Amin
ADC Conversion
➢ This chapter explores real-world devices such as
ADCs, DACs, and sensors.
➢ Explain how to interface AVR to these devices.
➢ The process of A/D conversion involves:
✓Band-limiting the analog signal
✓Setting periodic sampling points (setting
sampling period) at which the continuous time
analog signal is going to be digitized.
✓Freezing analog signal at sampling points so
that signal doesn’t change for duration of
conversion (sample & hold)
✓Determining what digital value best represents
the analog signal level (quantizing).
Periodic Sampling
➢ Now that we have limited the bandwidth of the signal, we
need to sample it.
➢ The Nyquist/Shannon theorems say that you need to
sample the signal at least at twice the maximum frequency
contained in the signal.
➢ E.g., if you limited your signal to a max frequency of 10Hz,
You should sample it at least at 20Hz, i.e., 20 times a
second).
➢ In many cases though we start from the sampling
frequency and having a good understanding of that we
limit the signal to at most half of that.
➢ This is superposition of two sine signals with a higher frequency = 4
➢ Thus, to be able to reconstruct the signal (without loosing any of its
features) we need to sample at least 8Hz.
➢ So, what happens if we over- or under-sample?
Oversampling
➢ If original signal was
nicely limited,
oversampling will
result in more
samples than we
need for processing
and reconstruction
(i.e., burden on our
calculations/
processor time)
➢ Shown here is 20
samples per second
(a sampling clock of
20Hz)
Undersampling
➢ Undersampling will
result losing the
features of a signal.
➢ If we wanted to
reconstruct the signal
the reconstructed
signal (red) would not
look the same as the
original (black) signal
➢ What is the sampling
clock used here?
Hold after Sample
➢ We need circuitry
that can
“remember” (hold)
the analog voltage
at the sampling
time
Quantization
➢Now that the signal is not changing for
some time (depending on the sampling
period), we need to determine what digital
value best represents the analog level.
➢This will take some time, which should not
be more than the sampling period!
➢There are many methods of doing this,
many microcontrollers use “successive
approximation” to do this.
ADC CHARACTERISTICS
➢ ADC converters are among the most widely used
devices for data acquisition.
➢ Digital computers use binary (discrete) values, but in the
physical world everything is analog (continuous).
➢ Temperature, pressure (wind or liquid), humidity, and
velocity are a few examples of physical quantities that
we deal with every day.
➢ Physical quantity converted to electrical (voltage,
current) signals using transducer (also referred to as
sensor).
➢ Sensors for temperature, velocity, pressure, and other
natural quantities produce output that is voltage/current.
➢ We need ADC converter to translate analog signals to
digital numbers so that MC can read & process them.
ADC CHARACTERISTICS
➢ Resolution versus Step Size for ADC (Vref = 5 V)
Major Characteristics of ADC
Resolution:
➢ ADC has n-bit resolution, n = 8,10,12,16, or 24 bits.
➢ Higher-resolution ADCs provide a smaller step size
➢ step size is the smallest change that can be discerned
by an ADC.
➢ Although the resolution of an ADC chip is decided at
the time of its design and cannot be changed, we can
control the step size with the help of Vref
Major Characteristics of ADC
Conversion time
➢ is defined as the time it takes the ADC to convert the
analog input to a digital (binary) number.
➢ The conversion time is dictated by
✓the clock source connected to the ADC
✓the method used for data conversion
✓technology used in the fabrication of the ADC chip such as
MOS or TTL technology.
Major Characteristics of ADC
Vref
➢ Vref is input voltage used for the reference voltage.
➢ Voltage connected to this pin, along with resolution of the
ADC chip, dictate the step size.
➢ For 8-bit ADC, step size is Vref/256.
➢ if analog input range needs to be 0 to 4 volts, Vref = 4V.
That gives 4V/256=15.62 mV for step size of an 8-bit ADC.
➢ if we need a step size of 10 mV for an 8-bit ADC, then
Vref= 2.56 V, because 2.56V/256 = 10 mV.
Major Characteristics of ADC
➢ For 10-bit ADC, if Vref = 5V, then the step size is 4.88 mV
➢ In some applications, we need the differential reference
voltage where V = Vref (+) −Vref (−).
➢ Often the V (−) pin is connected to ground and the Vref (+)
pin is used as the Vref.
Major Characteristics of ADC
➢Digital data output
➢ In 8-bit ADC we have 8-bit digital data output of D0–D7,
in10-bit ADC data output is D0–D9.
➢ To calculate output voltage, we use the following formula:
Dout =Vin/step_size
➢ Dout = digital data output (in decimal), Vin = analog input
voltage, and step size (resolution) is the smallest change,
which is Vref/256 for an 8-bit ADC
➢ This data is brought out of the ADC chip either one bit at a
time (serially), or in one chunk, using a parallel line of
outputs.
Example
For an 8-bit ADC, we have Vref = 2.56 V.
Calculate the D0–D7 output if the analog input is:
(a) 1.7 V, and (b) 2.1 V.
➢ Bit 5 ADC Left Adjust Results: dictates either the left bits
or the right bits of the result registers ADCH:ADCL that are
used to store the result. If ADLAR = 1, the result will be left
adjusted; otherwise, the result is right adjusted.
➢ Bit 4:0 Analog Channel and Gain Selection Bits: select the
gain for the differential channels. Also select which
combination of analog inputs are connected to the ADC.
Vref source
➢Vref Source Selection Table for AVR
ADC input channel source
➢among ADC0 to ACD7.
In this case a single pin
is used as the analog
line, and GND of the
AVR chip is used as
common ground.
➢Table 5 lists the values
of MUX4–MUX0 bits for
different single ended
inputs.
ADC input channel source
➢ if choose differential
input, can also select
op-amp gain.
➢ can choose gain of the
op-amp to be 1x, 10x,
or 200x.
➢ can select positive
input of op-amp to be
one of the pins ADC0
to ADC7, and the
negative input of the
op-amp can be any of
ADC0, ADC1, or
ADC2 pins.
ADLAR bit operation
➢ In AVR two 8-bit registers are dedicated to the ADC
result, but only 10 of the 16 bits are used and 6 bits are
unused.
➢ Notice that changing the ADLAR bit will affect the ADC
data register immediately.
ADCSRA register
➢ ADCSRA register is status and control register of
ADC.
➢ Bits of this register control or monitor operation of
ADC.
ADCSRA register
➢ Bit 7 ADC Enable: enables or disables the ADC. Setting
this bit to one will enable ADC and clearing this bit to zero
will disable it even while a conversion is in progress.
➢ Bit 6 ADC Start Conversion: To start each conversion you
must set this bit to one.
➢ Bit 5 ADC Auto Trigger Enable: Auto triggering of the ADC
is enabled when you set this bit to one.
➢ Bit 4 ADC Interrupt Flag: is set when an ADC conversion
completes, and data registers are updated.
➢ Bit 3 ADC Interrupt Enable: setting it to one enables the
ADC conversion complete interrupt.
➢ Bit 2:0 ADC Prescaler Select Bits: determine division
factor between XTAL frequency and input clock to ADC.
ADC Start Conversion bit
➢ ADC has a Start Conversion input.
➢ AVR chip has a special circuit to trigger start
conversion.
➢ In addition to ADSC bit of ADCSRA there are
other sources to trigger start of conversion.
➢ If you set the ADATE bit of ADCSRA to high, you
can select auto trigger source
➢ Notice that there are many considerations if you
want to use auto trigger mode.
A/D conversion time
➢ Using ADPS2:0 bits we can set the A/D conversion time.
➢ To select the conversion time, select any of Fosc/2,
Fosc/4, Fosc/8, Fosc/16, Fosc/32, Fosc/64, or Fosc/128
for ADC clock
➢ Fosc: speed of crystal frequency connected to AVR Chip
➢ ADC requires an input clock frequency less than 200 kHz
for the maximum accuracy.
Example
An AVR is connected to 8 MHz crystal oscillator.
Calculate the ADC frequency for:
(a) ADPS2:0 = 001 (b) ADPS2:0 = 100 (c) ADPS2:0 = 111
(a) ADPS2:0 = 001 (1 decimal) → ck/2 input activated
8 MHz / 2 = 4 MHz (>200 kHz and not valid)
➢ D0: LSB, D7: MSB for inputs, and Iref is input current.
➢ Iref current is generally set to little mA (e.g., 2 mA).