0% found this document useful (0 votes)
55 views69 pages

Unit-10 Applications and Design of Microcontroller Based Systems_Technical

The document discusses the applications and design of microcontroller-based systems, focusing on interfacing matrix keyboards and ADCs with the 8051 microcontroller. It provides assembly language programs for scanning a keyboard and interfacing with ADC 0808/0809, detailing the operation and timing for data acquisition. Additionally, it includes review questions and pin diagrams for various ADC models, emphasizing their features and operational procedures.
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)
55 views69 pages

Unit-10 Applications and Design of Microcontroller Based Systems_Technical

The document discusses the applications and design of microcontroller-based systems, focusing on interfacing matrix keyboards and ADCs with the 8051 microcontroller. It provides assembly language programs for scanning a keyboard and interfacing with ADC 0808/0809, detailing the operation and timing for data acquisition. Additionally, it includes review questions and pin diagrams for various ADC models, emphasizing their features and operational procedures.
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/ 69

Microprocessors and Microcontrollers 13 • 26 Applications and Design of Microcontroller Based Systems

No step 4
Yes step 7
7. Find key code and display the key pressed on 7-segment display.
(By grounding one scan line at a time and checking return lines for any one line
to go to 'O' level. )
8. Go to step 1.
Program :
org lookup_table_address
db 30h, 31h, 32h, 33h, 34h, 36h, 36h, 37h,
38h, 39h,41h,42h,43h,44h,4 5h,46h
org program_start_address
beg: mov Pl #Of h; configure lower 4 lines of port 1 as i/p
mov dptr,#lookup_table_addr ess ; initialise dptr with
; lookup_table_addr.
aga: mov a, Pl
anl a, #Ofh
cjne a, #Ofh,aga ; check for key released
lcall delay ; call delay routine for key debounce
agal: mov a, Pl
anl a, #Ofh
cjne a,#Ofh, go ; check for key pressed
ljmp agal
go: lcall delay ; call delay routine for key debounce
mov a, Pl
anl a, #Ofh
cjne a,#Ofh, gol ; is key really pressed?
ljmp agal
gol: mov rl, # Olh ; initialise counter 1
mov rO, #Oefh ; store word for column selection
movr3, #04h ; initialise column counter
aga3: mov Pl, rO ; select only 1 column
mov a, Pl ; get the status of return lines
jnb acc.O,display ; check bit O and if it is O jump to display
inc dptr ; increment lookup_table pointer
jnb acc.1,display ; check bit 1 and if it is 1 jump to display
inc dptr ; increment lookup_table pointer
inb acc.2,display ; check bit 2 and if it is 2 jump to display
inc dptr ; increment lookup_table pointer
jnb acc.3,display ; check bit 3 and if it is 3 jump to display
inc dptr ; increment lookup_table pointer
mov a, rO ; get the word for column selection
®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessors and Microcontrollers 13 • 27 Applicatio ns and Design of Microcontroffer Based Systems

rl a ; select next column


mov IO, a ; store word for column selection
djnz r3, aga3 ; check for last column
ljmp beg ; if any key is not pressed scan again
end

Review Questions

1. What is keybounce ? How it is achieved ?


2. Explain the matrix keyboard interface of 8051.
3. What is key bouncing ? How it is eliminated ?
4. Interface a 4 x 4 matrix keyboard to 8051. Write the required block schematic and the assembly
level program.
5. Interface a 4x4 matrix keyboard to 8051. Write a subroutine to scan the keyboard and send the
ASCII code for a valid key closure on Port O.
6. Show a simple keyboard interface with a port of 8051 and explain its operation.
7. Interface a 2 x 4 keys keyboard to 8051 and write an ALP to send the keycode to port Pl,
whenever a key is depressed.
8. Draw and explain the interfacing of matrix keyboard with 8051.
GTU : Summer- 17,19, Marks 7
9. Onl.y draw 4 x 4 matrix keyboard connection diagram interfacing with 8051 microcontroller.
GTU : Winter- I 9, Marks 4

~Parallel and Serial ADC Interfacing


GTU: Winter-16 , 17,18,19 , Summer- 17

IFJJ■ Interfacing of ADC 0808/0809


The AOC 0808 and AOC 0809 are monolithic CMOS devices with an 8-channel
multiplexer. These devices are also designed to operate from common microprocessor/
microcontroller control buses, with tri-state output latches driving the data bus. The
main features of these devices are:
Features
• 8-bit successive approximation AOC.
• 8-channel multiplexer with address logic.
• Conversion time 100 µs.
• It eliminates the need for external zero and full-scale adjustments.
• Easy to interface to all microprocessors .
• It operates on single 5 V power supply.
• Output meet TTL voltage level specifications.
Pin Diagram
Fig. 13.5.l shows pin diagram of 0808/0809 ADC.
TECHNICAL PUBLICA T/ONS® - An up thrust for knowledge
Microprocessors and Microcontrollers 13 - 28 Applications and Design of Mlcrocontroller Based Systems

3
4
2}
:
Analog
inputs
Analog
5
inputs
6
7 ~} Mdress
soc
EOC ALE

D83 D87

OUTPUT CONTROL D86

CLK 085

Vee 084

REF+ 080

GND REF

D81 D82

Fig. 13.5.1 Pin diagram of ADC 0808/0809

Operation

ADC 0808/0809 has eight input channels, so to select desired input channel, it is
necessary to send 3-bit address on A, B and C inputs. The address of the desired
channel is sent to the multiplexer address inputs through port pins. After at least 50 ns,
this address must be latched. This can be achieved by sending ALE signal. After another
2.5 µs, the start of conversion (SOC) signal must be sent high and then low to start the
conversion process. To indicate end of conversion ADC 0808/0809 activates EOC signal.
The microprocessor system can read converted digital word through data bus by
enabling the output enable signal after EOC is activated. This is illustrated in Fig. 13.5.2.

A
B
C
~ Address
-- 50 nsl--
x
ALE /
l-25 µs.j
~ ()

soc ~
EOC "
))

/
>-
(
)

~:: -~- ---------------------------------------------------->< Valm ••ra


OE-------------_;/

Fig. 13.5.2 Timing waveforms for ADC 0808


®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Syste ms
M;croprocessors and Mlcrocontroflers 13 - 29 Appl/ cation s and Desig n of Micro contro l/er Base d

Interfacing
.
Fig. 13.5.3 show s typical interfacing circu
microcontroller system. it for ADC 0808 with micr opro cess or/

Analog
Inputs 1K

0.01 µF
7414
I
12V

2K

2K 6.8V
+ 10mF
1µF solid
Tantalum
10 K

Fig. 13.5.3 Typical Interface for 0808/0809

to prod uce a Vee and +VREF


The zene r diod e and LM 308 amplifier circuitry is used
voltage the AID converter will
of 5.12 V for the AID converter. With this reference
have 256 step s of 20 m V each.
;'.(.::';:,.:-.
❖;::,z·
"/;.-•
Exam ple 13.5.1
..... ✓;.- /.:-;;1.
! ,1, pt
,,,/IJ ;pt)#V
ft~~ ~, t,.
nel, 8-bit ADC to 8051.
Solution : The Fig. 13.5.4 show s the interfacing of 8 chan
ed inpu t channel, it is necessary
ADC 0808 has eigh t inpu t chan nels, so to select desir
addr ess of the desired channel is
to send 3-bit addr ess on ADC, ADB, ADA inpu ts. The
and Pl.O of 8051.
sent to the addr ess inpu ts thro ugh port pin Pl.2, Pl.1
® edge
TECHNICAL PUBLICATIONS • An up thrust for knowl
Microprocessors end Microcontrollers 13 - 30 Applications and Design of Mlcrocontro/ler Based Syste
ms

Oscillator
~~\ ~~ ~~ ~ - . ~ ' ,:_, 'v. ,. +5 V AOC 0808
' :-.; "' :-.: "=''

' >- OE EOC P2 .0


..
" CHO IN0
CH1 IN1 soc P1 .3
CH2 IN2 ALE P1.4
CH3 IN3 ADC P1 .2
ooo, µ_f! . CH4 IN4 ADB P1 .1
• ·~ «'.: " .· ;·~';\~j:~~~~%;;~~1~fffr . . .. ·••. '• ❖ ,,···
CH5
CH6
IN5
IN6
ADA P1.0

CH7 IN7
CLOC K

07
06
05
Vee 04 Port 0 of
+REF D3 8051

-REF D2
D1
GND DO

Reference for AID

Fig. 13.5.4
After at least 50 ns, this address must be latched. This
can be achieved by sending
ALE signal. After another 2.5 µs, the start of conversion
(SOC) signal mus t be sent high
and then low to start the conversion process. To
indicate end of conversion (EOC)
(AOC 0808/0809) activates EOC signal. The 8051 pins
P2.0 and Pl.3 are connected to
EOC and SOC pin of 0808/0809.
After conversion is over, 8-bit digital data is available on
Do thro ugh D 7 lines. The
8051 accepts this data through port 0.
Program
CLR P1 .3 ; Make SOC low
CLR P1.4 ; Make ALE low
MOV PO, #OFFH ; Configure port O as inpu t
MOV P2, #OFFH ; Configure port 2 as inpu t
BACK : MOV DPTR, #OCOOOH ; Initialize mem ory poin ter

