On Mon, 5 Dec 2005 10:55:06 -0800 you wrote: >I'm just starting to play around with sine waves using PWM and a lookup table. > >I'm concerned as to the maximum frequency of a sine that can be generated. Walking through an example, based on Fast PWM. > >Xtal=9830400Hz >8bit Fast PWM >This gives PWM frequency of (9830400/256) 19200Hz. > >So, if I wanted to generate a sine wave at 2200Hz, I'd only be changing the pulse width ~9 times per cycle. This seems completely inadequate. > >As this is my first attempt at sine wave generation, I have a couple of questions > >1) Does the math above seem correct, or am I mistaken in my limited understanding of using PWM The division looks incorrect. 9830400/256 = 38400. >2) Assuming my math is correct, then there must be one rule-of-thumb for how how a frequency one can generate using fast-pwm for a given Xtal frequency. What is the rule? >3) Anything else you'd care to add/offer? You could sacrifice resolution to get a faster pwm by setting the top to a lower value than 255. Also the ATtiny26 has a 64MHz PLL clock for PWM giving a PWM frequency of 250KHz at 8 bits. An alternative is a dedicated synth chip. The AD9833 is not too expensive and isn't difficult to program. -- Ralph Hilton http://www.ralphhilton.org C-Meter: http://www.cmeter.org FZAOINT http://www.fzaoint.net
Message
Re: [AVR-Chat] Generating sine waves with PWM
2005-12-06 by Ralph Hilton
Attachments
- No local attachments were found for this message.