0% found this document useful (0 votes)
20 views58 pages

MicroprocessorBasedSystems Term-II Lec2 ADC and DAC Interface

The document discusses analog to digital converters (ADCs), including how they sample and hold analog input signals, convert them into digital values based on their resolution, and how precision and accuracy relate to the conversion process. ADCs are used to convert analog sensor signals to digital values that can be read by microcontrollers. Common resolutions for microcontroller ADCs range from 8 to 16 bits.

Uploaded by

Mohamed Salah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views58 pages

MicroprocessorBasedSystems Term-II Lec2 ADC and DAC Interface

The document discusses analog to digital converters (ADCs), including how they sample and hold analog input signals, convert them into digital values based on their resolution, and how precision and accuracy relate to the conversion process. ADCs are used to convert analog sensor signals to digital values that can be read by microcontrollers. Common resolutions for microcontroller ADCs range from 8 to 16 bits.

Uploaded by

Mohamed Salah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

E1322

Microprocessor based Systems II

‘ADC/DAC Interface and Signal Conditioning’

Dr. Ahmed El-Awamry

Date: 17.02.2024, Time: 15:00


Objective

▪ Be able to include the ADC and DAC with the


appropriate signal condistioning in an
embedded system.

© Dr. Ahmed El-Awamry 17.02.2024 2


ADC Devices

▪ ADCs (analog-to-digital converters) are


among the most widely used devices for data
acquisition
▪ A physical quantity, like temperature, pressure,
humidity, and velocity, etc., is converted to
electrical (voltage, current) signals using a device
called a transducer, or sensor
▪ We need an analog-to-digital converter to
translate the analog signals to digital
numbers, so microcontroller can read them

© Dr. Ahmed El-Awamry 17.02.2024 3


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

time

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

time
• Sample – the action of duplicating the voltage value of the input
signal.

• Hold – the action of holding the voltage for a brief amount of time by
use of a capacitor.
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

time
• The Sample is accomplished by momentarily connecting the signal to
a capacitor in order to charge it up to the same voltage.
• The Hold is accomplished by disconnecting the signal and allowing
the conversion to be conducted on the voltage on the capacitor.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

time

• The Sample-and-Hold circuitry is designed so that this can be


accomplished very quickly so that it can disconnect from the input
signal as soon as possible to avoid altering its signal integrity.
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+

VR- time
• Input Voltage Range – The voltage is digitized within a range of
voltages from:
o Voltage Reference High (VR+)
o Voltage Reference High (VR-)

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+

VR- time
• The goal of the conversion is to convert the analog voltage into a
digital number.
• This is called digitizing, quantizing, or discretizing.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1
0
VR- time
n=1
Sample=0
• n represents the number of bits in the digital value of the conversion.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1
0
VR- time
n=1
Sample=0
• n represents the number of bits in the digital value of the conversion.
• The input voltage range is divided into 2n discrete zones.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1
0
VR- time
n=1
Sample=0
• The larger the n, the closer the digital value is to the actual analog
voltage.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
11
10
01
00
VR- time
n=2
Sample=01
• The larger the n, the closer the digital value is to the actual analog
voltage.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
111
110
101
100
011
010
001
000
VR- time
n=3
Sample=010
• The larger the n, the closer the digital value is to the actual analog
voltage.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The larger the n, the closer the digital value is to the actual analog
voltage.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The number of bits n is called the ADC’s resolution.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The number of bits n is called the ADC’s resolution.
• MCU’s typically have ADC’s with resolutions of 8 to 16 bits.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The number of bits n is called the ADC’s resolution.
• MCU’s typically have ADC’s with resolutions of 8 to 16 bits.
• The MSP430 has up to 12-bits of resolution.
• The STM32 has up to 16-bits of resolution
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The precision of an ADC is the smallest voltage that the LSB of the
digital output can represent.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The precision of an ADC is the smallest voltage that the LSB of the
digital output can represent.
• This is found by dividing the input voltage
range by the number of discrete zones.
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+

VR- time

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The original analog value is found by multiplying the digital
conversion result (NADC) with the resolution.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

VR-

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The accuracy is how close the digital output is to the input signal.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR-
Sample=0100
• The accuracy is how close the digital output is to the input signal.
• By design, an ADC will only ever be able
to get within +/- ½ LSB of the original
analog value.
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

VR-

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100


1000

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111


1000

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111


1000 0101

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001


1000 0101

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001


1000 0101 1101

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

• The voltage can be sampled over time to create a list of digital


values.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

TSA
• The sample period (TSA) is the time between samples.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

TSA
• The sampling rate is the frequency of sampling: fSA= 1/TSA

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

TSA
• The sampling rate is the frequency of sampling: fSA= 1/TSA
• This has units of samples-per-second (i.e., ksps, Msps).
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

