Function Generation Report

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

ES C263: Microprocessor Programming & Interfacing

Design Assignment Report

By

Nikhil R
Sharva Kant
R Srinivas
K Pavan Kumar Reddy

2007A8PS028P
2007A8PS029P
2007A8PS030P
2007A8PS035P

Group No: 58

April 2009
Birla Institute of Technology & Science, Pilani

Table of Contents

Problem Statement .................................................................................................................... 2


Hardware Devices Used ............................................................................................................. 3
System Description .................................................................................................................... 4
Microprocessor ...................................................................................................................... 4
Memory.................................................................................................................................. 4
I/O Interfacing Using 8255 ..................................................................................................... 5
I/O Map For 8255 ................................................................................................................... 5
Switches ................................................................................................................................. 6
4 Digit, 7-Segment LED display .............................................................................................. 6
DAC Controlled Function Generator ...................................................................................... 7
Software Implementation .......................................................................................................... 9
Assumptions ........................................................................................................................... 9
Algorithm ............................................................................................................................. 10
Assembly Level Program of complete implementation ...................................................... 11

1 | MuP Design Assignment

Problem Statement

Problem (P17): Frequency Generation


Description: This system is used to generate a Sine/ Triangular/ Square waveform of
Frequencies ranging from 10 Hz to 99 KHz. Voltage is between 0-10V.

Tri

SIne

Square

10
100

O/P
Generate

1K
10K

Sample Operation Algorithm: To generate a Square waveform of frequency 94.35 KHz, the
user has to press Square, followed by 10K Key 9 times; 1K Key 4, times; 100 Key, 3 times
and 10 Key, 5 times.
When Generate is pressed, the square waveform of that frequency will be generated. If the
user wants to change the waveform into a sinusoidal one, he just has to press Sine.

2 | MuP Design Assignment

Hardware Devices Used


1. INTEL 8086
: Microprocessor
2. Crystal
: 4 MHz Crystal
3. 74LS373 (3)
: 8-bit address latches- address bus
4. 74LS244
: 3-state buffer- control bus
5. 74LS245 (2)
: 8-bit data buffers- data bus
6. 2708 (2)
: 1K, 8 bit EPROM
7. 6116 (2)
: 2K, 8 bit SRAM
8. 82C55
: Programmable Peripheral Interface
9. DAC0830
: 8-Bit P Compatible, Double-Buffered D to A Converters
10. LMH74153
: 4:1 MUX
11. Gates
: AND, NAND & OR gates.
12. Push Buttons (8)
: For inputs
13. 4- Digit 7-Segment Display
14. 7447
: BCD to 7-Segment Converter.
15. LM392, LM394, LF351, 2N3810
: Oscillators and transistors for function
generation circuit

3 | MuP Design Assignment

System Description
This Microprocessor based Function Generator consists of the following broad subsystems.

Microprocessor
Memory
o ROM
o RAM
I/O Devices Interfaced to a Programmable Peripheral Interface
o Switches
o 4 Digit, 7-Segment LED display
o DAC controlled function generator

Microprocessor
The system utilizes a standard INTEL 8086 microprocessor. The microprocessor runs on
4MHz crystal.

Memory
The memory consists of 2KB of EPROM to store the code and 4KB of SRAM to store data
during the execution. The address maps for the memory are as below.

Device

A 1 9 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

2708
FF800H

FFFFFH

00000H

007FFH

00800H

00FFFH

6116

4 | MuP Design Assignment

I/O Interfacing Using 8255


A programmable peripheral interface (8255) is used to interface all input and output devices
to the microprocessor.

I/O Map For 8255


Base Address: 80H
Its is I/O mapped I/O System
The addresses of the ports are as follows:

PORT of 8255
PORT A
PORT B
PORT C
Control Register

Address
80H
82H
84H
86H

Data lines: D0-D7 data lines of the microprocessor (as it is connected in even bank)
Port Specification:
Group A: Mode 0
Group B: Mode 0

Port A: Input
Port B: Output
Port C: Output

Hence, the control word is


1

or 90H, which is written to the control register.


5 | MuP Design Assignment

Port A is used for the input. The 8 input buttons are connected to the 8 pins of PORT A
through a resistor and grounded.
Port B is used to give the data (regarding frequency) to the DAC.
PORT C: 2 pins are required to select the appropriate output waveform. Two pins are
required to select one of the four seven-segment displays at a time to display by scanning.
By setting and resetting the pins using Bit Set Reset (BSR), this can be achieved. The
remaining four bits of PORT C is used to give the BCD number to be displayed on the LED
display.

Address Map
Hex

