You are on page 1of 5

ECU391

MICROPROCESSORS AND MICROCONTROLLERS LAB

Experiment Number: 1 Date: : 04/08/2010

ADC and DAC Interfacing


Aim:

1. 2. 3. 4.

Use ADC to measure a dc voltage at any pin of the ADC and get a digital output. Use DAC, to generate a triangular waveform of T=10 m sec Using DAC, generate a ramp waveform with T=10 m sec Using DAC, generate a staircase waveform with 6 steps and each step is 0.5 m sec

Submitted by Sarath A Y B080229EC S5 ECE, Batch: B

Program 1: Triangular waveform of T=5 m sec using DAC


DAC used: 0800 Program: .MODEL SMALL .CODE .STARTUP ORG 1000H START: MOV AL,00H ;small model

;code starts from 1000H ;moving lowest value of wave to al ;sending value of al to output port ;calling a delay procedure to hold the value of al at ;the output port to get the required delay ;incrementing value of al to get increasing portion ;of wave ;compare al with FF(255) ;if al FF, jump to 'up' and continue the loop ;sending value of al to output port ;calling a delay procedure to hold the value of al at ;the output port to get the required delay ;incrementing value of al to get decreasing portion ;of wave ;compare al with 0 ;if al 00h, jump to 'down' and continue the loop ;jump to 'start' and repeat the whole process ;procedure for creating required delay ;store the required value to cx ;stay in this location for cx times ;return from procedure to main program ;end of procedure ;end of program

;loop to get increasing portion of the wave UP: OUT 0C8H,AL CALL DELAY INC AL CMP AL,0FFH JNZ UP ;loop to get decreasing portion of the wave DOWN: OUT 0C8H,AL CALL DELAY DEC AL CMP AL,0H JNZ DOWN JMP START DELAY PROC NEAR MOV CX,04H HERE:LOOP HERE RET DELAY ENDP .EXIT END Delay Calculations: Required time period of wave=10 ms Half time period = 5ms Clock frequency of 8086 processor = 4.77 MHz Duration of one clock cycle = 1/(4.77*10^6)

= 0.209 sec Number of machine cycles for the instructions are: LOOP: 17 MOV: 4 CMP: 9 JNZ: 16 INC: 2 Total delay= (4+17.N +2+9+16).255 * 0.209 sec = 5 m sec Solving , N=4 Waveform:

Program 2 : Ramp waveform with T=10 m sec using DAC


DAC Used: 0800 Program: .MODEL SMALL .CODE .STARTUP ORG 1000H START: MOV AL,00H ;small model

;code starts from 1000H ;moving lowest value of wave to al ;sending value of al to output port ;calling a delay procedure to hold the value of al at ;the output port to get the required delay ;incrementing value of al to get increasing portion ;of wave ;compare al with FF(255) ;if al FF, jump to 'up' and continue the loop ;procedure for creating required delay ;store the required value to cx ;stay in this location for cx times ;return from procedure to main program ;end of procedure ;end of program

;loop to get increasing portion of the wave RAMP: OUT 0C8H,AL CALL DELAY INC AL CMP AL,0FFH JNZ RAMP JMP START DELAY PROC NEAR MOV CX,04H HERE:LOOP HERE RET DELAY ENDP .EXIT END

Delay Calculation Required time period of wave = 10ms Total delay = (4+17N+2+9+16)*255*(0.209 u sec) = 10 m sec

solving, N=9 Waveform:

Program 3: Staircase waveform with 6 steps and each step is 0.5 m sec using DAC
DAC used: 0800 Program: .MODEL SMALL .CODE .STARTUP ORG 1000H START: L1: MOV AL,00H OUT 0C8H,AL CALL DELAY ADD AL,42H CMP AL,252 JNZ L1 JMP START DELAY PROC NEAR MOV CX,8AH HERE:LOOP HERE RET DELAY ENDP .EXIT END Delay Calculation Delay required for one step = 0.5m sec Delay = (4+17N + 4+9+19)*0.209 u sec = 0.5 m sec solving, N= 138 =8A H Waveform: ;procedure for creating required delay ;store the required value to cx ;stay in this location for cx times ;return from procedure to main program ;end of procedure ;end of program ;small model

;code starts from 1000H ;moving lowest value of wave to al ;sending value of al to output port ;calling a delay procedure to hold the value of al at ;the output port to get the required delay ;increment al by 42 ;compare al with 252(after 6 times, al becomes 252 ; 6*42 =252) ;if al 255, jump to 'L1' and continue the loop

Program 4:Use ADC to measure a dc voltage at any pin of the ADC and get a digital output.
ADC Used: 0809 Program: .MODEL SMALL .CODE .STARTUP ORG 1000H MOV AL,10H OUT 0C8H,AL MOV AL,18H OUT 0C8H,AL MOV AL,01 OUT ODOH,AL MOV AL,00 MOV AL,00 MOV AL,00 MOV AL,00 OUT ODOH,AL IN AL,0D8H AND AL,01H CMP AL,01H JNZ L1 IN AL,0C0H MOV BX,1200H MOV [BX],AX ;small model

;code starts from 1000H ;select adc channel ;send al value to ALE ;sending ale high to start ;sending start of conversion signal ;delay given to adc to get digital value

L1:

;make soc signal low ;checking for end of conversion ;continue checking for end of conversion ;read analog data from channel 1 ;store the result in 1200H

.EXIT END

You might also like