pulse width modulation

Discussion in 'Embedded Systems and Microcontrollers' started by bhuvanesh, Jan 2, 2014.

  1. bhuvanesh

    Thread Starter Member

    Aug 10, 2013
    268
    2
    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 [​IMG]
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    PWM means you control the pulse width, not the voltage amplitude.
     
    bhuvanesh likes this.
  3. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    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.
     
    bhuvanesh likes this.
  4. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.
     
    bhuvanesh likes this.
  5. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    That's also true, I meant to mention ADCs in my post but forgot :p
     
    bhuvanesh likes this.
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    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.
     
    bhuvanesh likes this.
  7. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    497
    Hook up pwm pin to dc voltage meter. Then run your program.
     
Loading...