pulse width modulation

Thread Starter

bhuvanesh

Joined Aug 10, 2013
268
analogWrite(pin num,255)//100% duty cycle so it completely on
analogWrite(pin num,125)/50% dutycycle so its 50% of time on and 50 percent of time off)

my question is in the above image whatever may be the duty cycle it on (5v) and off(nearly o v)

then how do we getting half of that voltage i mean around 2.5 from the actual 5v(change in value between 0 to 255 only says on time of time )

.thank you in advance
 

DerStrom8

Joined Feb 20, 2011
2,390
PWM means you control the pulse width, not the voltage amplitude.
Except PWM is said to give you a different voltage.

The way they get that is they use the average voltage. If you have a pulse width of 90% (mostly on), your average voltage will be much closer to 5 volts. If you have a pulse width of 10% (mostly off), you'll have an average voltage of close to 0. 50% duty cycle will give you half, or 2.5v.

It's important to note that it's not actually giving a lower voltage output, it's just switching it so fast that it appears to be lower.
 

MrChips

Joined Oct 2, 2009
30,808
Another way of putting this, if you integrate (take the average) the PWM signal you end up with a smoothed analog voltage. This is a common way of using PWM to implement a digital-to-analog converter (DAC) on a microcontroller.
 

DerStrom8

Joined Feb 20, 2011
2,390
Another way of putting this, if you integrate (take the average) the PWM signal you end up with a smoothed analog voltage. This is a common way of using PWM to implement a digital-to-analog converter (DAC) on a microcontroller.
That's also true, I meant to mention ADCs in my post but forgot :p
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
Also Switching an inductive device, the current waveform does not follow the voltage square wave but results in a sawtooth, with average or mean current level that varies with the PWM pulse width.
Max.
 
Top