TECHNICAL PUBLICATIONS® - An up thrust for knowl


edge
Microprocessors and Microcontroflers
13 - 31 Applications and Design of Mlcrocontro
l/er Bas ed System .
MO VA , #OOH
; Set add ress for cha nne l 0
ACALL R_ADC
; Call ADC Routine
MOVX @DPTR,A
; Set mem ory poi nter
MO VA ,#0 3H
; Set add ress for cha nne l 3
ACALL R ADC
; Call ADC Routine
MOVX @DPTR, A
; Sav e dig ital valu e
INC DPTR
; Inc rem ent mem ory poi nte r
MO VA ,#0 7H
; Set add res s for cha nne l 7
ACALL R_ADC
; Call ADC Routine
MOVX @DPTR, A
; Sav e dig ital val ue
ACALL DELAY
; Wa it for 1 sec
SJM PBA CK
; Rep eat
Analog to Digital Conversion Routine
R_ADC: MO VP 1,A
; Get the cha nne l num ber and set its
SET Pt. 4 add ress
; Sen d ALE
NOP ; Pul se
CLR P1. 4
SET P1.3 ; Sen d star t of
NOP ; Con ver sion
CLR Pt.3 ; Pul se
WA IT: JB P2.0, WAIT ; Wa it for EOC sign al
WAIT1: JNB P2.0,WAIT
MOV A,P 0 ; Get dig ital dat a
RET ;Re tur n
Delay Routine
DELAY : MOV TMOD, #01 ; Tim er 0, mo de 1 (16-bit mod e)
MO VR 0, #14 H ; Init iali ze cou nte r to 20
BACK: MOV TL0, #B0 H ; TL0 = B0H, the low Byt e
MOV THO, #3C H ; THO = 3CH, the hig h byt e
SETB TRO ; Sta rt the tim er 0
AGAIN : JNB TFO, AG AIN ; Che ck timerO flag unt il it rolls ove r
CLR TRO ; Sto p tim er 0
CLR TFO ; Cle ar tim er O flag
DJN Z RO, BACK ; Dec rem ent cou nte r and if not zero
rep eat
RET ; Ret urn

'!f!::r ~2~~~ift~~l~l ~~l~~:j s~'~ :~ tta


TECHNICAL PUBLICA T/ONS® - An up
thrust for knowledge
Microprocessors and Microcontrof/ers 13 - 32 Appl/cations and Design of Microcontroller Based Systems

IF&*I Interfacing of ADC 0803/0804/0805 with 8051


The ADC 0803, ADC 0804 and ADC 0805 are CMOS 8-bit successive-approximation
analog to digital converters. These devices are design to operate from common
microprocessor control buses, with tri-state output latches driving the data bus, and are
identical except for accuracy.
Pin Diagram

Fig. 13.5.5 shows the pin


diagram of ADC 0803, ADC 0804 cs
and ADC 0805. IN+ and IN- RD

inputs allow application of WR


CLKIN
differential input voltage which DB2
has high common mode rejection
iNTR
IN+ DB3 DATA
and eliminates offset due to the DB4 OUTPUTS
IN-
zero input analog voltage value. DBS
The devices can operate with an D86
external clock signal or, the on D87
chip clock generator can be used
independently by adding an Fig. 13.5.5 Pin diagram of ADC 0803/0804/0805
external resistor and capacitor to
set the time period.
Features
• 8-bit successive approximation AOC
• Conversion time 100 µs
• Access time 135 ns.
• It has an on-chip clock generator.
• It does not require any zero adjustment.
• It operates on single 5 V power supply.
• Output meet TTL voltage level specifications.
Operation

When the WR input goes low, the internal successive approximation register (SAR) ~s
reset. As long as both CS and WR remain low, the analog to digital converter ~ill
remain in its reset state. One to eight clock periods after CS or WR makes a low-to-high
transition, conversion starts. The INTR signal is held high during conversion proc~ss.
After conversion, INTR goes low which is used as end of conversion signal. By makillg
CS and RD signals low, an output can be read through DBo to DB7 data signals.

®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessor and Microcontrollers 13 - 33 Applications and Design of Mlcrocontroller Based Syste ms

Analog Inputs

As mentioned earlier, there are two analog inputs to ADC


0803 /0804 /0805 : IN+ and
IN-. These inputs are connected to an internal operational ampl
ifier and are differential
inputs. The differential input rejects the common mode noise
and eliminates offset at
zero analog input voltage.
The Fig. 13.5.6 shows a few ways to use these differential input
s. The Fig 13.5.6 (a)
shows the one way to use single input that can vary between
0 V and +5 V. Using
another way variable voltage can be applied to the Vin (-) pin
so that the zero reference
for Vin (+) can be adjusted, as shown in Fig. 13.5.6 (b).
v,n(+)
Analog input Vin(+)
Analog Input

