PWM question

Thread Starter

Sonoma_Dog

Joined Jul 24, 2008
99
ok, i got a little confuse on PWM generation.

There is some specific pins for PWM output in ATmega168. My question is, can i just toggle high and low for other pins to make a PWM waveform? and what is the different between a PWM pin and non-PWM pin?

Thanks in advance
 

mik3

Joined Feb 4, 2008
4,843
Yes you can use other pins to create PWM but you have to write some more code than if you use the normal PWM pin. The normal PWM has the algorithm created already and you just enable it and set some parameters to set the desired frequency and pulse width. If you use an other pin then you have to create this algorithm (program). You can make it by making an interrupt to be triggered every T seconds (1/T=the desired frequency) by one of the uC timers. Then you will use some other instructions such as delays in the interrupt function to vary the pulse width according what you want to do.
 

hgmjr

Joined Jan 28, 2005
9,027
ok, i got a little confuse on PWM generation.

There is some specific pins for PWM output in ATmega168. My question is, can i just toggle high and low for other pins to make a PWM waveform? and what is the different between a PWM pin and non-PWM pin?

Thanks in advance
The thing I found useful about the built-in PWM function of the AVR is the ease with which I could control the frequency and duty-cycle of the PWM. As mik3 mentioned, you can use one of the pins to produce a PWM control but the down-side of doing so is the cost in program memory and processing power consumed to code the algorithm.

hgmjr
 
Top