Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generating sine wave using PWM method

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,691
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
 

jonw0224

Full Member level 4
Joined
Nov 22, 2004
Messages
211
Helped
45
Reputation
90
Reaction score
14
Trophy points
1,298
Location
USA
Activity points
2,528
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.
 
  • Like
Reactions: sebinphilip

    V

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating

    sebinphilip

    Points: 2
    Helpful Answer Positive Rating

ezshereef

Junior Member level 3
Joined
Jan 5, 2006
Messages
27
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,281
Activity points
1,524
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.
 

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,691
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
 

Davood Amerion

Advanced Member level 2
Joined
Mar 1, 2005
Messages
584
Helped
116
Reputation
232
Reaction score
24
Trophy points
1,298
Location
Persia
Activity points
6,345
pwm rc sin

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

in your example:
F(clk)= 5000 * 256

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

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,691
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
 

jonw0224

Full Member level 4
Joined
Nov 22, 2004
Messages
211
Helped
45
Reputation
90
Reaction score
14
Trophy points
1,298
Location
USA
Activity points
2,528
generate sinus wave pwm

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

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,691
metho of generating sine wave

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

Maverick Max
 

Davood Amerion

Advanced Member level 2
Joined
Mar 1, 2005
Messages
584
Helped
116
Reputation
232
Reaction score
24
Trophy points
1,298
Location
Persia
Activity points
6,345
avr pwm generate sin wave negative

you can use RC clock source such as LM555
 

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,691
generating sine wave table

Actually Im more interested in software...

Maverickmax
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top