Q) Generate a Half Rectified Sine wave from using the DAC interface. (The output of the DAC is to be displayed on the CRO)
This program will display a half rectified sine wave on CRO device using DAC interface.
Algorithm:
Calculate table values using the formula table[i]=127+127SinÓ¨ (Equation to generate sine wave) where Ó¨ ranges from 0 to 180 in steps of 6 degree.
Step 1: Initialize the control word 80H and store it in the control register.
Step 2: Initialize the Port A address and initialize the counter to 31(total number of elements in table).
Step 3: For (i=0 to31)
Out-port(Port A, Table[i]) ; /*will get +ve half cycle of sine wave
For (i=0 to 31)
Out-port(Port A, 127]) ;/*will get –ve half cycle of sine wave
Step 4: Stop.
CODE:
Step 1: Initialize the control word 80H and store it in the control register.
Step 2: Initialize the Port A address and initialize the counter to 31(total number of elements in table).
Step 3: For (i=0 to31)
Out-port(Port A, Table[i]) ; /*will get +ve half cycle of sine wave
For (i=0 to 31)
Out-port(Port A, 127]) ;/*will get –ve half cycle of sine wave
Step 4: Stop.
CODE:
Explanation:
.MODEL SMALL
.DATA
PA EQU 0e800H
PB EQU 0e801H
PC EQU 0e802H
CR EQU 0e803H
CW DB 80H
TABLE DB 127,140,153,166,178,190,201,212
DB 221,229,236,243,247,251,253,254
DB 253,251,247,243,243,236,229,221
DB 212,201,190,178,166,153,140,127
One data and one code segment.
Data segment with the required memory locations.
All port addresses are stored in appropriate locations. Control word, which is 80H is stored in CW.
Required sine wave values are calculated using the formula,
127+127sin(x) where x is the angles between 0 degree and 180 degree.(take some 20 values with equal intervals=6 degree)
For example,
Take degree x=0.
Calculate the formula result 127+127sin0=127.(A scientific calculator may help in table value calculation. (DONT BY HEART THE VALUES. Calculate it)
Data segment with the required memory locations.
All port addresses are stored in appropriate locations. Control word, which is 80H is stored in CW.
Required sine wave values are calculated using the formula,
127+127sin(x) where x is the angles between 0 degree and 180 degree.(take some 20 values with equal intervals=6 degree)
For example,
Take degree x=0.
Calculate the formula result 127+127sin0=127.(A scientific calculator may help in table value calculation. (DONT BY HEART THE VALUES. Calculate it)
.CODECode segment is started and data segment is initialized. Control word is loaded into AL, Control register address is loaded into DX, and ports are activated using OUT DX,AL instruction.
MOV AX,@DATA
MOV DS,AX
MOV AL,CW
MOV DX,CR
OUT DX,AL
MOV DX,PA
NEXTCYCLE:
LEA SI,TABLE
MOV CX,31D
Output port address PA is moved to DX.
NEXT_CYCLE is a label.
Offset of TABLE is stored in SI and counter is set to 31 since there are 32 values to be displayed in the CRO for the wave.
NEXT_ANGLE:
MOV AL,[SI]
OUT DX,AL
INC SI
LOOP NEXT_ANGLE
NEXT_ANGLE is a label.
Move the content of SI location into AL for displaying and display it using OUT command.
Increment SI to point to next location.
Call LOOP to jump to NEXT_ANGLE by decreasing CX by 1 and if CX not equal to 0, jump.(will execute 32 times displaying each value of table on CRO as a wave point)
First half is displayed. Now we need to display a single reference line for the next half cycle. This is done by displaying 127 (value of x axis point of the sine wave) for the next 32 times.
MOV CX,31D
MOV AL,127D
REFLINE:OUT DX,AL
LOOP REFLINE
JMP NEXT_CYCLE
Counter set to 31D. (to run for 32 times).
AL is loaded with 127 as said above.
REFLINE is a label.
AL is displayed on CRO using OUT command.
Then LOOP back to REFLINE.
This will display 127 on CRO for 32 times, which makes the cycle rectified.
After 32 iterations, we need to display the next positive half cycle. Go to NEXT_CYCLE unconditionally.
AL is loaded with 127 as said above.
REFLINE is a label.
AL is displayed on CRO using OUT command.
Then LOOP back to REFLINE.
This will display 127 on CRO for 32 times, which makes the cycle rectified.
After 32 iterations, we need to display the next positive half cycle. Go to NEXT_CYCLE unconditionally.
MOV AH,4CH
INT 21H
END
Terminate using 4CH and INT 21H. This program wont actually terminate as it is infinite displaying of wave (infinite loop).
END represents end of code.
Output:
Seen in CRO.
Seen in CRO.
Share your views about this article!