๐Ÿ“ฃ๐Ÿ“ช ๐Ÿšš Adafruit will not be shipping USPS orders Monday October 14, 2019 ๐Ÿ—“. Expedited USPS orders placed after 11am ET ๐Ÿ•š Friday October 11 will go out Tuesday October 15 ๐Ÿ“ฃ๐Ÿ“ช๐Ÿšš
0

using pwm with atmega 8
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

using pwm with atmega 8

by amit_mittal on Sat Aug 09, 2008 3:22 am

:?
I want to generate sine wave o/p with my atmega 8 m/c
help me out
i am finding problem in using pwm modes ?
----
|
| |
amit_mittal
 
Posts: 1
Joined: Sat Aug 09, 2008 2:09 am

by franklin97355 on Sat Aug 09, 2008 12:11 pm

PWM is a great way to reduce power output from a pin but the duty cycle is not steady and only the average duty cycle is controlable. You will have to find another way to create your sine wave.

franklin97355
 
Posts: 21204
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

by adafruit on Sat Aug 09, 2008 1:37 pm

you -can- make sine waves but they'll be low frequency and you need some filtering
http://www.atmel.com/dyn/resources/prod ... oc2542.pdf

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by mtbf0 on Sun Aug 10, 2008 12:36 pm

thisproject is supposed to output sine waves. it sounds ok, but i have no 'scope so i have no idea what the output waveform really looks like. the outputs are on oc1a and oc1b. the code should compile for a mega8 if you fix the output control register names. since this is written for the arduino environment, you will also need to change the declaration of
Code: Select all | TOGGLE FULL SIZE
void loop (void)
to
Code: Select all | TOGGLE FULL SIZE
int main ()
and add a call to setup() at the beginning of main.

it's set up to run at 8MHz, but might actually work at 16Mhz, though the tempo would be double time. it's also possible that some of the constant calculations might get screwed up, since i was trying to squeeze as much precision as i could out of them. running at 16MHz would have the advantage of putting the pwm frequency outside the range of human hearing, (31.25KHz).

oops, just spotted a bug in the last line of the code. should be
Code: Select all | TOGGLE FULL SIZE
while (song_flags);
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.