ADC Interfacing With 8051
ADC Interfacing With 8051
MICRO-
CONTROLLERS
contains
AND ¾ No RAM
EMBEDDED ¾ No ROM
PROCESSORS ¾ No I/O ports
Microcontroller
Microcontroller has
vs. General- ¾ CPU (microprocessor)
Purpose ¾ RAM
Microprocessor ¾ ROM
¾ I/O ports
¾ Timer
¾ ADC and other peripherals
Microcontroller
vs. General-
Purpose Microcontroller
Microprocessor CPU RAM ROM
(cont’)
Serial
I/O Timer COM
Port
D7
Transmitter Receiver
Half Duplex
Receiver Transmitter
Transmitter Receiver
Full Duplex
Receiver Transmitter
ground
Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 15
DTR (data terminal ready)
BASICS OF ¾ When terminal is turned on, it sends out
SERIAL signal DTR to indicate that it is ready for
COMMUNICA- communication
TION DSR (data set ready)
¾ When DCE is turned on and has gone
RS232 Pins through the self-test, it assert DSR to
indicate that it is ready to communicate
RTS (request to send)
¾ When the DTE device has byte to transmit,
it assert RTS to signal the modem that it
has a byte of data to transmit
CTS (clear to send)
¾ When the modem has room for storing the
data it is to receive, it sends out signal CTS
to DTE to indicate that it can receive the
data now
Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 16
DCD (data carrier detect)
BASICS OF ¾ The modem asserts signal DCD to inform
SERIAL the DTE that a valid carrier has been
COMMUNICA- detected and that contact between it and
TION the other modem is established
RI (ring indicator)
RS232 Pins ¾ An output from the modem and an input to
(cont’) a PC indicates that the telephone is ringing
¾ It goes on and off in synchronous with the
ringing sound
MAX232 Vcc
C3
+
MAX232 requires
16 2 four capacitors
+
1 MAX232
C1
3 6 8051
4 C4
+
C2
+
MAX232
5 P3.1 11 11
TxD 14 2 5
T1in T1out
11 14
13 3
R1out R1in P3.0 10 12
12 13
RxD
T2in T2out
10 7
R2out R2int
DB-9
9 8
14 MAX233 11
12
15
8051
16
17 MAX233
10 P3.1 11 2
TxD 5 2 5
T1in T1out
2 5
4 3
R1out R1in P3.0 10 3
3 4
RxD
T2in T2out
1 18
R2out R2int
DB-9
20 19
Serial Data
Receiving COM Port RxD
P2 SW
(cont’)
SERIAL Solution:
COMMUNICA- (a) This program transfers ASCII letter B (01000010
binary) continuously
TION (b) With XTAL = 11.0592 MHz and SMOD = 1 in the
PROGRAMMING above program, we have:
Solution:
With XTAL = 11.0592 and SMOD = 1, we have timer frequency =
57,600 Hz.
(a) 57600 / 9600 = 6; so TH1 = -6 or TH1 = FAH
(b) 57600 / 4800 = 12; so TH1 = -12 or TH1 = F4H
TION Solution:
PROGRAMMING With XTAL = 11.0592 and SMOD = 1, we have timer frequency =
57,600 Hz. The baud rate is 57,600/2 = 28,800. This baud rate is
not supported by the BIOS of the PCs; however, the PC can be
Doubling Baud programmed to do data transfer at such a speed. Also,
Rate HyperTerminal in Windows supports this and other baud rates.
(cont’)
Solution:
Doubling Baud SW BIT P1.2
Rate MAIN:
ORG 0H ;starting position
;------------
MESS1: DB “The Earth is but One Country”,0
END
(cont’)
R/W tAS tPWH tAH
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 9
HANEL National Cheng Kung University 10
them
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 11
HANEL National Cheng Kung University 12
3
+5V power supply
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 13
HANEL National Cheng Kung University 14
Vref/2 D0-D7
INTERFACING INTERFACING
TO ADC AND ¾ It is used for the reference voltage TO ADC AND ¾ The digital data output pins
If this pin is open (not connected), the analog These are tri-state buffered
SENSORS SENSORS ¾
input voltage is in the range of 0 to 5 volts (the
The converted data is accessed only when CS =
same as the Vcc pin)
ADC804 Chip ADC804 Chip 0 and RD is forced low
If the analog input range needs to be 0 to 4
(cont’) volts, Vref/2 is connected to 2 volts (cont’) ¾ To calculate the output voltage, use the
following formula
Vref/2 Relation to Vin Range
V in
D out =
+5V +5V
Vref/2(v) Vin(V) Step Size ( mV)
6 Vin(+)
20
VCC
18 Not connected* 0 to 5 5/256=19.53 6 Vin(+)
20
VCC
D0 18
step size
D0
7 D1 17 7 D1 17
Vin(-)
2.0 0 to 4 4/255=15.62 Vin(-)
8
9
A GND
Vref /2
D2
D3
16
15
8
9
A GND
Vref /2
D2
D3
16
15 Dout = digital data output (in decimal),
14 1.5 0 to 3 3/256=11.71 D4 14
Vin = analog voltage, and
19 D4 19
13 13
CLK R D5
12
CLK R D5 12
D6
11 1.28 0 to 2.56 2.56/256=10 D6 11
step size (resolution) is the smallest change
D7 D7
4 CLK in
WR
3 1.0 0 to 2 2/256=7.81 4 CLK in
WR
3
INTR 5 INTR 5
1 CS 0.5 0 to 1 1/256=3.90 1 CS
2 RD 2 RD
10 10
D GND Step size is the smallest change can be discerned by an ADC D GND
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 15
HANEL National Cheng Kung University 16
4
The following steps must be followed
Analog ground and digital ground
INTERFACING INTERFACING for data conversion by the ADC804 chip
¾ Analog ground is connected to the ground
TO ADC AND TO ADC AND ¾ Make CS = 0 and send a low-to-high pulse
of the analog Vin to pin WR to start conversion
SENSORS SENSORS
¾ Digital ground is connected to the ground ¾ Keep monitoring the INTR pin
of the Vcc pin If INTR is low, the conversion is finished
ADC804 Chip ADC804 Chip If the INTR is high, keep polling until it goes low
(cont’) To isolate the analog Vin signal from (cont’) ¾ After the INTR has become low, we make
transient voltages caused by digital CS = 0 and send a high-to-low pulse to the
+5V switching of the output D0 – D7 RD pin to get the data out of the ADC804
6 Vin(+)
20
VCC
18
¾ This contributes to the accuracy of the CS
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 19
HANEL National Cheng Kung University 20
5
INTERFACING 8051 Connection to ADC804 with Self-Clocking INTERFACING 8051 Connection to ADC804 with Clock from XTAL2 of 8051
TO ADC AND TO ADC AND
SENSORS 8051 ADC804 5V
SENSORS 8051 ADC804 5V
D Q
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 21
HANEL National Cheng Kung University 22
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 23
HANEL National Cheng Kung University 24
6
Signal conditioning is a widely used
INTERFACING term in the world of data acquisition INTERFACING Getting Data From the Analog World
TO ADC AND TO ADC AND
¾ It is the conversion of the signals (voltage, Analog world (temperature,
SENSORS current, charge, capacitance, and SENSORS pressure, etc. )
resistance) produced by transducers to
Signal voltage, which is sent to the input of an A- Signal
Transducer
Conditioning to-D converter Conditioning
and Signal conditioning can be a current-to- and
Interfacing voltage conversion or a signal Interfacing Signal conditioning
LM35 LM35
amplification (cont’)
¾ The thermistor changes resistance with ADC
temperature, while the change of
resistance must be translated into voltage
in order to be of any use to an ADC Microcontroller
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 25
HANEL National Cheng Kung University 26
Example:
INTERFACING Look at the case of connecting an LM35 to an ADC804. Since the INTERFACING 8051 Connection to ADC804 and Temperature Sensor
ADC804 has 8-bit resolution with a maximum of 256 steps and the
TO ADC AND LM35 (or LM34) produces 10 mV for every degree of temperature
TO ADC AND 8051 ADC804 5V
SENSORS change, we can condition Vin of the ADC804 to produce a Vout of SENSORS VCC
2560 mV full-scale output. Therefore, in order to produce the full- XTAL1 P2.5 RD
CLK in
scale Vout of 2.56 V for the ADC804, We need to set Vref/2 = 1.28. WR
Signal Signal
P2.6 LM35 or
XTAL2 CLK R LM34
This makes Vout of the ADC804 correspond directly to the P1.0
Conditioning Conditioning
D0
temperature as monitored by the LM35. D1 Vin (+) 2.5k
and and
D2
D3 Vin (-)
D Q
Interfacing Interfacing
Temperature vs. Vout of the ADC804 D4 A GND
D5 10k
LM336
D6 Vref /2
LM35 Temp. (C) Vin (mV) Vout (D7 – D0) LM35 Q P1.7 D7
CS
Set to 1.28 V
(cont’) 0 0 0000 0000 (cont’) P2.7 INTR GND
1 10 0000 0001 Q
D
2 20 0000 0010
3 30 0000 0011 Q Notice that we use the LM336-2.5 zener diode to
fix the voltage across the 10K pot at 2.5 volts.
10 100 0000 1010
74LS74 The use of the LM336-2.5 should overcome any
30 300 0001 1110 fluctuations in the power supply
Department of Computer Science and Information Engineering Department of Computer Science and Information Engineering
HANEL National Cheng Kung University 27
HANEL National Cheng Kung University 28
7
ADC808 has 8 analog inputs
INTERFACING INTERFACING
TO ADC AND ¾ It allows us to monitor up to 8 different TO ADC AND
SENSORS transducers using only a single chip SENSORS
ADC808/809
Vref(+) EOC
ADC808 Analog Channel Selection
Vref(-) OE
Selected Analog Channel C B A SC ALE C B A
IN0 0 0 0
(LSB)
IN1 0 0 1
IN2 0 1 0
IN3 0 1 1
IN4 1 0 0
IN5 1 0 1
IN6 Science and Information
Department of Computer 1 1 Engineering
0 Department of Computer Science and Information Engineering
HANEL National Cheng KungIN7
University 1 1 1 29
HANEL National Cheng Kung University 30