A15 A 1 4 A 1 3 A 1 2 A 1 1 A 1 0 A 9 A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 A 0

0080H
0082H
0084H
0086H

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

1
1
1
1

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
1
1

0
1
0
1

0
0
0
0

Switches
We need 8 buttons to select the following functions: 10 Hz, 100 Hz, 1 KHz, 10 KHz, Sine, Tri,
Square & Generate. This is implemented by using 8 push buttons, one each attached to the
8 pins of PORT A in 8255. The buttons are so connected through a resistor and ground, such
that on press, the corresponding pin is pulled down to a Logic Low. All lines from the input
port are NANDed together and connected to the external interrupt INTR of the
microprocessor. The service routine for INTR has been interfaced at FFh.

4 Digit, 7-Segment LED display


The frequency typed by the user is displayed on 4-Digit, 7-Segment LED display. The four
digits are displayed by the process of Scanning in which only one of displays is lit at a time.
The digits to be displayed are displayed in each display for a short period of time (~ 2ms)
and the entire process is repeated over and over again to give an impression of static display
(due to persistence of vision)
PC0- PC3 of 8255 is used to give a BCD value to a BCD to 7-Segment converter IC (7447). The
pins PC4 & PC5 are used to select on of the four displays at any point of time.

6 | MuP Design Assignment

DAC Controlled Function Generator


This microprocessor based function generation system utilizes a Digital to Analog Converter
(DAC) to control the frequency of the output waveforms which could be either sine,
triangular or square wave form. The DAC controlled function generator circuit shown below
generates the three types of waves depending on the frequency fed to the DAC in the form
of an 8-bit representation.

O1

O2
O3

7 | MuP Design Assignment

If D is the data sent to the DAC, the frequency of signal received in the output is given by

where C, the value of capacitance was found to be 0.5 nF for the current purpose.

The circuit has 3 outputs, O1, O2 & O3. Depending on the form of the wave selected by the
user, one of three outputs is selected using a multiplexer.
The pins PC6 & PC7 are used to select the required output signal and provide the output.
This is done using a 4:1 MUX.

8 | MuP Design Assignment

Software Implementation
Assumptions
The following assumptions were made in order to develop the software for the system.

At the location FFFF0H, where the instruction pointer points on RESET of


microprocessor, there exists a JUMP statement leading to the start of the code.
The user gives sufficient time between two successive key presses, enough to
perform all operations associated with a particular key press. The software however
is designed to handle debounce.
The user can only increase the frequency and never decrease. If he/she requires a
lower value of frequency, the system needs to shut down and restarted.
The maximum frequency of signal to be generated s 99.99 khz and user does not
enter anything above this value.
The interrupt vector corresponding to external interrupt is FFh and is supplied to the
microprocessor externally.

9 | MuP Design Assignment

Algorithm
1. The frequency to be input from the user is stored as a 4-digit BCD value in memory.
The form type as well as the data to be sent to DAC is also stored in the memory. All
the values are initially zero.
2. The processor now continuously displays the 4 digit BCD value stored in memory on
the 7-segment LED displays by the process of scanning. This display is made inside an
infinite loop.
3. On key press, the external interrupt is triggered and the corresponding interrupt
service routine (ISR) at FFh is called.
4. In the ISR, the value of PORTA of 8255 is Input and compared with values to
determine which key has been pressed.
a. If the key was any of the multiplier keys, the frequency stored in the memory
is correspondingly multiplied.
b. If the key was a form selector key, the form in the memory is correspondingly
updated.
c. If the key was the Generate Key, then the frequency in memory is converted
to the 8-bit equivalent to be sent to the DAC, the value is Output to PORTB of
8255 and the pins PC6 & PC7 are set/reset based on the form factor.
The control is returned back to the mainline program after a debounce period,
where the frequency continues to be displayed while the output remains as the
required signal as the outputs in 8255 are latched.

10 | MuP Design Assignment

Assembly Level Program of complete implementation


.model small
.data
frequency dw 0000h
form db 00h
dacdata db 00h

.code
.startup
;initializing the PPI
mov al, 90h
OUT 86h, al
;initializing the data to DAC and waveform to 0
mov al, 00h
out 82h, al
;PORT B is set to 0
out 84h, al
;PORT c is set to 0

loop:
mov ax, frequency
;isolating each digit of the BCD frequency
mov cx, 04h
mov bx, ax
shl ah, cx
and bh, 0Fh
shl al, cx
and bl, 0Fh
;ah, bh, al, bl now have the four digits in the same order

; outputting the frequency to 7-segment LED display by method of scanning


