function-generation-report

download function-generation-report

of 16

Transcript of function-generation-report

  • 8/14/2019 function-generation-report

    1/16

    ES C263: Microprocessor Programming & Interfacing

    Design Assignment Report

    By

    Nikhil R 2007A8PS028P

    Sharva Kant 2007A8PS029P

    R Srinivas 2007A8PS030PK Pavan Kumar Reddy 2007A8PS035P

    Group No: 58

    April 2009

    Birla Institute of Technology & Science, Pilani

  • 8/14/2019 function-generation-report

    2/16

    1 | MuP Design Assignment

    Table of Contents

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

    Hardware Devices Used ............................................................................................................. 3

    System Description .................................................................................................................... 4

    Microprocessor ...................................................................................................................... 4

    Memory .................................................................................................................................. 4I/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

  • 8/14/2019 function-generation-report

    3/16

    2 | 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.

    Sample Operation Algorithm: To generate a Square waveform of frequency 94.35 KHz, the

    user has to press Square, followed by 10K Key9 times; 1K Key4, times; 100 Key, 3 times

    and 10 Key, 5 times.

    When Generateis pressed, the square waveform of that frequency will be generated. If theuser wants to change the waveform into a sinusoidal one, he just has to press Sine.

    SIne Tri Square

    10K

    1K

    100

    10

    Generate

    O/P

  • 8/14/2019 function-generation-report

    4/16

    3 | MuP Design Assignment

    Hardware Devices Used

    1. INTEL 8086 : Microprocessor2. Crystal : 4 MHz Crystal3. 74LS373 (3) : 8-bit address latches- address bus4. 74LS244 : 3-state buffer- control bus5. 74LS245 (2) : 8-bit data buffers- data bus6. 2708 (2) : 1K, 8 bit EPROM7. 6116 (2) : 2K, 8 bit SRAM8. 82C55 : Programmable Peripheral Interface9. DAC0830 : 8-Bit P Compatible, Double-Buffered D to A Converters10. LMH74153 : 4:1 MUX11.Gates : AND, NAND & OR gates.12.Push Buttons (8) : For inputs13. 4- Digit 7-Segment Display14.7447 : BCD to 7-Segment Converter.15.LM392, LM394, LF351, 2N3810 : Oscillators and transistors for function

    generation circuit

  • 8/14/2019 function-generation-report

    5/16

    4 | MuP Design Assignment

    System Description

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

    Microprocessor Memory

    o ROMo RAM

    I/O Devices Interfaced to a Programmable Peripheral Interfaceo Switcheso 4 Digit, 7-Segment LED displayo 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 A1 9 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

    2708

    FF800H 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0

    FFFFFH 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

    6116

    00000H 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    007FFH 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1

    00800H 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0

    00FFFH 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1

  • 8/14/2019 function-generation-report

    6/16

    5 | 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 Address

    PORT A 80H

    PORT B 82H

    PORT C 84H

    Control Register 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 0 0 1 0 0 0 0

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

  • 8/14/2019 function-generation-report

    7/16

    6 | MuP Design Assignment

    Port Ais used for the input. The 8 input buttons are connected to the 8 pins of PORT A

    through a resistor and grounded.

    Port Bis used to give the data (regarding frequency) to the DAC.

    PORT C: 2 pins are required to select the appropriate output waveform. Two pins arerequired 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 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0

    0082H 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0

    0084H 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0

    0086H 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 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- PC3of 8255 is used to give a BCD value to a BCD to 7-Segment converter IC (7447). The

    pins PC4 & PC5are used to select on of the four displays at any point of time.

  • 8/14/2019 function-generation-report

    8/16

  • 8/14/2019 function-generation-report

    9/16

    8 | 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 & PC7are used to select the required output signal and provide the output.

    This is done using a 4:1 MUX.

  • 8/14/2019 function-generation-report

    10/16

    9 | 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 ofmicroprocessor, there exists a JUMP statement leading to the start of the code.

    The user gives sufficient time between two successive key presses, enough toperform 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 alower 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 notenter anything above this value.

    The interrupt vector corresponding to external interrupt is FFh and is supplied to themicroprocessor externally.

  • 8/14/2019 function-generation-report

    11/16

    10 | 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 onthe 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 interruptservice routine (ISR) at FFh is called.

    4. In the ISR, the value of PORTA of 8255 is Input and compared with values todetermine which key has been pressed.

    a. If the key was any of the multiplier keys, the frequency stored in the memoryis correspondingly multiplied.

    b. If the key was a form selector key, the form in the memory is correspondinglyupdated.

    c. If the key was the Generate Key, then the frequency in memory is convertedto 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.

  • 8/14/2019 function-generation-report

    12/16

    11 | 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

  • 8/14/2019 function-generation-report

    13/16

    12 | 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 ;sets the first 4 bits of PORT C to the value contained in al (third digit)

    mov ch, 08h ;BSR control word to reset 4th bit

    out 86h, ch

    mov ch, 0Bh ;BSR control word to set 5th bit

    out 86h, ch

    CALL delay

    out 84h, bl ;sets the first 4 bits of PORT C to the value contained in bl (fourth digit)

    mov ch, 09h ;BSR control word to set 4th bitout 86h, ch

    mov ch, 0Bh ;BSR control word to set 5th bit

    out 86h, ch

    CALL delay

    jmp loop ;cause the display to happen in an infinite loop

    .exit

    ; external interrupt service routine

    isr(int FFh)

    in al, 80h

    cmp al, FEh ;chk if the 10 button was pressed

    jz ten

    cmp al, FDh ;chk if the 100 button was pressed

    jz hundred

    cmp al, FBh ;chk if the 1K button was pressed

    jz onek

    cmp al, F7h ;chk if the 10K button was pressed

    jz tenk

    cmp al, EFh ;chk if the sine button was pressed

    jz sine

    cmp al, DFh ;chk if the tri button was pressed

  • 8/14/2019 function-generation-report

    14/16

    13 | MuP Design Assignment

    jz tri

    cmp al, BFh ;chk if the square button was pressed

    jz square

    cmp al, 7Fh ;chk if the generate button was pressed

    jz generate

    ten: ;adds 10 hertz to frequency

    mov bx, frequency

    add bl, 01h

    mov frequency, bx

    jmp finish

    hundred: ;adds 100 hertz to frequencymov 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, 00hjmp finish

    tri: ;sets the form byte to 01h if the tri button was pressed

    mov form, 01h

    jmp finish

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

    mov form, 02h

    jmp finish

  • 8/14/2019 function-generation-report

    15/16

    14 | 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, clmov 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, 10000div 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, 01hjz triout

  • 8/14/2019 function-generation-report

    16/16