11b. Fully rectified sine wave in CRO using DAC interface

vtu mp 11b
Q) Generate a Fully Rectified Sine wave form using the DAC interface (The output of the DAC is to be displayed on a CRO).
This program will display a fully rectified sine wave on CRO device using a 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
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)

Now the positive half cycle is displayed on CRO. Since this is fully rectified sine wave, you need to display the same above cycle for the next coming cycles. So see below,

LEA SI,TABLE
MOV CX,31D
JMP NEXT_ANGLE

Again load SI with TABLE’s offset and counter with 31D.
Jump unconditionally to NEXT_ANGLE to display same cycle again and again.

MOV AH,4CH
INT 21H
END

Finally terminate using 4CH and INT 21H.
END represents end of 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!