out 84h, ah ;sets the first 4 bits of PORT C to the value contained in ah (first digit)
mov ch, 08h ;BSR control word to reset 4th bit
out 86h, ch
mov ch, 0Ah ;BSR control word to reset 5th bit
out 86h, ch
CALL delay

11 | MuP Design Assignment

out 84h, bh ;sets the first 4 bits of PORT C to the value contained in bh (second digit)
mov ch, 09h ;BSR control word to set 4th bit
out 86h, ch
mov ch, 0Ah ;BSR control word to reset 5th bit
out 86h, ch
CALL delay
out 84h, al
mov ch, 08h
out 86h, ch
mov ch, 0Bh
out 86h, ch
CALL delay

;sets the first 4 bits of PORT C to the value contained in al (third digit)
;BSR control word to reset 4th bit

out 84h, bl
mov ch, 09h
out 86h, ch
mov ch, 0Bh
out 86h, ch
CALL delay

;sets the first 4 bits of PORT C to the value contained in bl (fourth digit)
;BSR control word to set 4th bit

jmp loop

;cause the display to happen in an infinite loop

;BSR control word to set 5th bit

;BSR control word to set 5th bit

.exit

; external interrupt service routine


isr(int FFh)
in al, 80h
cmp al, FEh
jz ten

;chk if the 10 button was pressed

cmp al, FDh


jz hundred

;chk if the 100 button was pressed

cmp al, FBh


jz onek

;chk if the 1K button was pressed

cmp al, F7h


jz tenk

;chk if the 10K button was pressed

cmp al, EFh


jz sine

;chk if the sine button was pressed

cmp al, DFh

;chk if the tri button was pressed

12 | MuP Design Assignment

jz tri
cmp al, BFh
jz square

;chk if the square button was pressed

cmp al, 7Fh


jz generate

;chk if the generate button was pressed

ten:
;adds 10 hertz to frequency
mov bx, frequency
add bl, 01h
mov frequency, bx
jmp finish
hundred:
;adds 100 hertz to frequency
mov bx, frequency
add bl, 10h
mov frequency, bx
jmp finish
onek:
;adds 1K hertz to frequency
mov bx, frequency
add bh, 01h
mov frequency, bx
jmp finish
tenk:
;adds 10K hertz to frequency
mov bx, frequency
add bh, 10h
mov frequency, bx
jmp finish

sine:
;sets the form byte to 00h if the sine button was pressed
mov form, 00h
jmp finish
tri:
;sets the form byte to 01h if the tri button was pressed
mov form, 01h
jmp finish
square:
mov form, 02h
jmp finish

;sets the form byte to 02h if the square button was pressed

13 | MuP Design Assignment

generate:
;performs necessary computations to calculate D to DAC, sets the o/p select,
outs the D to DAC
mov ax, frequency
;unpacking BCD and converting to binary
mov bl, al
and bl, 0Fh
mov cl, 04h
shr al, cl
mov bh, al
mov dl, ah
and dl, 0Fh
mov cl, 04h
shr ah, cl
mov dh, al
mov al, 10
mul bh
add ax, bl
mov bx, ax
mov al, 100
mul dl
add bx, ax
mov al, 1000
mul dh
add bx, ax
;bx has the frequency*100 stored in it
mov ax, 256
mul bx
mov cx, 10000
div cx
;now ax has a value between 0-255 corresponding to the frequency
out 82h, al

; outs the frequency to the DAC and latches it

cmp form, 00h


jz sineout
cmp form, 01h
jz triout
14 | MuP Design Assignment

cmp form, 10h


jz squareout

sinout:
mov ch, 0Ch
out 86h, ch
mov ch, 0Eh
out 86h, ch
jmp finish

;reset 6th and 7th bit so that sine way is selected


;BSR control word to reset 6th bit
;BSR control word to reset 7th bit

triout:
;set 6th and reset 7th bit so that tri way is selected
mov ch, 0Dh ;BSR control word to set 6th bit
out 86h, ch
mov ch, 0Eh ;BSR control word to reset 7th bit
out 86h, ch
jmp finish
squareout:
mov ch, 0Ch
out 86h, ch
mov ch, 0Fh
out 86h, ch
jmp finish

finish:
call DELAY

;reset 6th and set 7th bit so that tri way is selected
;BSR control word to reset 6th bit
;BSR control word to set 7th bit

;to ensure debounce is taken care of

iret

DELAY proc near


pushf
mov cx, 435
X1:
NOP
NOP
loop X1
ret
DELAY endp
end

; gives a delay of about 2ms

15 | MuP Design Assignment

You might also like