maddy_nish

12-02-2010, 10:45 AM

Hi,

I have a doubt about creating an approx sine wave of 50hz with AVR micro,,, Here is the skeleton code please correct me if im wrong..

In the below code im trying to use a 8 bit PWM output, changing the duty cycle according to the value of sine. The Else statement alone will loop for 20 times till x value becomes 2. Hence dealy of 1 ms eact time will be a total delay of 20ms to complete one cycle of sine wave which will produce o frequency of 50Hz. Since the dudty cycle changes with sine i assume that the power output across a resistor connected between OCR output pin and ground will vary according to 50Hz sine wave.

while(1)

{

if(x==2)

{

x=0;

}

else

{

x=x+.1;

OCR1A=255*sin(3.142*x); 8 Bit PWM

delay(1); //Delay in milli seconds

}

} //End of main while

I have a doubt about creating an approx sine wave of 50hz with AVR micro,,, Here is the skeleton code please correct me if im wrong..

In the below code im trying to use a 8 bit PWM output, changing the duty cycle according to the value of sine. The Else statement alone will loop for 20 times till x value becomes 2. Hence dealy of 1 ms eact time will be a total delay of 20ms to complete one cycle of sine wave which will produce o frequency of 50Hz. Since the dudty cycle changes with sine i assume that the power output across a resistor connected between OCR output pin and ground will vary according to 50Hz sine wave.

while(1)

{

if(x==2)

{

x=0;

}

else

{

x=x+.1;

OCR1A=255*sin(3.142*x); 8 Bit PWM

delay(1); //Delay in milli seconds

}

} //End of main while