Domanda

I am trying to make use of the ATMega16's timer0 to generate PWM pulses and output sound on a basic buzzer..

But i am facing a problem figuring out how i can be able to change the frequency of the waves im creating (to generate different notes)

I saw on the datasheet that with the timer0 you can use ICR for TOP values and that way you can change the frequency and with OCR you'll be able to change the duty cycle..

Is there a similar way but on either timer0 or timer2 ?

I am already using timer1 to control something else so i'm wondering if i have to start over :(

Thanks in advance,

Any idea is appreciated

È stato utile?

Soluzione

Generally, when "running out of" timers, simple software routines based on timer interrupts will take you pretty far.

For example, using one of the timer compare interrupts you could easily generate almost all frequencies:

In the timer compare ISR just toggle the respective output pin and (let the timer be) reset to 0. The set compare value determines the generated frequency in terms of fractions of the timer's frequency.

There are many more elaborate ways to use a limited number of available timers to perform a lot of timer tasks at the same time. It is basically all just based on thoughtfully used ISRs.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top