4.1.3 Pulse Width Modulation (PWM)

On some AVR MCUs, timers can also be used to generate PWM signals. A PWM signal has a fixed period. However, the on-duration (pulse width) of one period can range from 0 to the entire period. PWM is a very useful concept because it can be applied to normally on/off switches to achieve ``analog'' or ``graduated'' results.

In the context of robot programming, PWM is often used for the following purposes:

In order for a timer to generate PWM, there is one additional value called ``output compare''. This value is less than or equal to the overflow value. When the counter of a timer is less than this output compare value, an output pin drives high, when the counter of a timer is greater than or equal to this output compare value, the same output pin drives low. As a result, the duty cycle is directly proportional to the ratio of the output compare value and the overflow value.

Note that the overflow value controls the period of a PWM signal.

The PWM feature of a timer is very useful. It is possible to generate PWM in software. However, software generated PWM is processor power intensive, and it does not have the same precision of timer generated PWM signals.

Copyright © 2006-02-15 by Tak Auyeung