I've looked at Atmels site, the academy, and Google but I could not find a site that had a simple example of a PWM driving a LED or speaker at a set frequency. There were tons that would fade the LEDs and stuff but I can't seperate the fading part of the code from the basic PWM part.
Anyways as a simple demo I would like to buzz the piezo speaker on my Butterflys OCR1A port at 260Hz. The mega169v is running at 1MHz. I'm a bit confused about duty cycle and the prescaler. If I had a duty cycle of 50% and a prescaler of 1 would the frequency be 500KHz? :?
Here is my main() of some code that I scrapped from some fader examples. I don't even know what it should be doing (its not buzzing the piezo anyways).
int main(void) { // Program initalization Initialization(); TIMSK0 = 0x80; // Int T1 Overflow enabled TCCR1A = (1 << COM1A1)+(1 << WGM01); // non inverting / 8Bit PWM TCCR1B = (1 << CS10); // CLK/1 DDRD = (1 << 5); // PD5 (OC1A) as output OCRA1H = 0; OCRA1L = 80; OCRA1 = 80; sei(); // Interrupts enabled return 0; }
I'm sorry that this is so n00bish. I wish there was a tutorial on PWMs and how they work in an AVR.
Thanks! :)