Skip to main content

Generating Sine Wave Using 8085 and DAC

Strategy

Is it possible to create a beautiful sine wave using our microprocessor or microcontroller. What strategy we want to use. According to us it is possible. To generate sine wave we have to output digital equivalent values which will represent sine wave as shown in figure. Digital data 00H represents -2.5V. The 7FH represents 0V6 and FFH represents +2.5V.

The digital equivalent for sine wave can be calculated as follows. We know that sin 0°=0 and sin 90°=1. The range in 0° to 90° is distributed over digital range of 7FH to FFH i.e.,(FFH to 7FH) 128 decimal steps. Therefore taking 128 as a offset we can write digital equivalent value for sin θ =(128+128×sin ɑ). Where ɑ  is an angle in degrees which varies from -90° to +90° with a period of 5°. By changing the value of ɑ to less than 5°, you can get more accurate sine wave. Now you have to enter DATA(approximate hex code) in corresponding memory location as shown in the table below:


Address Algle(θ) Degree(ɑ) Hex code Data
(hex code
approximate)
2500 -90 0.0 00 00
2501 -85 0.48 00 01
2502 -80 1.94 01 02
2503 -75 4.36 04 04
2504 -70 7.71 08 08
2505 -65 11.99 0B 11
2506 -60 17.14 11 17
2507 -55 23.14 17 1E
2508 -50 29.94 1D 25
2509 -45 37.49 25 2D
250A -40 45.72 2E 36
250B -35 54.58 37 40
250C -30 64.00 40 49
250D -25 73.90 4A 54
250E -20 84.22 54 5E
250F -15 94.87 5F 69
2510 -10 105.77 6A 74
2511 -05 116.84 74 7F
2512 00 128.00 80 84
2513 05 139.15 8B 95
2514 10 150.20 96 9F
2515 15 161.12 A1 AF
2516 20 171.77 A6 B4
2517 25 182.09 B6 C0
2518 30 192.00 C0 C8
2519 35 201.42 C9 D0
251A 40 210.27 D2 D8
251B 45 218.50 DA E0
251C 50 226.05 E2 EA
251D 55 232.85 E8 ED
251E 60 238.85 EE EF
251F 65 244.00 F4 F2
2520 70 248.28 F8 F9
2521 75 251.63 FB FC
2522 80 254.05 FE FD
2523 85 255.51 FF FF
2524 90 256.00 100 00
Now the program can be written as below;
Address Label Mnemonic Machine code Comments
2000 MVI A,80H 3E, 80 Initializing the ports of the PPI 8255 as O/P ports by writing the control word as 80H.
2002 0UT CWR D3, Address of CWR Control word specify the I/O function for each ports of 8255.
2004 START MVI C,24H 0E, 24
2006 LXI H,2500H 21, 00, 25
2009 POS MOV A,M 7E
200A OUT PORT A D3, address of PORT A [[H-L]] is outputted through portA
200C INX H 23
200D DCR C 0D
200E JNZ POS C2, 09, 20
2011 MVI A,24H 0E, 24
2013 NEG DCX H 2B
2014 MOV A,M 7E
2015 OUT 00H D3, Address of PORT A [[H-L]] is outputted through portA.
2017 DCR C 0D
2018 JNZ NEG C2, 13, 20
201B JMP START C3, 04, 20

Note:

  • I will suggest you to use R-2R DAC(Digital to Analog Converter) for this purpose. If you are using this R-2R DAC for this purpose it is not preferred to breadboard it. You have to solder it to avoid erroneous values.

  • R-2R ladder DAC

  • Refer your manual of microprocessor trainer kit to find out address of CWR and port A

Comments

Popular posts from this blog

8051 Simple Programs

Sum of 8-bit Numbers Stored in Memory Here  we will discuss about 8051 programs but we can't discuss about all of the 8051 instructions. For programming 8051 we should know about assembler directives as well as instruction set. Click  here to download Atmel c51 user guide that will discuss about 8051(c51 family microcontroller) instruction set, assembler directives, c51 cross assembler from Atmel.  Program ORG 00H MOV R0,#50H   ; get memory location in memory pointer R0 MOV R1,#51H   ; get memory location on memory pointer register R1 MOV A,@R0       ; get content of memory location 50H to accumulator ADD A,@R1        ; add content of A with content of memory location 51H and store result in A MOV R0,#52H    ; get 52H to memory pointer R0 MOV@R0,A         ; copy content of A to memory location 52H END Add 16-bit Numbers ...

Even and Odd Memory Banks

The 8086 microprocessor uses a 20-bit address to access memory. With 20-bit address the processor can generate 2 20 = 1 Mega address. The basic memory word size of the memories used in the 8086 system is 8-bit or 1-byte (i.e., in one memory location an 8-bit binary information can be stored). Hence, the physical memory space of the 8086 is 1Mb (1 Mega-byte). For the programmer, the 8086 memory address space is a sequence of one mega-byte in which one location stores an 8-bit binary code/data and two consecutive locations store 16-bit binary code/data. But physically (i.e., in the hardware), the 1Mb memory space is divided into two banks of 512kb (512kb + 512kb = 1Mb). The two memory banks are called Even (or Lower) bank and Odd (or Upper) bank. The organization of even and odd memory banks in the 8086-based system is shown in Figure. The 8086-based system will have two sets of memory IC's. One set for even bank and another set for odd bank. The data lines D 0 -D 7 are conne...

Hex file generation using Keil

Keil μvision is an Integrated Development Tool(IDE) to write, simulate and flash our program written either in assembly language or in C. We can also flash our program to mcs51 series(8051 family) microcontroller using Keil μvision IDE. But I will prefer you to use Flashmagic developed by NXP to flash your program into 89c51(I am emphasize that 8051 has no flash memory. But we can use other microcontrollers that are code compatible with 8051 like 89c51 from Atmel or 89c51RD2BN from NXP etc.). But we want to familiar with Keil μvision to generate hex files from our embedded C programs. You want to click here to download latest version of Keil μvision. This will redirect you to official website of Keil. You must fill the form before download Keil. The Keil μvision IDE setup file has more than 100 Mb in size. After downloading this setup file double click on it and install it. During installation this may ask your e-mail ID and lot of things. If you want notif...