# Generating sine wave using PWM method

Status
Not open for further replies.

#### Maverickmax

generate sin wave with pwm

Hi

So far I understand to generate sine wave look-up table. Now I need to know how to create algorithm to use the table with PWM in order to produce sine wave.

Any good tutorial or link for me to develop my understanding on this area?

Maverick Max

generating sine wave

Maverick Max

The PWM period must be much shorter than the sine wave period. Let's say for example, the PWM period is 256 counts and there are 36 PWM periods over a sine wave period (each PWM period is 2*pi/36 radians or 10 degrees).

Let's say that at a value of zero, we are using a PWM period of 50%. Negative one is 0% and positive one is 100%.

For each PWM period, you use the sine table to determine what your duty cycle should be. For sin(0), PWM = 50%, count=128. For sin(2*pi/36), PWM = 59%, count=151, for sin(2*pi*2/36), PWM = 67%, count=171, etc.

So your output is high for 128, low for 128, high for 151, low for 256-151=105, high for 171, low for 85, etc. throughout the period of the sinewave.

Basically, all you do is compare a counter to the appropriate value in your table. The result of the comparison yields the state of your output.

• sebinphilip

V
Points: 2
V
Points: 2

### sebinphilip

Points: 2
generate sine wave using look up table software

hi,

pfa an apllication note for avr mcu to generate DTMF using PWM. this should tell you how to generate sine wave usin PWM.

lm555 sinewave

jonw0224 said:
Maverick Max

The PWM period must be much shorter than the sine wave period. Let's say for example, the PWM period is 256 counts and there are 36 PWM periods over a sine wave period (each PWM period is 2*pi/36 radians or 10 degrees).

Let's say that at a value of zero, we are using a PWM period of 50%. Negative one is 0% and positive one is 100%.

For each PWM period, you use the sine table to determine what your duty cycle should be. For sin(0), PWM = 50%, count=128. For sin(2*pi/36), PWM = 59%, count=151, for sin(2*pi*2/36), PWM = 67%, count=171, etc.

So your output is high for 128, low for 128, high for 151, low for 256-151=105, high for 171, low for 85, etc. throughout the period of the sinewave.

Basically, all you do is compare a counter to the appropriate value in your table. The result of the comparison yields the state of your output.

Cheer for giving me some idea...

what about using of PWM frequency such as 5kHz and generate 500Hz while fclk is 40MHz?

Do I need a forumla to detemine this out?

Maverick Max

pwm rc sin

for 256 count for each PWM pulse as jonw0224 said, you need ;
F(clk) = F(PWM) * 256

F(clk)= 5000 * 256

you can use frequency divider to yeild this F(clk).

pwm sine table

Hi

Since I have managed to understand how to generate sine wave. Now I need to know how to vary frequency (speed).

Does anyone know how to do it?

Maverick max

generate sinus wave pwm

You can change your PWM period or (more preferred) you can change the number of PWM periods per sinewave period.

metho of generating sine wave

Do you have any example for me to implement variable frequency?

Maverick Max

avr pwm generate sin wave negative

you can use RC clock source such as LM555

• Pakdehari

### Pakdehari

Points: 2
generating sine wave table

Actually Im more interested in software...

Maverickmax

Hello,what a nice idea

Status
Not open for further replies.