Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
MICROPROCESSORS AND MICROCONTROLLER 1
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 1
Microprocessor Applications
Data Acquisition System
Data acquisition is the process of sampling signals that measure real world
physical conditions ( such as temperature, voltage, pressure, sound, etc..) and
converting the resulting samples into digital numeric values that can be
manipulated by a microprocessor/microcontroller/computer. Data acquisition
systems (DAS or DAQ) typically convert analog information to digital values for
processing. The components of data acquisition systems include:
Sensors - to convert physical parameters to electrical signals.
Signal conditioning circuitry - to convert sensor signals into a form that can
be converted to digital values.
Sample and Hold circuits – to hold analog input value over a certain length
of time for subsequent processing.
Analog-to-digital converters - to convert conditioned sensor signals to
digital values.
Analog Multiplexors – To measure or quantize more than one signal
A basic DAQ system consists of sensors, DAQ measurement hardware, and a
microprocessor / microcontroller/computer with programmable software.
Process
Analog Mux
Sample/ Hold Amp
A/ D
µp/µc
Keyboard
Display
Transducers
Block Diagram of DAS
MICROPROCESSORS AND MICROCONTROLLER 2
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 2
Sample and Hold Circuit (S/H)
If an attempt is made to digitize a rapidly changing input signal, the input
signal would have changed before the conversion is complete. The output of the
converter will represent the input at the end of the conversion cycle rather than at
the start. Therefore an error ΔV is introduced in the output voltage. This error
voltage is a function of the rate of change of the input signal. This error is
eliminated by using a sample and hold with a buffer amplifier on the input of the
A/D converter.
The function of the S/H circuit is to sample an analog input signal and
hold this value over a certain length of time for subsequent processing. (i.e.) S/H
circuit is used to maintain a stable input to the ADC during conversion. A S/H
amplifier has two modes of operation controlled by a digital signal. In the
SAMPLE mode the output follows the input, normally with unity gain. In the
HOLD mode, the output of the S/H amplifier retains the last value it had until it
switches to sample mode.
LF 398A S/H.
The LF398A is a 8 pin DIP ( National semiconductor). The only component
to be externally connected is the hold capacitor. A low value of capacitance is
preferred for quick charging by the input amplifier and a high capacitance is
preferred to retain the charge for a longer duration. In a particular application,
proper capacitance value should be selected for optimum performance.
Parameters of S/H
Acquisition time: This is the time required by the output of the device to reach its
final value within a specified error percentage in the Sample Mode.
Aperture time: It is the time required to switch from sample state to hold state.
Typical value of aperture time is 10 ms.
MICROPROCESSORS AND MICROCONTROLLER 3
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 3
Droop: It is the change of output voltage per unit time during hold, as a result of
leakage or bias currents flowing through the capacitor. For LF398A the droop
value is 5mV/min.
Fig.
Multiplexers
Multiplexers are basically switches to transfer the signals from one of the
input sources to the output on the control command. The control command should
clearly identify the input source from which the information signals is to be
transferred. The various input sources are called multiplexer channels. The
information required to select the channel is known as address of the channel.
The analog switches used in the multiplexer may be any one of several types
of electromechanical or solid state switches.
Interfacing 7 – segment displays
Decimal digits and some letters of the alphabet can be displayed using a
seven segment display devices. In seven segment displays an LED is used for each
segment. There are two types of seven-segment display devices: Common Anode
and Common Cathode types.
MICROPROCESSORS AND MICROCONTROLLER 4
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 4
In common anode type all of the anodes of the LEDs are connected in
common; in the common cathode type all of the cathodes of the LEDs are
connected in common.
These variations require different drive arrangements. BCD to seven
segment (7447 / 7448) decoder drivers are available for driving seven segment
displays.7447 is used to drive common anode type and 7448 is used to drive
common cathode type. The following figure shows the connection diagrams.
MICROPROCESSORS AND MICROCONTROLLER 5
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 5
In common anode type, logic 0 at decoder driver output turns a segment ON
where as in common cathodes type a logic 1 at decoder driver output turns a
segment ON.
Interfacing 7 segment displays with 8085
Here the output device 7-segment displays are interfaced with 8085 in I/O
mapped IO scheme. Using a suitable decoder circuit the address of the ports of
8255 can be fixed. Here Port A is configured as an output port. Pins PA0-PA3 is
used to send the BCD value of the LSD and PA4-PA7 is used to send the BCD
value of MSD. Using this scheme it is possible to displays numerical values from
00 to 99.
The following program demonstrates the working of the above circuit.
Aim: To display the content of the memory location 4500H in the seven segment
display device.
Control word formation:
Port A , Port B, Port C : output Mode: Simple I/O
Control Word: 80H
8085
IO/M’
8255 PPI
PA0-PA3
RD’
WR’
PA4-PA7
CS’
7447
7447
ADDRESS
DECODER
D0-D7
A0-A7
MICROPROCESSORS AND MICROCONTROLLER 6
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 6
Program: To display two digits on a 7 segment displays
START: MVI A, 80 ; Control word 80H is stored in Acc
OUT CWR ; Control word is send to Control Word Reg. of 8255
LDA 4500 ; The data to be displayed is loaded in to Acc
DAA ; Decimal Adjust Accumulator to get the BCD values
OUT PORTA ; PA0-PA3 receives the BCD value of LSD and
HLT ; PA4-PA7 receives the BCD value of MSD.
;The corresponding digits are displayed in the 7-seg.disp.
DIGITAL CLOCK
A digital clock is a type of clock that displays the time digitally i.e. in
numerals as opposed to an analog clock. Also many microprocessor applications
would require, doing certain tasks at specific time of the day or would involve the
time of day in some other form. For example switching ON and OFF street lights
at specific time in the evening and following morning or punching entry time of
every worker for a shift, at a factory gate etc. A basic requirement of these types of
applications is a real time digital clock with a display of current time. A digital
clock can be implemented by using a dedicated hardware like MM5314 or by
software. The following program is used to implement a digital clock on an 8085
system.
The basic requirement of a digital clock is the seven segment displays to
show Hours, Minutes & Seconds. The seven segment displays are interfaced with
the 8085 processor through the ports of 8255 PPI available in the microprocessor
trainer Kit. The displays are driven by suitable seven segment decoder driver
(7447/7448). The main part of the digital clock program is the accurate generation
of 1 Hz frequency or 1 second time delay for reference.
MICROPROCESSORS AND MICROCONTROLLER 7
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 7
The 1Hz frequency or 1 second time delay can be produced exactly by using
a timer 8253 or by using a well designed delay subroutine.
Program Logic
Three CPU registers are used to count Hours, Minutes and Seconds. The
Seconds counter is incremented for every second, and its content checked for 60.
When it reaches 60, it is reset to 0 and the Minutes counter is incremented by one.
When the Minutes counter reaches 60, it is reset to zero and the Hour counter is
incremented by one. Similarly, when the Hours counter reaches 13 it is reset to 1.
The counter incrementing is done in decimal format. For every second the display
is updated by the Hours, Minutes and Seconds registers. The program works in a
continuous loop and displays time round the clock. The block diagram of the
digital clock, the flow chart and the program are shown below.
Digital Clock Basic Block Diagram
A0-A7
8085
8255
PA4-A7
PA0-A3
RD’
WR’ PB4-B7
PB0-B3
CS’ PC4-C7
PC0-C3
ADDRESS
DECODER
D0-D7
7447
7447
7447
7447
7447
7447
Hr
Min
Sec
MICROPROCESSORS AND MICROCONTROLLER 8
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 8
FLOW CHART
N
N Y
START
INITIALIZE HR,MIN,SEC
COUNTERS
CALL DELAY SUBROUTINE
FOR 1 SEC
SEC SEC +1
SEC >59?
MIN MIN +1 SEC 0
MIN >59?
HR HR +1 MIN 0
HR >12?
HR1
Y
Y N
MICROPROCESSORS AND MICROCONTROLLER 9
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 9
8255 Port Configuration:
Control word formation:
All the ports of 8255 are configured as output ports in Mode 0.
(i.e) Port A , Port B, Port C : output , Mode: Simple I/O
Therefore, the Control Word is: 80H
Port C : to send Seconds value to 7 segment displays
Port B: to send Minutes value to 7 segment displays
Port A: to send Hour value to 7 segment display
Program
Label Mnemonics Comment
Start: LXI D,HH00 ;(D) Hr
LXI B,MMSS ; (B) Min, (C) Sec
MVI A,80H ; (A) Control word for Port Conf.
OUT CWR ; Move the Control word to Control Register
of 8255 to configure the ports/
DISP: CALL DISPLAY ;Call display Subroutine to Display
Hr,Min,Sec values on the 7 segment display
DEL: CALL DELAY ; Call 1 sec Delay Subroutine
INR C ; Sec Sec +1
MOV A,C ;Mov Sec to Acc
CPI A,3C ; Is Sec >59 (ie) Sec =60?
JNZ DEL ; If No (ZF!=1) , Goto Label DISP
MVI C,00 ; if Yes, set Sec 00
INR B ; Min Min +1
MOV A,B ; Move Min value to Acc
MICROPROCESSORS AND MICROCONTROLLER 10
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 10
CPI 3C ; Is Min >59 (ie) Min = 60?
JNZ DEL ; If No (ZF!=1) , Goto Label DISP
MVI B,00 ; If Yes, set Min 00
INR D ;Hour Hour +1
MOV A,D ;Move Hour value to A
CPI 0D ; if Hour >13 ?
JNZ DEL ;If No (ZF!=1) , Goto Label DISP
MVI D,01 ; If Yes , set Hour 1
JMP DISP ; Jump to DISP
HLT ;HALT
Subroutine to Display Hour , Min, and Sec values
DISP: MOV A, D ; (A) Hour Value
DAA ; Get the BCD values
OUT PORT A ; Display Hour value
MOV A,B ; (A) Minute Value
DAA ; Get the BCD value
OUT PORTB ;Display Minute Value
MOV A, C ; (A) Seconds
DAA ;Get the BCD value
OUT PORTC ; Display Seconds value
RET ; Return
MICROPROCESSORS AND MICROCONTROLLER 11
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 11
1 Sec Delay Subroutine:
DELAY: PUSH A ; Save the contents of registers
PUSH B ; used in the main program
PUSH D
LXI B,COUNT2 ; (BC) COUNT2 based on COUNT1
LOOP2: LXI D,COUNT1 ; (DE) COUNT1 based on CLK freq.
LOOP1: DCX D
MOV A,D
ORA E
JNZ LOOP1
DCX B
MOV A,B
ORA C
JNZ LOOP2
RET ;RETURN
MICROPROCESSORS AND MICROCONTROLLER 12
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 12
ZERO CROSS DETECTION
A zero-crossing is a point where the sign of a mathematical function changes (e.g.
from positive to negative), represented by a crossing of the axis (zero value) in the
graph of the function. It is a commonly used term in electronics, mathematics,
sound, and image processing.
FREQUENCY MEASUREMENT
Frequency measurement is a very important application of both counting and
timing. Fundamentally, frequency measurement is a measure of how many times
something happens within a certain known period. The use can be as diverse as
how many counts are received per minute in Geiger Counter, how many cycles per
second (hertz) there are in an electronic or acoustic measurement or how many
wheel revolutions there are per unit of time in a speed of measurement. Both a
counter and a timer are needed, the timer to measure the reference time and the
counter to count the number of events within that time.
To measure the frequency of a signal, the time period for half cycle is
measured which is inversely proportional to the frequency. A sinusoidal signal is
MICROPROCESSORS AND MICROCONTROLLER 13
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 13
converted to square wave using a voltage comparator LM311 or OpAmp Lm747.
A diode is used to rectify the output signal. A potential divider is used to reduce
the magnitude to 5 volts.
By the method of zero cross detection, the pulse width can be determined. A
program can be used to sense the zero instant of the rectified square wave. The
microprocessor measures the magnitude of the square wave at two consecutive
points as shown in fig. The two magnitudes are compared and decision (i.e.,
whether the point is at zero instant) is taken on the basis of carry and zero flags.
Various points of on the square wave are shown in fig. Very near to P3 at its
left side the magnitude of square wave is zero and at P4, logic 1. The
microprocessor subtracts the 1st value from the 2
nd, so the result is non-zero and
there is no carry. This is the basis of selection of zero instant point. Suppose the
microprocessor takes reading at P1 and P2 where both magnitudes are zero.
Difference of the two is zero. So this is not the zero instant of the wave. At points
P5 and P6, the difference of the two values is zero, so it is also not a zero instant
point. At P7, and P8, the difference is non-zero, but there is carry. So it is the end
point of the half-square wave.
As soon as the zero instant point is detected the microprocessor initiates a
register pair to count the number how many times the loop is executed. [or start the
timer to find the elapsed time between two zero instant points]. It crosses the loop
when the magnitude of the square wave becomes zero. Thus the time for half cycle
is measured. The count can be compared with stored numbers in a look-up table
and the frequency can be displayed.
MICROPROCESSORS AND MICROCONTROLLER 14
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 14
FLOW CHART
MICROPROCESSORS AND MICROCONTROLLER 15
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 15
Port A of 8255 is configured as Input port and the signal whose frequency to be
determined is connected to the Port line PA0.
Program:
START: MVI A,98 ;Get the control word
OUT cwr ; Initialize the ports
READ: IN PORTA ; Read voltage pulse at Port- A
MOV B,A ;
IN PORTA ; Read voltage pulse again
CMP B ;Compare two readings
JZ READ ;
JC READ ;
LXI B,0000; Initialize BC pair for counting
LOOP: INX B
IN PORTA ;Read voltage pulse
RAR
JC LOOP ;Check whether v has becomes zero. No goto Loop
CALL LTAB; Call Lookup table Subroutine
CALL DISP ; Call Display Subroutine
HLT ;Stop
LOOK UP TABLE
COUNT FREQUENCY
MICROPROCESSORS AND MICROCONTROLLER 16
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 16
8085 Based Traffic Light Control System
A simple traffic light system which has only two basic sequences of traffic is
used in the model. First the traffic is allowed from North to South and from South
to North direction. During this period, no traffic is allowed either way from East to
West or from West to East. In the second sequence the condition is just reversed.
(i.e) Vehicles movement from East to West and West to East is allowed, but North
to South and South to North is not allowed. In both the sequences, free left is
allowed. A typical road junction with the arrangement of Lamps is shown in the
following fig.
R – RED Lamps to stop the traffic
G – Green Lamps to allow the traffic flow.
Y – Yellow Lamp to caution that traffic is about to start or about to stop.
MICROPROCESSORS AND MICROCONTROLLER 17
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 17
There are toally 12 LEDs/Lamps. In order to control the lamps the PPI 8255 is
used in the system. The Port A and Port CLower of 8255 is used to connect the
traffic lights as shown below.
Lamp R1 G1 Y1 R2 G2 Y2 R3 G3 Y3 R4 G4 Y4
Port PC3 PC2 PC1 PC0 PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
SeqA 0 1 0 1 0 0 0 1 0 1 0 0
05H 14H
SeqB 1 0` 0 0 1 0 1 0 0 0 1 0
08H A2H
SeqW 0 0` 1 0 0 1 0 0 1 0 0 1
02H 49H
The above table also shows the respective control words to activate Sequence A ,
Sequence B and Sequence W (Warning indicator- Yellow)
Program Logic.
Step 1: Program the Ports A and Port C (lower) of 8255 as output ports in
simple i/o mode.
Step 2: Activate Sequence A
Step 3: Wait for T1 seconds.
Step 4: Activate the Sequence W
Step 5: Wait for T2 seconds.
Step 6: Actiave Sequence B
Step 7: Wait for T1 seconds.
Step 8: Activate the Sequence W
Step 9: Wait for T2 seconds.
Step 6: Go to Step 2
MICROPROCESSORS AND MICROCONTROLLER 18
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 18
Connection Diagram
Program:
As discussed in the class room.
The
The LEDs in the circuit can be replaced by high voltage lamps by using relay and a
switching transistor as shown in the above figure.
MICROPROCESSORS AND MICROCONTROLLER 19
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 19
MICROPROCESSORS AND MICROCONTROLLER 20
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 20
MICROPROCESSORS AND MICROCONTROLLER 21
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 21
MICROPROCESSORS AND MICROCONTROLLER 22
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 22
MICROPROCESSORS AND MICROCONTROLLER 23
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 23
MICROPROCESSORS AND MICROCONTROLLER 24
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 24
MICROPROCESSORS AND MICROCONTROLLER 25
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 25
MICROPROCESSORS AND MICROCONTROLLER 26
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 26
MICROPROCESSORS AND MICROCONTROLLER 27
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 27
MICROPROCESSORS AND MICROCONTROLLER 28
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 28
MICROPROCESSORS AND MICROCONTROLLER 29
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 29
MICROPROCESSORS AND MICROCONTROLLER 30
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 30
MICROPROCESSORS AND MICROCONTROLLER 31
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 31
MICROPROCESSORS AND MICROCONTROLLER 32
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 32
MICROPROCESSORS AND MICROCONTROLLER 33
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 33
- Motor speed from nagoor kani –
-
MICROPROCESSORS AND MICROCONTROLLER 34
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 34
-
MICROPROCESSORS AND MICROCONTROLLER 35
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 35
MICROPROCESSORS AND MICROCONTROLLER 36
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 36
MICROPROCESSORS AND MICROCONTROLLER 37
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 37
MICROPROCESSORS AND MICROCONTROLLER 38
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 38
MICROPROCESSORS AND MICROCONTROLLER 39
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 39
MICROPROCESSORS AND MICROCONTROLLER 40
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 40
Frequency Measurement
The sinusoidal voltage signal is stepped down to the desired level using voltage transformer and then
is converted to square wave by using a zero crossing detector (ZCD).
MICROPROCESSORS AND MICROCONTROLLER 41
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 41
MICROPROCESSORS AND MICROCONTROLLER 42
K.ELAMPARI , ASSOCIATE PROFESSOR OF PHYSICS, S.T.HINDU COLLEGE, NAGERCOIL. Page 42
Ref:
https://books.google.co.in/books?id=HwuXdsnRNd4C&pg=PA517&dq=ZERO+CROSS+DETE
CTION+USING++microprocessor&hl=en&sa=X&ei=82YeVdX4BIaGuATJ-
4GwDg&ved=0CF0Q6A