Go Down

Topic: sine/triangle wave sound with PWM? (Read 25591 times) previous topic - next topic


Jul 12, 2010, 06:58 am Last Edit: Jul 12, 2010, 07:23 am by wyager Reason: 1
So, I was trying to mess with noise cancellation on my arduino (I think I did it wrong now that I remember) but at the time I was wondering if it was feasible to generate a pseudo-sine (or triangle) wave (but mostly sine  :D) by rapidly switching PWM duty cycle. I know a 16mhz AVR can do PWM at 8mhz(fixed), which is plenty fast enough for these purposes, but I'm more concerned about the duty cycle switching speeds. Basically my idea would take 2 PWM pins per speaker, and maybe an h-bridge. Basically you set one pin to ground, and the other you rapidly adjust the PWM duty to simulate the changing values of a sine wave. Let's assume we want a frequency limit of 10khz, and to generate one of those sine wave parabolas we want 10 different values (this would be pretty low resolution) over a single half-wave (one parabola). We could use a super-low-pass filter cap to smooth it out. To get the other parabola (on the opposite side of the x-axis) we have to reverse the pin orientation so the other one is ground and the one that used to be ground is now doing the PWM. We would again have to make those 10 different PWM values to simulate the parabola. This means for each cycle, we need 20 separate PWM values (remember, that's an arbitrary value). If we're at 10khz, that's 200khz duty cycle switching. Is this doable? Switching the PWM level 200 thousand times a second? Would this idea even work  :-? ?


I know a 16mhz AVR can do PWM at 8[glow]ghz[/glow],

Now that is something I would like to see demonstrated.  ;D


Jul 12, 2010, 07:17 am Last Edit: Jul 12, 2010, 07:24 am by wyager Reason: 1
Derp! lol what was I thinking? :P


This may be of interest: http://adrianfreed.com/content/arduino-sketch-high-frequency-precision-sine-wave-tone-sound-synthesis



thanks! I'll look at those, the first one seems pretty complex.


Wow, things like this remind me I must make a signal genorator soon... they are so darned useful...  any good kits out there guys? I do love a good kit.  SMD would be fun... sorry to thread-jack btw :P


Look this atmega based one:

Go Up