Duty Cycle


Closed Thread
Results 1 to 11 of 11

Thread: Duty Cycle

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    The PWM period is defined in units of 1/(Fosc/4).
    If you're operating at 4Mhz the PWM period is defined in units of us and the dutycycle in terms 0.25us. A PWM period value 26 means a PWM period 26us which is equal to 38461Hz.

    The PWM output goes high when the period start (timer = 0) and goes low when the timer equals CCPR1L (and the internal "instruction cycle clock" equals CCP1CON.4:5).

    CCPR1L = 13
    Period starts, output goes high. Timer ticks along.....13 ticks later it matches CCPR1L, output goes low....timer continues, when it reaches 26 it automatically resets to 0 and the cycle repeats. Output is high for 13 ticks and low for 13 ticks - you get a 50% dutycycle. Set CCPR1L to 6 and the output is high for 6 ticks and low for 20 ticks - you get a 25% dutycycle.

    To get better resolution you can use the CCP1CON.4:5 bits. This uses the extra two bits retrieved from the internal "instruction cycle clock" and is why you can get 4 "steps" per tick. This allows the PWM module to drive the output low "in between" normal timer ticks. If you're not interested in the high resolution don't bother with the two lower bits.

    The higher PWM frequency (lower/shorter period) you use the less resolution you'll get (as I hope you can see from above).

    /Henrik.

  2. #2
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    Hi Henrik,

    It is slowly sinking in!

    But, how do i get the duty range in your example 0-103 is this just the 26 * 4 = 104 (with 103 available)?


    Gordon,,,

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    Hi,
    Yes basically, 104 steps, 0-103.
    103 = %01100111 where the lower two bits go in CCPCON.4:5 and the other, shifted to the right in in CCPR1L (00011001) = 25.

    Think of CCPR1L as bits to left of a decimal point and CCPCON.4:5 as bits to the right of decimal point. Because you only have two bits to the right of the decimal point the number can only be x.0%(00), x.25%(01), x.50%(10), x.75%(11).

    If you have a period of 26 ticks (no matter what that actually means in terms of frequency), a dutycycle of 13.0 is 50%.

    When you have a period of 26 you get a 50% dutycycle by setting the dutycycle register(s) to "00011001.00" (or "13.00") because 13 is 50% of 26 which is your PWM period in timer ticks).

    /Henrik.

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    If I were you...
    Here is where I would dust off the old O-Scope and be able to see what the effect of different values had on the duty cycle.

    Nothing like being able to SEE what is going on in your program.

    Like one of Darrels signatures stated...

    "I hear and forget, I see and understand, I do and remember" Or something like that... and I don't remember who he was quoting... Albert Einstein or Confucus or
    sombody like that.

    Any way I always enjoy and learn from being able to visualize the PWM cycle using an oscope... then you can try different values and see if your calculations are proving true.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    Dwight, you mean to imply there is a real world side to all this stuff?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Duty Cycle

    Many thanks to Henrik for taking the time to explain this for me, at last it is clear...

    But Hekler is absolutely right, there's no substitute for actually seeing it working.


    Gordon,,

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts