18F4431 - Complementary mode PWM


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce, yes that worked (but I would expect nothing less from you )

    But why ?

    - I've got a period of $07E8 which is 2024 in decimal
    - I ramp duty to 2024 which is seems is not 100% of a period (led watching was misleading, I guess, because one channel was ramping 0-25% (?) and the other 100-75% which isn't really much of a change in output intensity)
    - so why does a duty cycle of 8000 get me 99% ?

    Andrew

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    0 TO 2024 wasn't giving you enough range.
    Code:
        ' At 20MHz, to figure a PWM frequency of 19.455kHz
        '
        ' TPWM = time period of PWM frequency
        ' PTPER = 12-bit period register PTPERL and PTPERH
        ' PTMRPS = PWM time base prescaler
        ' 
        '           (PTPER+1)*PTMRPS         257
        ' TPWM = ----------------  =  ------------ = 0.0000514 
        '                  Fosc/4                5000000
        '
        ' Frequency = 1/TPWM = 1/0.0000514 = 19.455kHz
        '
        ' PWM resolution (bits resolution for duty cycle)
        '
        '                   log(PTPER+1)*4)          3.01
        ' Resolution = ------------------ = ----------- = 10 bits
        '                      .301                       .301
    You have PTPER at 2024. PTMRPS at 16. Plug these into the above, and you get 0.00648.
    1/0.00648 = 154.32 so you have a PWM frequency arouund 154hZ.

    Your resolution is about 13-bits. %0001111111111111 = 8191.

    So 8000 instead of 2024 is just giving you full range duty cycle.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Got it now, for some reason I had it in my head that the calculated resolution was just a max you could go to - not the actual max you had to go to for 100% duty cycle.

    Thanks for the guidance - where's the book ? !!!

    Andrew

Similar Threads

  1. 18f4431; driving a stepper IN HARDWARE mode
    By DDDvvv in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st January 2010, 16:49
  2. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  3. switch mode power supply with PWM
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th July 2009, 20:51
  4. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  5. 18f4431 pwm4 and pwm 5 issues
    By lothar in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th April 2009, 16:48

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