V in(-)
V 1n(- l

- +5V
(a)
(b)
-
Fig. 13.5.6 Ways to use differential inputs
Clock Sign al
ADC 0804
The ADC 0803/0804/0805 requires a clock
source ranging 100 kHz to 1460 kHz for CLKR
operation. The clock signal can be applied
external or it can be generated with an RC
circuit, as shown in the Fig. 13.5.7. When the
RC circuit, show n in Fig. 13.5.7 is used to
generate the clock, the clock frequency is
given as,
F - 1 Fig. 13.5.7 Clock circuit
clock - 1.1 RC

!to~ i~t~~r~ - -;, :: ,:


11
The Fig. 13.5.8 show s the interfacing of ADC 0803/0804/0805
~ ~ cy sho~ , ,l:~,- ,
with 8051 using port 1
and port 2. Here, port 1 is used to read digital data from ADC
and port 2 is used to
provide control signals to ADC 0803/0804/0805. Potentiome
ter is used to adjust Vin+
voltage. The clock signal is prov ided using internal clock
generator and two external
components, resistor and capacitor as show n in the Fig. 13.5.8
. The frequency of such
dock can be deter mine d by,
1
f =
1.1 RC
TECHNICAL PUBLICA T/ONS® - An up thrust for knowledge
Microprocessor and Microcontrollers 13 - 34 Applications and Design of Mlcrocontroller Based Systems

+SV

POT

150 pF

ADC 0803/0804/0805

Fig. 13.5.8
we get
The typical values are R =10 kQ and C =150 pF. With these values
is aroun d
appro ximat ely 606 kHz clock frequency. In such case, the conversion time
110 µs.
Following are the steps followed for data formation by the ADC0804 chip.
Step 1 : Make low to high pulse to pin WR to start the conversion.
is finished
Step 2 : Keep monitoring the INTR pin. If INTR is low, the conversion
and we can go to next step. If INTR is high, keep polling until it goes low.
Step 3 : After the INTR has become low. Make a high to low pulse to
the RD pin to
get the data out the ADC0804 IC chip.
AD Conversion Program
MOV Pl, #OFFH ; configure Portl as input
BACK: CLR P2.6 ; (Make WR = 0 and
SETB P2.6 ; Make WR = 1 to genera te start of
; conver sion pulse]
AGAIN : JB P2.7, AGAIN ; Wait for end of conve rsion
CLR P2.5 ; Enabl e read
MOV A,Pl ; Read data throug h port 1
SETB P2.5 ; Disabl e read after readin g data
SJMP BACK ; go for next conve rsion cycle

®
TECHNICAL PUBLICA T/ONS - An up thrust for knowledge
Microprocessor snd Mlcrocontrollers 13 • 35 Appl/cations and Design of Mlorocontroller Base

cs--- ,
d Systems

Data out

iNrn - - - - - - - - - - - -
Start conversion
1
RD _ _ _ _ _ _ _ _ _ _ _ _ _conv
End _ersio
__ n _;

Fig. 13.5.8 (a)


..,, ,.••,•,. •'.','•' .•-:':'.',,:' •:.~••~::.•.. •:l•;::·, •'•\ ;:, N:,;,\ :(;, ,;.;,,,;~-:-.,:❖,;•:❖-:• •
Exam ple 13.5.2
. .n?~~ .
'1( ·..•.· .•..·..·... ::
Solution :
#include <reg 51.h >
_.t.~~Jl:~J
~
·~
. :.·•.~~.i«.ji;;> .
-. . ·.·ff.·.
-:·:::::=:·.,,:_ :·.
1
::►:;: ~~::~~~ GTU : Win ter- I 6, Mark s 7

1bit RD= P2" '5;


1bit WR = P2" '6;
1bit INTR = P2 A 7;
sfr PDATA = P1;
void main(vold)
{
uml gne d cha r value;
PDA TA = OxFF; /* mak e P1 an inpu t • /
INTR = 1; /* make INTR an inpu t • /
RD = 1; /* set RD high • /
WR = 1; /* set WR high */
while(1)
{
WR = 0; /* send WR puls e • /
WR = 1; /* L-to-H (sta rt conversion) • /
whlle(INTR= =1); /* wai t for EOC • /
RD = O; /* send RD puls e • /
valu e = PDATA; /* read value */
convertAndDisplay(value); /* Refer sect ion 10.6
•/

TECHNICAL PUBLICA TIONS® - An up thrus


t for knowledge
Microcontrol/ers 13 - 36 App/lcst/ons end Design of Mlcrocontroller Based Systems

::: 1;

EOC, HERE ; wait until done

JNB EOC, HEREl ; wait until done


SETB OE ; enable RD
ACALL DELAY ; wait
MOV A,PDATA ; read data
CLR OE ; clear RD for next time
ACALL CONVERSION ; hex to ASCII (Refer section 10.6)
ACALL DATA DISPLAY ; display the data (Refer section 10.6)
SJMP BACK

Solution:
#include <reg51.b>
8bit ALE = Pl "'4;
8bit SC = Pl "'3;
8bit EOC = P2"' 0;
8bit ADDR_A = P1 "'O;
8bit ADDR_B = P1"' 1;
8bit ADDR_C = P1 "'2;
mPDATA = PO;
void main()
{
unsigned char value;
PDATA = OxFF; /* make PO an input * /
EOC = 1; /* make EOC an input * /
ALE= O; /* clear ALE * /
SC= O; /* clear SC */
wblle(1)
{
ADDR_C = O; /* C = 0 */
ADDR_B = O; /* B = 0 */
ADDR_A = O; I* A = 1(select channel O) */
Delay(1); /* delay for fast DS89C4x0 * /
ALE= 1; /* Latch the address */
Delay(1);
SC= 1;

TECHNICAL PUBLICA TIONs® • An up thrust for knowledge


Microprocessor and Microcontro/lers 13 - 37 Appl/cations and Design of Microcontrolla r Based Systems

Delay (l);
ALE = 0 ;
SC = 0; /* start conve rsion */
whlla (EOC ==l); /* wait for data conve rsion */
whlla (EOC = =O);
Delay (l);
value = PDATA; /* get the data* /
Conve rtAnd Displa y(valu e); /* Refer sectio n 10.6 */
}
}
Practical Applications

The National LM35 is a temperature sensor. It


+V (4 - 30 V)
is a temperature-sensitive voltage source. Its
outpu t voltage increases by 10 mV for each °C
increase in its temperature . The Fig. 13.5.9 shows
the circuit connection for temperature sensor
LM35. The voltage outpu t from this circuit is
connected to a negative reference voltage, Vs as
show n, the sensor will give a meaningful outpu t
R2- --V
-s-
for a temp eratu re range of - 55 'C to 150 °C. The 50 µA
outpu t is adjus ted to O V for O C. The outpu t
0
-Vs
voltage can be amplified to give the voltage Fig. 13.5.9 Temp
erature dependent
range you need for a particular application. The voltage source using LM35
outpu t voltage from LM35 can be applied to
ADC and we can get digital equivalent of analog voltage corre
sponding to curre nt
temp eratu re.
The AD590 is anoth er commonly used temperature sensor. It is temp
erature sensitive
curre nt source. It produ ces a curre nt of 1 µA/°K . This curre nt
can be converted to
volta ge sourc e by curre nt to voltage converter. The advantage of curre
nt source sensor is
that volta ge drop in long connecting wires do not have any effect
on the outpu t value.
The outpu t of amplifier show n in Fig. 13.5.10 can be appli ed to
ADC to get the digital
equiv alent of curre nt temp eratu re.

AD590 Vout

fig. 13.5.10 Temperature sensor using AD590

TECHNICAL PUBLICATIONS® • An up thrust for knowledge


d systems
. Microcontro l/er B ase
13 _ 38 Applications and Design of
Microproces sor and Microcontrollers

IFJ-fj Interfacing of ADC 0844/0848 . a proximatt on


. A/D

The ADC0844 and AOC0848 are CMOS 8-bit succesSIVe p 8-channe l


. . Th 4-channe1 or
converters with versatile analog input multiplexers. . e d d differential or
d for single-en e t, from the contro1
multiplexers can be software configure d . ed to opera e
.
pseudo-differential modes of operation. These are esign
bus of a wide variety of microprocessors.
CS(23) RD(1_)_ _... WR(22)

AGND(10) VCC(24) DGND(12) VREF(11)

t t t - ---,'c~t:;;_:i----e INTR(21)
. ·: ~:,~·-:~--

· 8 ~bit Tri- state {0B0(20)- DB(13)


. s.A.R. t===~> I output L....----'"- MA0(20)- MA4(16)
CH1(2) • CHB(9) \ ------1,-·,;••~-"'"" 1-----'
Aio latches

Fig. 13.5.11 Block diagram of ADC0848

The Fig. 13.5.11 shows the block diagram of AOC 0848. The AOC0844 and AOC0848
contain a 4-channel and 8-channel analog input multiplexer (MUX) respectively. Each
MUX can be configured into one of three modes of operation differential, pseudo
differential, and single ended. The specific mode is selected by loading the MUX address
latch with the proper address (Refer Table 13.5.1). Inputs to the MUX address latch
(MA0-MA4) are common with data bus lines (DB0-DB4) and are enabled when the RD
line is high. A conversion is initiated via the CS and WR lines. If the data from a
previous conversion is not read, the INTR line will be low. The falling edge of WR will
reset the INTR line high and ready the AID for a conversion cycle. The rising edge of
~ with RD high, strobes the data on the MA0/DB0-MA4/DB4 inputs into the MUX
address latch to select a new input configuration and start a conversion. If the RD line is
held low during the entire low period of WR the previous MUX configura tion is
retained, and the data of the previous conversion is the output on lines DBO-DB7. After
the conversion cycle (tc ~ 40µs), which is set by the internal clock frequency , the digital
data is transferred to the output latch and the INTR is asserted low. Taking CS and RD
low resets INTR output high and outputs the conversion result on the data 1.
(DB0-DB7). This is illustrated in the timing diagram shown in the Fig. 13.s.13 _ mes

The Fig. 13.5.12 shows the pin diagrams for ADC0844 and ADC0848.
®
TECHNICAL PUBL/CA TIONS - An up thrust for knowledge
Microprocessor and Microcontrol/ers 13 - 39 Applications and Design of Microcontroller Based Systems

The Table 13.5.1 (a) and 13.5.1 (b) show the ADC0844 and ADC0848 multiple xer
addressi ng.
RD 1 20 24
Vee RD 1 Vee
cs 2 19 WR CH1 2 23 cs
CH1 3 18 INTR CH2 3 ·- 22: WR
CH2 -11 . D80 / MAO CH3 c' 4 .•, .. - 21 iNTR
CH3 ,. ;16 D81 / MA1 tl.19
CH4 5·•·"· DB0 t MAO
CH4 D82 / MA2 CH5 D61 / MA1
AGND D83 / MA3 CH6 OB2 / MA2
VREF D84 CH7 D63/ MA3
(MSB) 087 D65 CHS OB4 / MA4
DGND OB6 AGND D65
(a) VREF OB6

DGND D87

(b)

MUX
mode

Pseudo
differential

t're'VlOllS channel configuration


X = don 1t care
Table 13.5.1 (a) ADC0844 MUX addressing

TECHNICAL PUBLICA T/ONS® - An up thrust for knowledge


Microproce ssor and Microcontro flers 13 - 40 Applications and Design of Microcontro fler Based Systems
;,,,,u.,;-;;#',/N# , ,_,._,,_,,, ,_,,,,.,. ]
~-~

h•:;n~,-
;_N
.... _._..,........

~::: "''"':·~·::..·-- ~··_:_--:·""~:----•w•---


'

I MUX ~
. ~ · -~ ~ CS ::§,~~~
...~ . '+~~'•\~-..~~"'~
.! !~·: RO ~..;.,i..,,.,.
. ·
. ,~,.;:-;
~ •
·.·• ··,.,....,....,,, -,,;;w·/4,, ✓.;,:..,.;, ,.NP;•h/,)e-W.Y/, ✓;,,
MUX tn<lde
-,,;~ •-. _,__~ •

MA4 . , ;ta2
"" ,. ~
Mt.'; ~ ~ <\~L
%,,.,,
cwt· CH2 CH3 CH♦. .•.~-~ '-' ~~t~~ . . ~~•-,~~~~,,., , ,. . .. . ,
:- ~-·~ ~ "i~ T ~ :_~f._.ii__~_,.-~ ...
__
:.~_:_:_;_;_·:_r: ,~I...... ,. ·• .· . . . . .. Differential I'

,., 'L~ .., .


X: t .. ·•. L >:.<:./;;..

t
'

~ '.

.L

'
:,,i·: x•t_.:. '
-~ j !,
t~ · ·. t.. tvt~:; ¥~:s It

If,~
t ... ·•

i .:irritti:it
E;:·•
l.
. --::~•:;::• ·,::~~--<~:,••:- .: ·

H ;3"11 .. ·""
~=~ _:, .

t~
If
H
: H ::
,. ,,.,,,,A#,:,.-ft,;¥-.':;Y~ ·""

<~~~l "::;,,•,~
1/. (";, ~~
X X . • V

!...-N~,,._,.._._,,..,,,,, ,_,~/;N,_,,w,,.,,.,,.,,,,MN,,.,;,,.,,,,,,i<,,,h-'Nk,

Table 13.5.1 (b) ADC0848 MUX addressing

TECHNICAL PUBLICA TIONs® • An up thrust for knowledge


Microprocessor and Microcontrollers 13 - 41 Applications and Design of Microcontr ol/er Base d
Syste ms

--- 1l --

l
\ I
l
\ I
rnffl
I

DBO - 0B7 -
MA0 -MA4
- - -
Tri - state
- - - -< .
DB0 - OB7 )
.
-
Fig. 13.5.13 Timing diagram for selecting the chan
nel and reading data from ADC0848
Steps to select the channel and read data from
ADC 0804
1. When CS = 0 and RD = 1 prov ide addr ess of chan
nel to be selected and appl y a
low-to-high WR puls e to latch the address.
2. Now whe n RD = 1 and WR = 1, check for INTR
signal to go low; low INTR
indicates end of conversion (EOC).
3. With INTR low, mak e CS= 0, WR = 1 and appl y
low goin g puls e on RD to get
data out on the data pins of AOC0848.
The Fig. 13.5.14 show s the interfacing of AOC0848 with
8051.
+5V
8051 ADC0848

!li::i;:::fi!•·•'.~:!;!li.:i i;.------- +5V


. •.
' "': 1---- 02.5 6V

'
;t i....
. /.•.•--:~ •,;::-· .
-----M

. ,· •.•· .- ..·,·
/i/i/. : PO.~ . 1 4 - ~ M . .b~ l:MA3' •· •· ·:· :cH4\t
?0~4,.(...
: _ _. MA4.. · 8fl ... PH!?
:: ~o~p·:,. .- -.. . : o.:v QHl.i ~
PO,:e O~·

__ __e_2_
.i_:;
;1----;/1NrR
:; ~,. . c1;1 ,
CHS .·
. AGNO
PG.NO.·

Fig. 13.5.14 Interfacing of ADC 0848 with 8051

TECHNICAL PUBLICA TION s® - An up thrust for


knowledge
Microprocessor and Mlcrocontrol/ers 13 - 42 Appl/cations and Design of Mlcrocontroller Based Systems
1
Exampl e 13.5.4 M:ritc tittl()51 A.LP tb seltct the chllntiel 2 anl rt4d~ ·'iiata.·:-~, -~ ,..,.~~!£-.: . ,:
'.{/--~~
.-.~~ii-¾, t4-::%i-,U·
.x, ~;.x.> :--· · -- .,. -, i1·

Solutio n :
CS BIT P2.4
RD BIT P2.5
WRBIT P2.6
INTR BIT P2.7
ORG OH
SETB INTR ; make INTR an input
SETB cs ; set Chip Select high
SETB RD ; set Read high
SETB WR ; set Write high
BACK :
MOV P0,#09H ; Channe l 2 address
NOP ; wait
CLR cs ; Chip Select (CS=O)
CLR WR ; write= LOW
NOP ; wait to make pulse width wide enough
NOP
SWTB WR ; latch the address and apply start convers ion
SETB cs ; de-sele ct the chip
MOV P0,#0F FH ; make PO an input
HERE:
JB INTR,HERE ; wait for EOC
CLR cs ; Chip Select (CS=0)
CLR RD ; read RD=0
NOP ; wait to make pulse width wide enough
NOP
SETB RD ; bring out digital data
MOV A,P0 ; get the digital data
SETB cs ; de-sele ct for next round
ACALL CONVERT ; convert to ASCII
ACALL DATA_DISPLAY ; display the data
SJMP BACK

Exampl e 13.5.5

Solutio n :
#includ e <reg61 .h>
■bit cs = P2 A 4;
■bit WR = P2 A 5;
■bit RD= P2 A 6;
■bit INTR = P2 ,.._ 7;

void main(vold)
TECHNICAL PUBL/CA TIONS® - An up thrust for knowledge
Microprocessor and Microcontrol/ers 13 - 43 Applications and Design of Mlcrocontroller Based Systems

{
umlgned char value;
INTR = 1; /* make INTR an input*/
cs = 1;
WR= 1;
RD= 1;
whlle(l)
{
PO= Ox09; /* Channel 2 addr */
CS= O; /* chip select */
WR=O; /* write = LOW */
Delay(); /* make pulse wide enough * /
WR= 1; /* L-to-H to latch addr */
cs= 1; /* de-select */
PO= OxFF; /* make PO an input */
while(INTR= =1); /* wait for EOC */
CS= O; /* chip select */
RD= O; /* make read low * /
Delay();
RD= 1; /* read the data */
value= PO; I* get the data */
cs= 1;
ConvertAndDisplay(value ); /* Refer section 10.6 */
}
}

11111 Interfacing Serial ADC 1031


The ADC 1031 is a serial ADC chip from
National Semiconductor. It is a 10-bit successive SeLK Vee
approximation AID converter with serial IIO.
The Fig. 13.5.15 shows the pin diagram of ADC cs CeLK
1031 and the Table 13.5.15 gives pin description.
Do
SCLK : Serial Data Clock : This input controls
the rate at which the serial data exchange
GND VREF+
occurs. The falling edge shifts the data resulting
from the previous AID conversion out on D0 .
Fig. 13.5.15
CS : Chip select : This is active-low chip select
pin.
v,N : Analog input : The analog input is applied to this pin.

TECHNICAL PUBL/CA TIONs® - An up thrust for knowledge


M;croprocessor snd Microcontrollers 13 - 44 Appflcstlons snd Design of Mlcrocontroller BBBed Systems

VREF + : Reference voltage : This is a positive analog voltage reference ranges from
+ 2.5 to + 5.0 V.
Do : Data Output : The result of A/D conversion (D0 D9) is output on this pin. The
-
most significant bit D9 is shifted-out first through data output pin D 0 ,
CCLK : Clock Input : This dock input controls the successive approximation conversion
time interval, i.e. (A/D conversion rate). The dock frequency applied to this pin can be
between 700 kHz to 4 MHz.
The Fig. 13.5.16 shows the interfacing of ADC 1031 to 8051. As shown in the
Fig. 13.5.16, signals ScLK and CS are control by P2.0 and P2.l port output pins and serial
data from D0 output is accepted on Pin 3.0 of 8051.

+SV

ScLK

cs
i 'VI - - - Analog input

3 MHz GcLK
clock

Fig. 13.5.16 Interfacing serial ADC1031

1••• 1.,,_ilillii .~::t'~]lllm


Example 13.5.6

Solution:
ORG OOOOH
CLR P2.1 Make CS = 0 to select ADC 1031
SETB P3.0 Configure P3.0 as an input
MOV R2, #2 Set counter to read MSB and MSB-1
CLR A Clear A
BACK!: SETB P2.0 Send falling edge on pin ScLK
CLR P2.0
MOV A, P3.0 Read data bit and save it as LSB of A
RLC A Shift left the received bit/s
DJNZ R2, BACKl Check if R2 = 0, if not go to BACK1
to read bit MSB-1
MOVRl, A Store the data in Rt
MOVR2, #8 Set counter to read lower byte
CLR A Clear A
®
TECHNICAL PUBL/CA TIONS - An up thrust for knowledge
Microprocessor and Microcontrollers 13 - 45 Appl/cations and Design of Microcontroller Based Systems

BACK2: SET P2.0 Send falling edge on pin ScLK


CLR P2.0
MOV A, P3.0 Read data bit
RLC A Shift left the received bit/s
DJNZ R2, BACK2 Check if R2 = 0, if not goto BACK2
MOVR0, A Store lower-byte of Data in RO_
SETB P2.1 Disable ADC 1031 by making CS= 1
END
C program
#include <reg61.b>
11bit data P3.0
11bit Selle P2.0
11bit CS P2.l
umigned char count, data1, data2;
void main ()
{
cs = 0; /* Make CS = 0 to select ADC */
data = 1 ; /* Configure P3.0 as an input */

for (Count = 0 ; Count < 10 ; count + +)


{
Selle= 1 ; /* Send falling edge * /
Selle= 0
if (count < 2)
{
data2 = data;
data2 = data2 < < 1;
}
else
{
data1 = data ;
data1 = data1 < < 1;
}
}
cs= 1; /* Disable ADC */
}

Review Question s

1. Explain the functions of various pins of ADC 0804.


2. Draw and explain the interfacing of ADC 0804 to 8051.
3. Draw and explain the interfacing of ADC 0848 to 8051.
4. Write an 8051 C program to read the data from ADC 0848.
5. Draw and explain the interfacing of any serial ADC with 8051.
6. Draw the control byte format of ADC MAX 1112.

--
7. Explain interfacing of ADC 1031 to 8051 microcontroller.

TECHNICAL PUBLICATIONS® - An up thrust for knowledge


ntroller Bas ed Systems
l/ers 13 - 46 Applications and Design of Microco
Mic ropr oce sso r and Microcontro
··••· ·•·••··" ·· .. . ••·•·· ········" ...... ... .
ALP to convert the analog input to digital.
8· Inte,face an ADC to 805 1 and write an l.
n of ADC804 interfacing with ALP to 805
9. Wit1t block diag ram explain tlte operatio le interfacing such
. What are the signals of importance whi
10. Explain the salient features of an ADC
an AD C to a 8051 contmller ? to
interfacing an 8-bit AD C to a 8051 controller. Write the software required
11 . Sho w a scheme of
. Discuss practical application .
obtain the output from such an interface
using timing diagram for ADC.
12. Discuss interfacing of ADC0804 with 8051 lay the converted
a program to read analog data and disp
13. Interface ADC 0804 to 8051 and write
data at port 2. GTU : Win ter- 16, Mar ks 4
sche me to interface ADC 080 4 with 8051.
14. Draw an interfacing
GTU : Sum mer -17 , Mar ks 7
rfacing of 8051 with AD C 0808.
15. Draw and explain inte
ller. Write the steps in
rface ADC 0808 with 8051 microcontro
16. Draw the interfacing diagram to inte GTU : Win ter- 17, Mar ks 4
brief for analog to digital conversi on.
e an 8 bit ADC to 8051 microcontroller.
17. Give a complete scheme to interfac GTU : Win ter- I 8 , Mar ks 7

.
AID converter with 8051 microcontroller"
18. Write short note on "interfacing of GT U : Win ter- 19, Mar ks 3

1111 Interface of DAC 0808


8-b it R/2 R lad der typ e D/ A con verter compatible wit h TIL and
The DAC 0808 is an
duc t of an
log ic. It is des ign ed to use wh ere the out put cur ren t is linear pro
CMOS
eight-bit dig ital word.
The DAC 0808
. 13.6.1 sho ws the pin dia gra m and block dia gra m for DAC 0808.
Fig rent
ren ce cur ren t am plif ier, an R/2 R lad der and eig ht hig h spe ed cur
consists of a refe
Output Com pen sati on
range control

GN D -Vref

VEE +Vref

Cur rent outp ut Vee

(MSB) A1 A8 (LSB)

A2 A7

A3 Ae,
A4 8 9 As

Fig. 13,6, 1 (a} Pin diagram

An th
TECHNICAL PUBLICA TIO Ns® - up rust for knowledge
Microprocessor and Microcontrollers 13- 47 Applications and Design of Microcontroller Based Systems

switches. It has eight input data lines A1 (MSB) through As (LSB) which control
the
positions of current switches.

MSB
LSB
A1 A2 A3 A4 As As A7 Aa

5 6 7 8 9 10 11 12

1
Range
control

:i::'./;~i/ ~~'.\ .. :~~~w;;;-•.;~~;/~::=~·


·;'' R12Ff1idder Basic circuit
2 GND

(+) vret i:;: ==: :::: =--- -r-- ---- -L- --


14 13 Vee
Referenc e
15 current
amplifier
(-) vref .
16

---- ---- -lf- :--- ---- ---- ---- ~ Compensation


3

VEE
'--y- -"
NPN Current source pair

Fig. 13.6.1 (b) Block diagram


It requires 2 mA reference curren t for full scale input and two power supplies
Vee=+ 5 V and VEE = - 15 V (VEE can range from - 5 V to - 15 V).
The voltage Vref and resisto r R determines the total reference current source and
14
RIS is generally equal to R to match the input impedance of the reference current
14
amplifier.
Fig. 13.6.2 shows a typical circuit for DAC 0808.
The output curren t 10 can be given as
Vref ( A1 + A2 + A3 + A4 + As + A6 + A7 + As )
I0 = R14 T 4 8 16 32 64 128 256

__ __ __ __--- -;; --~ ~- -= =- ---


TECHNICAL PUBLICATIONS® - An up thrust for knowledge
I
Microprocesso r and Microcontro/lers 13 - 48 Applications and Design of Microcontrol/er Based Systems

Vee

2.5 K +5V
vref

2.5 K
8-bit
digit
input

R1s
2.5 K
15 pF

Vee
-15 V
Fig. 13.6.2 Typical circuit for DC 0808

•,&1!1~~~~~can~:~i,~;Oor J. Therefore, for ~iCal ~ f full .s<ale ·

. I~. ~ {~~(½+ !JF1~+;2 +~ +1~8 +~)


:;1 ~Jili~5:1ss =J~r ,~
It shows that the full scale output current is always 1 LSB less than the reference
current source of 2 mA. This output current is converted into voltage by I to V
converter. The output voltage for full scale input can be given as,
V O = 1.992 x 2.5 K = 4.98 V

11
!!t\%1t~Et~s:;~0~t; R0Cf;t:'i::.•:
current and at (111 ..·. . ... h binary
•·. .•. . ·- ---- ·
•· ...put 1t
.m -.
sm
. -: .. :.,: ;:.-·,,
t 9.92:
-·-:: :· . ·-
IDA.·· ··
;_ •. · .

The circuit shown in the Fig. 13.6.2 gives output in the unipolar range. When digital
input is OOH, the output voltage is O V and when digital input is FFH (1111 11 llh, the
output voltage is + 5 V. This circuit can be modified to give bipolar output.

®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessor and Mlcrocontrollers 13 - 49 Applications and Design of Microcontroller Based Systems

Fig. 13.6.3 shows th e circuit for giving output in the bipolar range. Here, resistor RB
(5 K) is connected between Vref and the output terminal of DAC 0808. This gives a
constant current source of 1 mA.

Vee
+5 V

5 13
R14 +SV
2.5 K vref

8-bit Ia l 5K -If ~
digital 1 mA
RB
5K
input

-10 A

15 pF 2.5 K

VEE

Fig. 13.6.3 Interfacing DAC In the bipolar range


The circuit operation can be observed for three conditions :
Condition 1 : For binary input (OOH)
When binary input is OOH, the output current I0 at pin 4 is zero. Due to this current
flowing through Ra (1 mA) flows through ~ giving VO = - 5 V.
Condition 2 : For binary input 8OH

When binary input is 8OH, the output current I0 at pin 4 is 1 mA. By applying KCL
at node A we get,
- Is +I 0 +If = 0

Substituting values of Ia and I0 we get,


-(1 mA) + (1 mA) + If = 0
If = 0
and therefore the output voltage is zero.

NS® - An up thrust for knowledge


TECHNICAL PUBLICA TIO
r Based Systems
Applications and Design of Microconfrolle
Microprocessor and Microcontrollers 13 - 50

Condition 3 : For binary Input FFH


g KCL
cur ren t I O at pin 4 is 2 mA . By applyin
Wh en bin ary inp ut is FFH, the out put
at nod e A we get,
- I 8 + 10 + 1r = 0

sub stit utin g values of I8 and I0 we get,


- (1 mA) + (2 mA) + If = 0
If = - 1 mA
13.6.3
In this way , circuit sho wn in the Fig.
Therefore, the out put voltage is + 5 V.
giv es out put in the bip olar range.
ics for IC 1408
IFll ■ Important Electrical Characterist
• Reference cur ren t :2m A

• Sup ply voltage : + 5 V V cc and - 15 V VEE

• Setting time : 300 ns

• Full scale out put cur ren t : 1.992 mA


• Accuracy : 0.19 %
d
C 0808 wit h 8051 microcontroller base
Fig. 13.6.4 sho ws the interfacing of DA
system.
be gen era ted usi ng this circuit.
We now see how different waveforms can

Square Wave

e squ are wav e firs t we hav e to out put FF and the n 00 on por t 1 of 8051.
To gen erat frequency
ut to the DA C 0808. Acc ord ing to
The por t 1 is connected as an inp
the two out put s.
req uire men t del ay is pro vid ed bet wee n
Program :
MO V SP, #08 H ; Initialize Sta ck Poi nter
; Loa d all 1 s in Por t 1
1

REPEAT: MO V PI, #OF FH


LCALL DELAY ; Call dela y rou tine
; Loa d all 0 s in Por t 1
1
MO VP, #OOH
LCALL DELAY ; Call dela y rou tine
LJMP REPEAT ; Rep eat
DELAY: MO V RO, #OF FH ; Loa d dela y cou nt
BACK: DJN Z RO, BACK ; Dec rem ent and che ck whe the r del ay
on
; cou nt is zero if not rep eat the ope rati
RET ; Ret urn to mai n pro gra m

thrust for knowledge


TECHNICAL PUBLICA TIONs® - An up
Microprocessor and Microcontrollers 13- 51 Applications and Design of Microcontroller Based Systems

4 MHZ
HO
Vcc
20
RST
Poo Ao -A15
R 8051 Po7
ALE Do- D7
PSEN
RD
PSEN
RD
P1o17 WR -WR

OE D,-Dy AsgA WR OE D,-Dg Av2A


2764 (EPROM) 6264 (RAM)
CS

moomo
lHA

Y -A45
Vcc R
GND G
+5 V
2.5 K
14
2.5 K
2.5 K
DAC
0808

15
16 3 1 2
$2.5 KI

Fig. 13.6.4
Triangular Wave
To generate triangular wave we have to output data from 00 initially, and it should
be incremented upto FF. When it reaches FF it should be decremented upto 00.

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13-52 Applicatiorns and Design of Microcontroller Based Systems

Program:
MOV SP, #08H ;Initialize Stack Pointer
MOV RO, #00H
REPEAT: MOV P1, RO ;Send digital data to the input
; of DAC 0808
INC RO ;Increment digital data
CJNE RO #0FFHREPEAT :Check digital data for peak output if not repeat
REPEAT1: MOV P1, RO ;Send digital data to the input of DAC 0808
DJNZ RO, REPEAT1 ;Decrement digital data and
;check digital data for least
;output if not repeat.
LJMP REPEAT
Sine Wave

To generate sine wave we have to output digital equivalent values which will
represent sine wave as shown in the Fig. 13.6.5. Digital data 00H represents - 2.5 V. 7FH
represents 0 V and FFH represents + 2.5 V. The digital equivalent for sine wave can be
calculated as follows.

+2.5 V

180° 3600
i90°
FFH
80H
96H
ABH
COH FEH
D{H
-2.5 V
E2H
EFH|
F8H

Fig. 13.6.5

We know that sin ° = 0 and sin 90° = 1. The range sin 0° to sin 90° is distributed
over digital range of 7FH to FFH ie. (FFH - 7FH) 128 decimal steps. Therefore, taking
128 as a offset we can write,
Digital equivalent value (DEV) for sin x = (128 + 128 x sin x)
where x is a angle in degrees and digital value is in decimal.

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13- 53 Applications and Design of Microcontroller Based Systems

Lookup table shows the digital equivalent values for sine wave.
Degrees Equation Digital Equivalent in Digital Equivalent in
Decimal Hex

(128 + 128 x sin 0) 128 80H

10° (128 + 128 x sin 10) 150 96H

20 (128 + 128 x sin 20) 171 ABH

300 (128 + 128 x sin 30) 192 COH

409 (128 +128 x sin 40) 210 D2H

50° (128 + 128 x sin 50) 226 E2H

609 (128 + 128 x sin 60) 239 EFH

70 (128 + 128 x sin 70) 248 F8H

80 (128 + 128 x sin 80) 254 FEH

90 (128 + 128 x sin 90) 256 --’ 255 FFH

1009 (128 + 128 x sin 100) 254 FEH

110° (128 + 128 x sin 110) 248 F8H

120° (128 + 128 x sin 120) 239 EFH

130 (128 + 128 x sin 130) 226 E2H

140° (128 + 128 x sin 140) 210 D2H

150 (128 + 128 x sin 150) 192 COH

160° (128 + 128 x sin 160) 171 ABH

170° (128 + 128 x sin 170) 150 96H

180° (128 + 128 x sin 180) 128 80H

(128 + 128 x sin 190) 106 6AH


190
200 (128 + 128 x sin 200) 84 54H

(128 + 128 x sin 210) 64 40H


210°
(128 + 128 x sin 220) 46 2EH
220
(128 + 128 x sin 230) 30 1EH
230°
(128 + 128 x sin 240) 17 11H
240°

(128 + 128 x sin 250) 08 08H


250°
(128 + 128 x sin 260) 02 02H
260°

TECHNICAL PUBLICATIONS - An up thrust for knowledge


off Microcontroller Based Systerns
13-54 Applications and Design
Microprocessor and Microcontrollers
00H
00
270 (128 +128 x sin 270)
02H
(128 + 128 x sin 280) 02
2800 08H
08
290 (128 + 128 x sin 290)
11H
300 (128 + 128 x sin 300) 17
1EH
30
310 (128 + 128 xsin 310)
2BH
(128 + 128 x sin 320) 46
320
40H
64
330 (128 + 128 xsin 330)
54H
(128 +128 x sin 340) 84
340 6AH
(128 +128x sin 350) 106
350
80
(128+ 128 xsin 360) 128
360
Table 13.6.1

AGAIN: MOVDPTR, #LUT Initialize pointer to lookup table


Initialize counter
MOV RO, #25H
BEGIN : CLR A
MOVC A, @A+DPTR Get datafrom lookup table

MOV P1, A Send data to port 1

INC DPTR
point to next lookup table entry
DJNZ RO, BEGIN Decrement counter and go to BEGIN
if not zerO

SJMP AGAIN Repeat the entire process


ORG 300

LUT: DB 80H,96H,ABH....
DB
DB 40H, 54H, 6AH, 80H

Note In above program we have to store entries from given lookup table instead of
aots.

Review Questions

1. Explain DAC0808 with the help of block diagram.


2. Draw and explain the typical interfacing circuit for DAC 0808.
3. Draw and explain the typical interfacing circuit for DAC 0808 in the bipolar range.
4. Give the important electrical characteristics for DAC 0808.
5. Interface an DAC to 8051. Write an ALP to generate triangular waveform.

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13-55 Applications and Design of Microcontroller Based Systems
6. Setup a circuit to generate a sine wave using 8051 and
DAC 0808. Explain how a sine wave Can
be generated using a suitable example.
7. Interface a DAC 0808 to 8051
microcontroller and write an assembly language program to
generate a sine wave of 10 Vpeak to peak. Give the complete hardware details and lookup table
used.
8. Drauw the block schematic of DAC 0808 interfaced to 8051 at
port P1 and write an 8051 pTogram
to generate sine wave.

13.7 Relay Interface


To control ON/OFF operation of ac devices we can use
electromagnetic relay. This
relay has both normally open and closed contacts. When a current is passed through the
coil of the relay, the switch arm is pulled down, opening the top contact and closing the
bottom contact, as shown in the Fig. 13.7.1.

Normally closed (NC)


contact
0000000OOOO
Normally open (NO)
Contact
Spring

Coil
Mounting
brackets
80000000o

Fig. 13.7.1 Electromagnetic relay


The relay contacts are rated for maximunm current of about 20A - 25 A. These relays
are also called mechanical relays because mechanical contact makes the circuit to ON or
OFF. The mechanical relays having higher current ratings are sometimes called
contactors.

The output current of 8051 microcontroller pins is not sufficient to drive the relay, or
solenoid. The relay/solenoid coil needs around 10 mA - 100 mA to be energized and
microcontroller's pin can provide a maximum of 1 - 2mA. For this reason, we have to
use driver such as the ULN2803 or a power transistor or a power MOSFET between the
microcontroller and the relay/solenoid as shown in the Fig. 13.7.2.

TECHNICAL PUBLICATIONSs An up thrust for knowledge


Systems
Microprocessor and Microcontrollers 13- 56 Applications and Design of Microcontroller Based

+V

+5 V +5 V 0000

Relay
Contact
S4.7K
8051
P1.0 Relay /solenoid
coil

ULN 2803

(a) Relay driving circuit

Freewheeling Relay
diode Contact

Relay / solenoid
coil

8051 SETB P1.0; Makes realy ON


MOSFET CLR P1.0; Makes realy OFF
P1.0

(b) Relay driving circuit using MOSFET


Fig. 13.7.2
Review Question

1. Explain the interfacing of relay to 8051.


13.8 Stepper Motor Interfacing GTU: Summer-10,12, Winter-08,11

A stepper motor is a digital motor. It can be driven by digital signal. Fig. 13.8.1
shows the typical 2 phase motor interfaced using 8051. Motor shown in the circuit has
two phases, with center-tap winding. The center taps of these windings are connected to
the 12 V supply. Due to this, motor can be excited by grounding four terminals of the
two windings. Motor can be rotated in steps by giving proper excitation sequence to
these windings. The lower nibble of port 1 of the 8051 is used to generate excitation

TECHNICAL PUBLICATIONS® - An up thrust for knowledge


Microprocessor and Microcontrollers 13-57 Applications and Design of Microcontroller Based Systems
+12 V

Stepper
X, motor
P1.0
7407

0090
Yo

P1.1 +12V
7407

L
P1.2
7407

P1.3
7407

Fig. 13.8.1 Stepper motor interface


signals in the proper sequence. Particular winding is excited by making
port pin low. For example, winding X1 can be excited by making P1.0 low. corresponding
The Table 13.8.1 shows typical excitation sequence. The given
excitation sequence
rotates the motor in clockwise direction. To rotate motor in anticlockwise
direction we
have to excite motor in a reverse sequence.
The excitation sequence for stepper motor
-X,
may change due to change in winding
connections. However, it is not desirable to
excite both the ends of the same winding
Simultaneously. This cancels the flux and
motor winding may damage. To avoid this,
digital locking system must be designed. Fig. 13.8.2 Digital locking system

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microcontroler Based Systeme
Microprocessor and Microcontrollers 13- 58 Applications and Design of

locking system. Only one output is activated (made


Fig. 13.8.2 shows a simple digital output is disabled (made high).
low) when properly excited; otherwise

P 1.3 P1.2 P.1 P 10 CODE


Step Y, Y
0 1 0 051
1

11 06HH
2 1 0
10 0AH
3 1
1 00 09H

Note Pl4 to P1.7 0

Table 13.8.1 Full step excitation sequence


The excitation sequence given in Table 13.8.1 is called full step sequence. In which
excitation ends of the phase are changed in one step. The excitation sequence given in
Table 13.8.2 takes two steps to change the excitation ends of the phase. Such a sequence
is called half step sequence and in each step the motor is rotated by 0.9°.

Step Y, P1.3 P 12 Pi.1 P L0 CODE


1 0 1 05H

1 0 0 07H

3 1 011 0 061

OEH
10 1 0AH

1 01 0 1 OBH

09H

8 00 1 ODH

1 1 05H

Table 13.8.2 Half step excitation sequence

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13- 59
Applications and Design of Microcontroller Based Systems
We know that stepper
from one position to the motor is stepped 9+12 V
next by
currents through the fields in thechanging the
motor. The
000
Free
winding inductance opposes the change in wheeling Motor
current and this puts limit on the diode winding
rate. For higher stepping rates andstepping
more
torque, it is necessary to use a higher voltage Ra
source and current limiting resistors as shown
in Fig. 13.8.3. By adding series
decrease L/R time constant, which resistance, we
current to change
allows the
more rapidly in the
windings. There is a power loss across series
resistor, but designer has to compromise Series
resistance
between power and speed.

Fig. 13.8.3 Excitation circuit with series


resistance
Example 13.8.1 Write an 8051 ALP program to rotate
stepper motor for 360 using
connections given in Fig 13.8.1 Use ful-step sequence.
Solution:
Algorithm
1. Initialize a
counter with rotation count
2. Initialize pointer to excitation code table
3. Initialize counter to excitation code
sequence
4. Get the excitation code
5. Send the excitation code
6. Wait for sometime

7. Increment pointer toexcitation code table


8. Decrement counter to excitation code sequence and if not zero, repeat
steps 4, 5, 6,
7 and 8.
9. Decrement counter having rotation count and if not zero repeat steps 2, 3, 4, 5, 6, 7
and 8.
For full-step, motor rotates by 1.8° when excited once. Thus complete full step
sequence rotates motor 1.8 X 4 =7.2". To rotate motor 360° we have to set count as
given below :
360
Count = = 50 = 32H
7.2

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Based Systems
Microprocessor and Microcontrollers 13- 60 Applications and Design of Microcontroller

Program
MOV R0 # COUNT : Initialize rotation cCount
AGAIN: MOV DPTR, #ETC ; Initialize pointer to excitation code table
MOV R1, #04 Initialize counter to excitation code sequence
BACK: MOVX A, @DPTR Get the excitation code
MOVP1, A send the excitation code
LCALL DELAY : Wait for some timne
INC DPTR ; Increment pointer
DJNZ R1, BACK : Decrement R1; if not zero goto BACK
DJNZ RO, AGAIN ; Decrement RO; if not zero goto AGAIN
RET
ORG 3000H
ETC DB 05H,06H,0AH,09H; code sequence for clockwise rotation
Example 13.8.2 Write assembly language program to control conveyer belt using stepper
motor and 8051 controller. Belt moues continuousyat ateof1sten/sec. but stops for
5 sec. uhen external interruptoceturs and then contnues tomove.
Solution :
MAIN MOV IE, #1000 0001B Enable external interrupt 0
AGAIN: MOV DPTR,#ETC ; Initialize pointer to excitation code table
MOV R1, #04 ; Initialize counter to excitation code sequence
BACK: MOVX A, @DPTR ; Get the excitation code
MOV P1, A ; send the excitation code
MOVA,#14H : Initialize count = 20
LCALL DELAY ; Wait for 1sec
INCDPTR ; Increment pointer
DJNZ R1, BACK ; Decrement R1
; if not zero goto BACK
SJMP AGAIN ; Repeat
ORG 3000H
ETC DB 05H,06H, 0AH, 09H ; Code sequence for
Clockwise rotation

Example 13.8.3 Describe the 8051 connection to the stepper motor and a ALP to rotate it
continuously in both clockwise or anti-clockwise after selection of mode. Check direction
after completion of one complete sequence. GTU: Winter-08
Solution: Assume mode selection input is connected to Port 2.0. If mode selection input
is 1, rotate motor anti-clockwise; otherwise clockwise.
AGAIN: SETB P2.0 Configure P2.0 as an input
JB P2.0, SKIP Check mode selection
MOV DPTR, #ETC1 Initialize pointer to excitation code table
SJMP NEXT for clockwise rotation

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13- 61 Applications and Design of Microcontroller Based Systems
SKIP : MOV DPTR, #ETC2 Initialize pointer to excitation code table
for anti-clockwise rotation
NEXT: MOV R1, #04 Initialize counter to excitation code sequence
BACK: MOVX A, @DPTR Get the excitation code
MOVP1, A Send the excitation code
LCALL DELAY Wait for some time
INC DPTR
Increment pointer
DJNZ R1, BACK
Decrement R1; if not zero goto BACK
SJMP AGAIN
Repeat
RET
ORG 3000H
ETC1 DB 05H, 06H, 0AH, 09H ;code sequence for clockwise rotation
ETC2 DB 09H, 0AH, 06H, 05H
; code sequence for anti-clockwise rotation
Example 13.8.4 Write a ALP to rotate the
e an stepper motor in clockwise direction, if the status
of a switch connected to port pin P1.2 is
ON. Otherwise rotate it in counterclockwise
dmection,
Solution :
GTU:Winter-1 1
ORG OH
MAIN :
;Starting address
SETB P1.2 :Make it an input
MOV DPTR, #ETC ;Initialize base pointer to
MOV RO, #00H excitation code table
;Initialize pointer to
BACK : JB P1.2, ACW
excitation code table
Check switch status
CJNZ RO, #04, NEXT ;Roll over the
MOV RO, #00H
sequence code
NEXT : MOVA, RO ;Copy pointer in A
MOVC A, @A + DPTR ;Get the code to rotate
MOV P1, A
clockwise
:Send code to port 1
LCALL Delay :Wait for some time
INC RO :Point to next code
SJMP BACK ;Repeat
ACW: R
CJNZ RO, #OFFH, NEXT1 ;Roll over the sequence code
MOV RO, #03H P1.2
NEXT1: MOV A, RO : Copy pointer in A
MOVC A, @A + DPTR :Get the code to rotate o SW
anticlockwise
MOV P1, A : Send code to port 1
LCALL Delay : Wait for somne time
DEC RO ;Point to previous code
SJMP BACK ;Repeat
Delay : MOV R2, #100

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Microprocessor and Microcontrollers 13- 62 Applications and Design of Microcontroller Based Systems

AGAIN1 : MOVR3, #255


AGAIN: DJNZ R3, AGAIN
DJNZ R2, AGAIN1
RET
ORG 0100H
ETC DB 05H, 06H, 0AH, 09H
to 8051 and write 8051
Example 13.8.5 Show the interfacing of a stepper motor
clockwise and one rotation
aSsembiY/8O51 C programto rotate stevper motor 2 rotations GTU : Summer- 10
anticlockuwise with appropriate delay.
Solution:

C Program
#include <reg51.h>
unsigned char i;
void main()

100 = 720° = 2 Rotations */


for (i=0; i< 100; i++) /* Rotate 1.8 x 4x

P1 = 0x05;
Delay(100):
P1 = 0x06;
Delay(100);
P1 = 0x0A;
Delay(100);
P1 = x09;
Delay(100);
4 x 50 = 360° = 1 Rotations */
for (i=0; i< 50; i++) /* Rotate 1.8 x

P1 = 0x09;
Delay(100):
P1 = 0x0A;
Delay(100);
P1 = 0x06;
Delay(100);
P1 = 0x05;
Delay(100):

}
cnt)
void Delay(unsigned int

TECHNICAL PUBLICATIONS An up thrust for knowledge


MicroprDoessor and Microcontrollers 13-63
Applications and Design of Microcontroller Based Systems
unsigned int i,j:
for(i=0; i<cnt; i++)
for(j=0; j<1200; j+t+);
}

Example 13.8.6 Draw a schematic diagram of 8051


interfaced with unipolar stepper motor.
Give reason, one need driver IC or circuit for
interfacing stepper motor with 8051.
GTU : Summer- 12, Marks 7
Solution: The Fig. 13.8.4 shows a schematic diagram of 8051
stepper motor. We can either use drive IC such interfaced with unipolar
as ULN 2003 or four transistor drivers
to energize the stator of the stepper motor.
When transistors are used as drivers, we
must also use diodes to take care of inductive current
generated when the coil is turned
off. One that reason driver IC is preferable for
9+5 V
interfacing stepper motor with 8051.

9+5 V
4.7 K4.7 K S4.7 K4.7 K
P1.0

P1.1 -00000000

P12
r0000000
P1.3

8051
ULN2003

Fig. 13.8.4

Example 13.8.7 Write a program to rotate a stepper motor,asinterfacedin aboveproblem, by


64° in clockwise direction. ASSume the motor has 4 step angle of2. Use the 4 step
sequence. GTU : Summer-12, Marks 7
Solution: Movement per 4-step sequence=4 x 2°= 8°.
To rotate motor 64° we have to send 4-step sequence times, i.e., 32 steps.
ORG 0000H
MOV A,#66H
MOV RO,#32
This will generate sequence of 6, 3, 9 and C.
BACK: RR A
MOV P1,A
TECHNICAL PUBLICATIONS- An up thrust for knowledge
Microcontroller Based Systems
Microprocessor and Microcontrollers 13-64 Applications and Design of

A CALL Delay
DJNZ RO,BACK
END

Review Questions

1. Draw and explain the stepper motor interface.


2. Explain the methods for excitation of stepper motor.
3. Explain the limitation for increasing the speed of stepper motor.
4. Interface stepper motor to the 8051 microcontroller and write an assembly language program to
rotate it 180°.

5. Interface 8051 to a stepper motor and write a program to rotate it continuously.


6. Interface a stepper motor to 8051 and write a program to rotate in clockwise direction, with a
speed of 6 RPM. Given,step angle = 1.8° and steps per revolution = 200.
7. Show an interface of 8051 controller with a stepper motor drive circuit and explain its principles of
operation.
8. Describe the 8051 connection to stepper motor and write an Assembly language program to rotate
the motor clockwise for 180°. Assuming motor specification 1.8/step.
9. Show the interfacing of a stepper motor to 8051 and write 8051 assembly/8051 'C' program to
rotate stepper motor 2 rotations clockwise and one rotation anticlockwise with appropriate delay.
10. Describe the 8051 connection to the stepper motor and a ALP to rotate it continuously in both
clockwise or anti-clockwise after selection of mode.
11. Show the interfacing of astepper motor to 8051 and orite a program to rotate steyper motor
5steps in clockwise direction and 10 steps in anticlockwise direction with a delay betoeen each
step.

13.9 DC Motor Interfacing GTU: Winter-17, 19, Summer-17


Unlike stepper motor, the DC (Direct Current) motor rotates continuously. It has two
terminals positive and negative. Connecting DC power supply to these terminals rotates
motor in one direct and reversing the polarity of the power supply reverses the direction
of rotation. The speed of the DC motor is measured in
Revolutions Per Minute (RPM).
The speed of the DC motor increases with increase in the supply voltage. However
we can not exceed supply voltage beyond the rated voltage. The speed of the DC motor
also depends on the load. At no-load speed is highest. As we
increase the load, the
speed decreases. The overloading the DC motor can damage it because of excessive heat
generated due to high current consumption.
Direction control

The Fig, 13.9.1 shows how de motor changes its direction of rotation when
the
polarity of power supply reverses.
TECHNICAL PUBLICATIONS - An up thrust for
knowledge
Microprocessor and Microcontrollers 13- 65
Applications and Design of Microcontroller Based Systems

M
M

Clockwise rotation Anticlockwise rotation


Fig. 13.9.1 DC motor rotation
By using switches for changing the power supply polarity we can control the
direction of the rotation of the DCmotor. This is illustrated in the Fig.
13.9.2.
+V

SW o
SW 1

SW 2
SW3

Motor not
running
Fig. 13.9.2 Bidirectional control of DC motor
SW3 SW2 SWI SWO Motor rotation
ON OFF OFF ON Clockwise
OFF ON ON OFF Anticlockwise
W*wwwwwwww.

Table 13.9.1 Switch configurations


Any other switch configurations, for example, SWOand SW2 ON is invalid, because it
creates short circuit of the power supply.
Example 13.9.1 Write an 8051ALP to control the direction of the DC motor according to the
status of bit P1.0. AsSume port pins P2.0, P2.1, P2.2 and P2.3 controls the suitches SWO,
SW1, SW2 and SW3 respectively.
Solution:
ORG OH
CLR P2.0 :make all switches OFF
CLR P2.1
TECHNICAL PUBLICATIONS - An up thrust for knowledge
MicroprocOssor and Microcontrollers 13- 66 Applications and Design of Microcontroller Based Systems

CLR P2.2
CLR P2.3
SETB P1.0 ;configure P1.0 as input
Check: JNB P1.0,Clockwise
CLR P2.0 :Make SWO OFF
SWTB P2.1 ;Make SW1 ON
SETB P2.2 :Make SW2 ON
CLR P2.3 :Make SW3 OFF
SJMP check
Clockwise: SETB P2.0 ;Make SWO ON
CLR P2.1 ;Make SW1 OFF
CLR P2.2 ;Make SW2 OFF
SETB P2.3 ;Make SW3 ON
SJMP check
END

13.9.1 Pulse Width Modulation (PWM)


We know that the speed of the dc motor depends on the applied voltage. The
average applied DCvoltage and hence the power can be varied using technique called
pulse width modulation. In this technique, the dc power supply is not a voltage of
fixed amplitude; however it is a pulsating DC voltage. By changing pulse width we can
change the applied power. This is illustrated in the Fig. 13.9.3.

25 %DC 4 Power

50 % DC Power

75 % DC Power
3T -

100 % DC Full Power

Fig. 13.9.3 Applied power variation using pulse width modulation


13.9.2 DC Motor Control with Optoisolator
The Fig. 13.9.4 shows the dc motor control using a bipolar transistor and MOSFET as
a switch. The circuit uses optoisolator which allows the motor and 8051 to use separate
power supplies. The circuit shown in the Fig. 13.9.4 is also protected from EMI
interference produced due to motor brushes. To protect the circuit from EMI interferernce
the decoupling capacitor is connected across the motor.

TECHNICAL PUBLICATIONS - An up thrust for


knowledge
Microprocessor and Microcontrollers 13-67 Applications and Design of Microcontroller Based Systems

12 V

M
+5 V 1N4004
Decoupling
capacitor
330 2 ILD74
8051 OPTOISOLATOR
8 10 K
TIP 120
Darlington
2 7 Transistor
Pz: +12 V
S100 K
3 6

4 5

Fig. 13.9.4 (a) DC motor connection using a bipolar transistor

12 V

+5 V M
1N4004
Decoupling
capacitor
330 2 ILD74 D
8051 OPTOISOLATOR
10 K
IRF 521

2
P0
+12 V
S100 K
3

Fig. 13.9.4 (b) DC motor connectlon using a MOSFET


As shown in the Fig. 13.9.4, the port pin P2.0 is used to
control the
motor. When P2.0 is low, motor is switched ON and when P2.0 isswitching of DC
high motor is
switched OFF.
In MOSFET circuit, the zener diode keeps the gate voltage
below the rated maximum
gate voltage for MOSFET.

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Based Systems
Microprocessor and Microcontrollers 13- 68 Applications and Design of Microcontroller

ON-OFF Switch connected to port


Example 13.9.2 Write an 8051 ALP to read the state of
PWM
P1.0. If it is low apply 25 %of power; otherwise upply 50 % of power using
technique. Use pin P2.0 to
to control
contro the DC motor.
Solution:
ORG 0H
CLR P2.0 ;turn off motor
SETB P1,0 ;Make P1.0 as input
Check: JNB P1.0,P50
SETB P2.0 ; high portion of pulse
MOV R5,#25
ACALL DELAY
CLR P2.0 ;low portion of pulse
MOV R5,#75
ACALL DELAY
SJMP MONITOR
P50: SETB P2.0 ;high portion of pulse
MOVR5,#50
ACALL DELAY
CLR P2.0 ;low portion of pulse
MOV R5,#50
ACALL DELAY
SJMP MONITOR
DELAY:
BACK1: MOV R2,#100
BACK2: MOV R3,#255
BACK3: DJNZ R3,BACK3
DJNZ R2,BACK2
DJNZ R5,BACK1
RET
END

Example 13.9.3 Write an 8051 C program to read the state of


ON-OFF switch connected to
port P1.0. If it is low apply 50 % of power; otherwise apply 75 %of power using
PWM
technique. Use pin 2.0to controlthe DC motor.
Solution:
#include <reg5l.h>
sbit SW = P1^0;
sbit CTL = P2^0;
vold Delay(unaigned int value);
void main()
{
SW = 1;
TECHNICAL PUBLICATIONS - An up thrust for
knowledge
Microprocessor and Microcontrollers 13- 69 Applications and Design of Microcontroller Based Systems

CTL = 0;
while(1)

if(SW =1)

CTL = 1;
Delay(75);
CTL = 0;
Delay(25);
else

CTL = 1;
Delay(50);
CTL = 0;
Delay(50);

}
void Delay(unsigned int value)
unsigned char i,j;
for(i=0; i<1200; i++)
for(j=0; j<value; j++);

Review Questions

1. Explain the ways of controlling speed of DC motor.


2. Write an 8051 C progam to control the direction of dc motor.
3. What is PWM ? How is it used to control the speed of DCmotor ?
4. How to interface DC motor to 8051 microcontroller using optoisolator? Write a C program to
move DC motor with 25 % duty cycle pulse.
5. Draw interfacing diagram for interfacing of DC motor using H-bridge circuit with 8051
microcontroller and also connect a switch at P2.1. GTU : Winter-17, Marks 3
6. How opto isolator can be used for D.C. motor control ? Explain it with suitable diagram.
GTU : Summer-17, Marks 7

1. For the interfacing diagram in (a), write a program to rotate DC motor in clockwise direction if
switch is ON and in anti-clockwise direction if the switch is OFF. GTU : Winter-17, Marks 4
8. Discuss how the speed and direction of DC motor canbe controlled using microcontroller.
GTU : Winter-19, Marks 7

DO0
TECHNICAL PUBLICA TIONS - An up thrust for knowledge

You might also like