9b. Sine wave on CRO using DAC interface

vtu mp 9b
Q) Generate the Sine Wave using DAC interface. (The output of the DAC is to be displayed on the CRO).

This program will display a sine wave on the 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, -table[i])    ;/*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)

.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,CW
MOV DX,CR
OUT DX,AL

Code 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 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)

This will display the positive half cycle. Now you need to display the same cycle with negative value of AL.( for negative half cycle).

LEA SI,TABLE
MOV CX,31D
NEXT_ANGLE1:
MOV AL,[SI]
NOT AL
OUT DX,AL
INC SI
LOOP NEXT_ANGLE1
JMP NEXT_CYCLE

Load SI with table again and CX with 31D.
Perform the previous snippet again but this time with the negative AL. (observe NOT AL which is used to negate the AL value in this snippet).
After displaying positive and negative half cycles in CRO, next cycle needs to be displayed. So call JMP to jump to NEXT_CYCLE unconditionally.

MOV AH,4CH
INT 21H
END

Finally, terminate using AH,4CH and INT 21H
And end the code
Output:
Seen in CRO.

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

Share your views about this article!