PWM - Dutycycle affecting frequency?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938

    Default PWM - Dutycycle affecting frequency?

    Hi,

    I'm just playing around with PWM (...and PicMultiCalc).

    While making some experiments, I notice that changing the dutycycle will affect the Period's duration (frequency).

    First, I set dutycylce to 127 (=50%). The frequency is 92,24kHz.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1640&stc=1&d=117939319 7">

    Second, same test at 64 (=25%) dutycycle. The frequency is now 46,02kHz.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1639&stc=1&d=117939319 7">

    In my comprehension of PWM, dutycycle would affect only the ratio of the HIGH against the LOW signal.

    Is this okay or am I measuring something wrong?
    Attached Images Attached Images   
    Roger

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i guess something is wrong in your code. Can you post it here?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Triggering parameters and signal amplitude ... please !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    36 mVPP looks like the scope is set in AC mode.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Code & parameters

    So, here's the code:
    Code:
    ' Fuses
    @ DEVICE PIC12F683,FCMEN_OFF
    @ DEVICE PIC12F683,IESO_OFF
    @ DEVICE PIC12F683,BOD_OFF
    @ DEVICE PIC12F683,CPD_OFF
    @ DEVICE PIC12F683,PROTECT_OFF
    @ DEVICE PIC12F683,MCLR_OFF
    @ DEVICE PIC12F683,WDT_OFF
    @ DEVICE PIC12F683,INTRC_OSC_NOCLKOUT
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    ANSEL      = %00000000  'Disable analog inputs
    ADCON0     = %00000000  'ADC is OFF
    CMCON0     = %00000111  'Comparator is OFF
    OPTION_REG = %10000000  'Pull-Ups disabled...
    TRISIO     = %00000000  'All PORTBs are Outputs
    GPIO       = %00000000  'All PORTBs are Low
    
    '-------------------------------------------------------------------------------
    ' Defines
    
    '-------------------------------------------------------------------------------
    ' Variables
    
    '-------------------------------------------------------------------------------
    ' Program
    MAIN:
        PWM GPIO.2,64,1000
        goto main
    end
    And here is how the oscillo is set:
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1649&stc=1&d=117941075 3">
    Attached Images Attached Images  
    Roger

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Rtfm ...

    Hi,Flotul ...

    Not good to change PWM parameters all the time !!! ( a re-write is a change ... )

    DO NOT use PWM in such a tight loop !!!

    And try it removing the loop ... will work fine,then !!!

    Alain
    Last edited by Acetronics2; - 17th May 2007 at 16:07.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    MAIN:
    PWM GPIO.2,64,1000
    goto main
    end[/code]
    Try adding a 'DEFINE NO_CLRWDT 1' and see if the freq still changes, or changes as much.

    PBP (by default) adds a ClearWDT instruction before every PBP instruction. So, when you get down to the smaller duty cycle, that instruction executes more and more often, affecting your PWM frequency.

    The problem with the PWM command, being software driven, is that it's frequency is affected by everything else in the program as a whole. It doesn't matter how short you make the program (as you've made the program as practically short as it can get), it'll still be affected by the 'goto main', it'll even be affected if the 'goto main' jumps across a page boundary.

    PWM driven from an interrupt or a hardware module is about the only way to go if you want to keep a stable base frequency.

    There's nothing wrong with your program, or your setup, or your 'scope settings...ya just need a bit more understanding the logic that's running underneath the PWM command...

Similar Threads

  1. SLA battery charging with PWM but which frequency
    By showtime in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 13th June 2017, 11:41
  2. Low freq PWM problem
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th February 2010, 07:09
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. PWM 'channels ...what's that all about then!
    By HankMcSpank in forum General
    Replies: 5
    Last Post: - 23rd April 2009, 16:49
  5. Adjusting PWM frequency
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 14th March 2008, 18:12

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