DAC ADC Interfacing With 8051
DAC ADC Interfacing With 8051
Topic to cover
Interface 8051 with the following Input / Output Devices
Transducer/Sensors
Table 10.1
Temperature (C) Thermistor Resistance
(k)
0 29.490
25 10.000
50 3.893
75 1.700
100 0.817
Temperature sensors (LM34 and LM35)
LM34 series are precision integrated-circuit temperature sensors whose
output voltage is linearly proportional to Fahrenheit temperature.
LM35 series are precision integrated-circuit temperature sensors whose
output voltage is linearly proportional to Celsius temperature.
They require no external calibration since it is internally calibrated.
Their output voltage changes 10mV for each degree of temperature change.
Table 10.2
Item Temperature Range Accuracy Output
LM34 -50 F to +300 F +3.0 F 10 mV/F
LM34C -40 F to +230 F +3.0 F 10 mV/F
LM35 -55 C to +150 C +1.5 C 10 mV/C
LM35C -40 C to +110 C +1.5 C 10 mV/C
LM35D 0 C to +100 C +2.0 C 10 mV/C
Analog-to-digital converter (ADC )
Need to have some means to convert them into digital signal so
that computers can handle
Analog-to-digital converter (ADC) is a device which can convert
analogue voltage to digital numbers so that microcontrollers can
handle and process the data.
ADC are the most widely used devices for data acquisition
ADC has n-bit resolution, where n can be 8, 12, 16 or even 24 bits.
The higher-resolution ADC provides a smaller step size.
Step size is the smallest change that can be recognized by ADC.
Analog-to-digital converter (ADC )
An ADC has a resolution of 8 bits, the range is divided into 2^8=256 steps
(from 0 – 255). But there are 255 quantization levels.
Vcc
Step Size n
2 1
Vcc is the reference voltage of ADC with n-bit resolution
Table 10.3 : Resolution versus Step Size for ADC (if Vcc =
5V)
n-bit Number of steps Step Size (mV)
8 2^8 = 256 5/255 = 19.61
10 2^10 = 1024 5/1023 = 4.89
12 2^12 = 4096 5/4095 = 1.22
16 2^16 = 65536 5/65535 = 0.076
ADC0804 Chip (Free Running Mode)
+5V
20
10k 6 Vin(+) 18
POT D0 Port of
7 Vin() 17
8 A GND
D1 8-bit uC
D2 16
9 15
Vref/2
D3 To
14
19 D4 LEDs
CLK R 13
D5
10k 4 D6 12
CLK in 11
150 pF ADC08 D7
1 04
CS
2
RD
WR 3
10 5 Normally
D GND INTR
open
START
Figure 10.1
ADC0804 Chip (Free Running Mode)
Continuous Conversions
(Extracted from Page 11
Of Spec sheet of ADC0804)
CS 1 20 VCC
RD 2 19 CLKR
WR 3 18 D0
CLK 4 17 D1
INTR 5 16 D2
VI+ 6 15 D3
VI- 7 14 D4
AGND 8 13 D5
VREF/2 9 12 D6
DGND 10 11 D7
RD (data enable)
Active low input used to get converted data out of the ADC0804 chip.
When CS = 0, if a high-to-low pulse is applied to the RD pin, the 8-bit
digital output shows up at the D0-D7 data pins.
WR (start conversion)
Active low input used to inform the ADC0804 to start the conversion
process. If CS = 0 when WR makes a low-to-high transition, the
ADC0804 starts converting the analog input value of Vin to an 8-bit
digital number. When the data conversion is complete, the INTR pin is
forced low by the ADC0804.
ADC0804 Chip
CLK IN and CLK R
Connect to external capacitor and resistor for self-clocking, f = 1/(1.1RC).
The clock affect the conversion time and this time cannot be faster than
110s.
Vref/2
Input voltage pin used for the reference voltage. If this pin is open, the
analog input voltage for the the ADC is ranged from 0 to 5 volts.
Vin
Dout
Step size
WR
D0 – D7 Data out
INTR
Start conversion End conversion
RD
Figure 10.2
Read it
Note: CS is set to low for both RD and WR pulses
Testing the ADC0804
P2.5 RD VCC
P2.6 WR CLK R
CLK IN
P1.0 D0
: 10k
Vin(+)
: POT
Vin()
:
:
A GND
: Vref/2
P1.7 D7 D GND
P2.7 INTR CS
Example 10-1
Write a program to monitor the INTR pin and bring the digital input value into register A.
Then call a subroutine to display the input value on a 7-segment display. Do this
continuously.
V 5 5 Vin
Step Size n cc Step Size 8 0.019608 V Dout
2 1 2 1 255 Step size
IN0 0 0 0
IN1 0 0 1
IN2 0 1 0
IN3 0 1 1
IN4 1 0 0
IN5 1 0 1
IN6 1 1 0
IN7 1 1 1
ALGORITHM
Select an analog channel by provide bits to A, B, C.
NOTE : there is no self-clocking and clock must be provided from
an external source to the CLK pin. Hence Enable clock
Activate ALE (address latch enable) with a low-to-high pulse.
Activate SC (start conversion) with a high-to-low pulse The
conversion is begun on the falling edge of the start conversion
pulse.
Monitor EOC (end of conversion) Pin .After conversion this
pin goes high.
Activate OE (output enable) with a low-to-high pulse to read
data out of the ADC chip.
SELECTING A CHANNEL AND READ TIMING
PROGRAM
Digital-to-Analog (DAC) Conversion
The digital-to-analog converter (DAC) is a device widely used to convert
digital values to analog signals.
It does the reverse operation of an ADC
The resolution of DAC depends on the no. of binary bits input to it.
The common ones are 8, 10 and 12 bits.
An 8-input DAC provides 256 discrete voltages (or current) levels of output.
(The 12-bit DAC gives 4096 discrete levels).
D0
Analog output
Digital (Voltage or current)
inputs DAC
D7 Figure 10.5
DAC0808 Chip (MC1408)
+5V Vref (e.g +5V)
VCC Rref1
P2.5
P2.6 Vin(+) Iref = Vref/(Rref1+Rref2)
= 2mA (Typical)
Iref Rref 2
P1.0 D0 Vin() R0
DAC0808 Iout
8051 To Scope
Comp. + Vout = 0 to 10V
P1.7 D7 Vee
15V
GND
Figure 10.6
DAC0808 Chip (MC1408)
Operating Principle
• In the DAC0808, the digital inputs are converted to corresponding current (I out).
• Then by connecting a resistor to the Iout pin, the current will further convert to
voltage level.
• The total current provided by the output Iout pin is a function of the reference
current (Iref) and is follows:
D7 D6 D5 D 4 D3 D2 D1 D0
I out I ref
2 4 8 16 32 64 128 256
Converting Iout to voltage (Vout)
Connect the output pin Iout to a output standard resistor and hence convert
this current to a voltage.
Output voltage, Vout = Iout x Ro
Example
Assume that Ro = 5k, Rref1 = 1k , Rref2 = 1.5k and using a standard 5V
supply connected to Vref(+), calculate Vout for the following binary inputs.
(a) 1001 1001 (99H) (b) 1100 1000 (C8H)
Solution: 5
I ref 2mA
1000 1500
(a) 99H = 15310 153
I out ( 2mA) 1.195mA
256
Vout (1.195mA)(5000k) 5.975V
Solution:
ORG 0H
CLR A
AGAIN: MOV P1, A ; send data to DAC
INC A ; count from 0 to FFH
ACALL DELAY ; let DAC work and recover
SJMP AGAIN
END
Example
Use the circuit in Figure 10.6, write a program to generate a sine wave
of full-scale 10V output. If the output is connected to a CRO, draw the
display on the CRO screen.
Solution:
Assume 10V full-scale voltage for the DAC output.
Vout = [5 + (5 sin )] V
A table is drawn up to list the magnitude of the sine of angles between 0 and
360 degrees. The table values are integer numbers representing the voltage
magnitude for the sine .
Table 10.5 gives the angles, the sine values, the voltage magnitudes and the
integer values representing the voltage magnitude for each angle (with 30
interval).
Vout x 256/10
ORG 0H
AGAIN: MOV DPTR, #TABLE
MOV R2, #COUNT
BACK: CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
DJNZ R2, BACK
SJMP AGAIN
;
ORG 300
TABLE: DB 128, 192, 238, 255, 238, 192
DB 128, 64, 17, 0, 17, 64, 128
;
; To get a better looking sine wave, regenerate the look-up table for 2-degree angles
END
Display on the Generating Sine Wave on CRO
D7..D0 V / Volts
FFh
10
9 V = 5 + 5 * sin
8
7
6
80h 5
4
3
2
1 /Degrees
0
30 90 150 210 270 330
Review Questions
1. In the ADC0804, the INTR signal is an _____ (input, output)
2. In the ADC0804, to begin conversion, send a(n) ______ pulse to pin _____ .
3. Which pin of the ADC0804 indicates end-of-conversion?
4. In a ADC, input is ________ (digital, analog) and output is _______ (digital, analog).
5. Find the step size for an ADC0804 chip if Vref/2 =1.9V .
6. With Vref/2 =0.64V, find the Vin for the D7 –D0 = 1001 1001 output.
7. In a DAC, input is ________ (digital, analog) and output is _______ (digital, analog).
8. DAC0808 is a9n) ___-bit D-to-A converter.
9. The output of DAC0808 is in _________ (current, voltage).
10. Find the Iout for the digital input 1110 1110 to DAC0808. Assume Iref = 2mA.
11. To get a smaller step, we need a DAC with _____ (more, fewer) digital inputs.
12. The LM35 provides ____mV for each degree of _______ (Fahrenheit, Celsius).