1. Sonoma_Dog

    Thread Starter Active Member

    Jul 24, 2008
    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
  2. mik3

    Senior Member

    Feb 4, 2008
    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.
  3. hgmjr

    Retired Moderator

    Jan 28, 2005
    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.

  4. Sonoma_Dog

    Thread Starter Active Member

    Jul 24, 2008
    I Got it, thanks.

    looks like programming is another thing i need to learn :)