• If you sample fast enough, you can reconstruct the original signal.

ANALOG TO DIGITAL CONVERTERS


ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

• If you sample fast enough, you can reconstruct the original signal.
• Nyquist-Shannon Sampling Theorem states you need to sample at
least twice as fast as the frequency of the incoming signal to
accurately reconstruct the original waveform.
ANALOG TO DIGITAL CONVERTERS
ANALOG TO DIGITAL CONVERTERS

ANALOG TO DIGITAL CONVERTERS

VR+
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001

time
0000

n=4 VR- 0100 0111 1001 1110


1000 0101 1101 1101

• The MSP430FR2355 can sample up to 200 ksps.


• The STM32F/STM32H can sample up to 3.6 Msps

ANALOG TO DIGITAL CONVERTERS


© Dr. Ahmed El-Awamry 17.02.2024 41
ADC 0804

© Dr. Ahmed El-Awamry 17.02.2024 42


ADC 0804

© Dr. Ahmed El-Awamry 17.02.2024 43


ADC 0804

© Dr. Ahmed El-Awamry 17.02.2024 44


ADC 0804

▪ The following steps must be followed for data


conversion by the ADC804 chip
▪ Make CS = 0 and send a low-to-high pulse to pin WR to
start conversion
▪ Keep monitoring the INTR pin
▪ If INTR is low, the conversion is finished
▪ If the INTR is high, keep polling until it goes low
▪ After the INTR has become low, we make CS = 0 and send
a high-to-low pulse to the RD pin to get the data out of the
ADC804

© Dr. Ahmed El-Awamry 17.02.2024 45


ADC 0804

© Dr. Ahmed El-Awamry 17.02.2024 46


ADC 0804

© Dr. Ahmed El-Awamry 17.02.2024 47


ADC0804 and LM35 Temp. Sensor

© Dr. Ahmed El-Awamry 17.02.2024 48


ADC0809

© Dr. Ahmed El-Awamry 17.02.2024 49


ADC0809

▪ Steps to Program ADC808/809


▪ Select an analog channel by providing bits to A, B,
and C addresses
▪ Activate the ALE pin
▪ It needs an L-to-H pulse to latch in the address
▪ Activate SC (start conversion ) by an H-to-L pulse
to initiate conversion
▪ Monitor EOC (end of conversion) to see whether
conversion is finished
▪ Activate OE (output enable ) to read data out of
the ADC chip
▪ An H-to-L pulse to the OE pin will bring digital data out of
the chip
© Dr. Ahmed El-Awamry 17.02.2024 50
ADC0809

© Dr. Ahmed El-Awamry 17.02.2024 51


© Dr. Ahmed El-Awamry 17.02.2024 52
Example Code
;Latch channel select
ale equ P3.4
setb ale
oe equ P3.7
;Start conversion
start equ P3.5
setb start
eoc equ P3.6
clr ale
sel_a equ P3.1
clr start
sel_b equ P3.2
;Wait for end of conversion
sel_c equ P3.3
jb eoc, $ ; $ means jump to same location
adc_data equ P1
jnb eoc, $
org 0H
;Assert read signal
;Data port to input
setb oe
mov adc_data, #0FFH
; Read Data
;EOC as Input
mov A, adc_data
setb eoc
clr oe
;rest of output signals
;ADC data is now in accumulator
clr ale
;Start over for next conversion
clr oe
sjmp main_loop
clr start
end
main_loop:
;Select Analog Channel 1
setb sel_a
clr sel_b
clr sel_c
© Dr. Ahmed El-Awamry 17.02.2024 53
DAC Interface

© Dr. Ahmed El-Awamry 17.02.2024 54


© Dr. Ahmed El-Awamry 17.02.2024 55
Generating Sine-Wave

ORG 0000H ; Start of program


MOV DPTR, #SINE_TABLE ; DPTR points to the start of the sine table
; Main loop
MAIN_LOOP:
CLR A ; Clear accumulator
MOVC A, @A+DPTR ; Move sine value into accumulator
MOV P1, A ; Output accumulator to port 1 (connected to DAC)
INC DPTR ; Move to next value in sine table
CJNE A, #END_OF_TABLE, MAIN_LOOP ; Check if at the end of table
MOV DPTR, #SINE_TABLE ; Reset pointer to start of table
SJMP MAIN_LOOP ; Jump back to start of main loop

; Sine table and end marker


SINE_TABLE:
DB 128, 131, 134, ... ; Sine values, scaled and shifted
END_OF_TABLE: DB 255 ; End of sine table marker (example)
END ; End of program

© Dr. Ahmed El-Awamry 17.02.2024 56


© Dr. Ahmed El-Awamry 17.02.2024 57
Appendix

You might also like