Professional Documents
Culture Documents
Function Generation Report
Function Generation Report
Function Generation 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
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.
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
2708
FF800H
FFFFFH
00000H
007FFH
00800H
00FFFH
6116
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
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.
O1
O2
O3
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.
Software Implementation
Assumptions
The following assumptions were made in order to develop the software for the system.
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.
.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
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
.exit
jz tri
cmp al, BFh
jz square
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
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
sinout:
mov ch, 0Ch
out 86h, ch
mov ch, 0Eh
out 86h, ch
jmp finish
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
iret