User manual

www.sainsmart.com
Copyright © 2013 SainSmart All Rights Reserved
Chapter4 PWM
Whats PWM?
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means.
Digital control is used to create a square wave, a signal switched between on and off. This on-off
pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the
portion of the time the signal spends on versus the time that the signal spends off. The duration
of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that
pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as
if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.
In the graphic below, the green lines represent a regular time period. This duration or period is
the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about
500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of
0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127)
is a 50% duty cycle (on half the time) for example.
For the Arduino, you write a value from 0 to 255 on a PWM pin, and the Arduino library will
cause the pin to output a PWM signal whose on time is in proportion to the value written.
When it comes time for us to actually write an output voltage, the 0-255 value lacks meaning.
What we want is many cases is a voltage. For our purposes, we will assume the Arduino is