PWM Concepts

So guys, im trying to understand the theory behind pwm...

Correct me if im wrong but as far as i can tell we can use pwm to give variable voltage as well as binary signals... So it depends on the nature of module how to interpret it for example an led can be dim or bright but a servo can change positions...

Now what i want to understand if we consider that binary signal of various sorts are being sent to a module that exclusively relies on pwm for both power and signals will it effect the speed or rotation of that module?

Note: i have just assumed that there is a module (maybe there actually is but not in my knowledge)

An additional question what is the absoltue variable in pwm is it the voltage or the signal itself that is then translated to binary or what?

Why don't you Google for articles and tutorials that explain how pwm works? There are many to find. Your current understanding certainly needs improving :wink:

Seriously, every article takes one of the two aspect and describes it.

In my experience PWM is always used as a control signal for devices that are powered separately.

If you know of any "module that exclusively relies on pwm for both power and signals" perhaps you could provide a link to such a "module" or details of it. I've never heard of such a thing so your question is meaningless to me.


Seriously, every article takes one of the two aspect and describes it.

Two aspects? What are those?

A PWM signal is not a variable voltage. It is a signal that switches at high speed between 0V and 5V for example. What varies is the % of time at 0V versus the % of time at 5V.

When used to drive LEDs, the LEDs do not dim. They flash on and off at high speed with the pwm signal. It is the human eye that perceives this as dimming, because the eye cannot see the rapid flashing. (This is certainly true for most red/green/blue leds. For white leds, things are slightly different. They consists of an UV led inside a piece of fluorescent material which transforms the UV light into white light. This may not be capable of switching on and off at high speed, so in practice, it may in fact be dimmed by the PWM signal).

PWM for servos (produced by the Servo library) is significantly different from PWM used to control motors and LEDs that is produced by the analogWrite() function. It is unfortunate that the same acronym is used for two different things.

For a servo the pulse width indicates the angle the servo arm should be at. Servo pulse widths vary between about 400 and 2400 microsecs and are repeated about 50 times per second.

For a motor or LED PWM defines the fraction of time that it receives power between 0/255 and 255/255. The standard frequency for pulses produced by analogWrite() is about 490 Hz.


By switching on & off at a known duty cycle, PWM modulates the average voltage and the average power.

At 50% PWM (127 or 128* on the Arduino) the voltage is off half the time so we have an average of about 2.5V and half the power. (But, you won't perceive an LED as "half brightness" and a motor won't necessarily run at half-speed.)

A low-pass filter can smooth the PWM to give a true-analog voltage. But this is only done in "special cases" because a simple R-C filter is affected by the load (it works best when driving a high-impedance load) and if you are driving a motor or anything "high power" you need a linear amplifier which is more complicated, more expensive, and less energy efficient than a simple switching transistor or MOSFET.

Switching power supplies and Class-D amplifiers use a special kind of high frequency PWM where the pulse duration is determined by an analog feedback circuit. The high frequency makes it easier to filter.

  • Of course the real average is 127.5 but it's an integer, so there are no decimals and we can't get exactly 50%.

A 50% duty cycle is no problem, the hardware counts the same number of pulses for each state.

It's possible to obtain any duty cycle between 0 (off) and 0x100 (on). As a minor problem this can not be achieved using 8 bit arguments and registers, so the Arduino firmware is cheating and AFAIR treats 0 and 1 the same (off). Or 0xFF and 0x100, dunno...

Seriously, every article takes one of the two aspect and describes it.

And yet you have ideas that are completely untrue about PWM.

You can filter PWM output to get an analog voltage that will likely have some ripple....

PWM going into motors gets averaged in the induced fields, the nice straight edge transitions take different shapes.