Sine Wave Generation Using 8051

SOFTWARE: KEIL MICRO VISION 4

SIMULATOR: KEIL MICRO VISION 4

PROGRAM:

#include<reg51.h>

void delay(void);

int a[]={128,164,196,221,240,251,255,255,251,240,221,196,164,128,100,87,62,53,45,45,53,62,87,100};

/*
255=sin 90
251=sin80
240=sin 70
221=sin 60
196=sin 50
164=sin 40
128=sin 30
100= sin 23
87=sin 20
62=sin 14
53=sin 12
45=sin10

*/

void main()

int j;

while(1)
{

for(j=0;j<24;j++)
{

P1=a[j];         // send sine values to port 1

delay();


}

}


void delay(void)
{

int r;

for(r=0;r<1275;r++);


}


PROGRAM DESCRIPTION:

I have generated sine wave on Port 1 of 8051.I have send the value to Port 1 as per the below calculation.After sending the each value,I have provided some delay.

Calculation of sine wave values:

Here in 8051,we know that all the ports are 8 bit ports.Hence any port can take the values ranging from 0 to 255 only.
Therefore,255 is the maximum value and 0 is the minimum value 
any port can take.
Maximum value is equivalent to logic 1 and Minimum value is equivalent to logic 0.
We know that sine 90 is equal to 1.So according to the logic mentioned above sine 90=255.For calculating the values for other sine degrees we need to calculate the value of x.
  • sin 90=255 ; sin y=x
  • After doing cross multiplication: x=sin y *255/sin 90
  • x=sin y*255;
  • Supposed here y=10,Then value of x become:
  • x=sin 10*(255)=0.173*255=44.280=45

Accordingly,I have calculated each sine value for other degrees.Here I have first started with 128 which is equivalent to half of 255.I have send the values from 128 so that proper sine wave get generated.
For getting the more accurate sine wave,we need to send more sine values to port 1.


VIDEO:




























Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

To display custom characters on the lcd using 8051 micro-controller.