HPWM with zero duty cycle on PIC18F2550


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: HPWM with zero duty cycle on PIC18F2550

    I have attempted to attach the code. I couldn't figure out how to insert it.

    I have an autocad wiring diagram but haven't figured out how to attach it or insert it yet.

    Sort of a humbling experience.

    thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2014
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: HPWM with zero duty cycle on PIC18F2550

    Consider this section of your code:

    Code:
    'create a  +/- value centered at 512
        left1 = abs(analogleft-512)
        right1 = abs(analogright-512)
        
        'scale value and create centered deadband of +/-10
        'value should fall between -10 and 256 for duty cycle
        
        dutycycleleft = ((left1 * 52)/100)-10
        dutycycleright =  ((right1 *52)/100)-10
    PBP only supports unsigned integers, meaning negative numbers are not supported. There can be no "-10"

    For example, you have a word variable "dutycycleleft". As a word, it can hold a value from 0 to 65555. If the current value is 5 and you subtract 10 then the variable will underflow by 5 and become 65531 instead of -5. This will cause the PWM to go full on.

    A quick and dirty way to fix the code is to take this from your code:
    Code:
    if dutycycleleft < 1 then       'if dutycycle is between -10 and 1
           dutycycleleft = 0         'then it equals zero
        endif
    And change it to:
    Code:
      if dutycycle left > 300 then
          dutycycleleft = 0
      endif

    Do the same for dutycycleright

    Try this and let me know how it works out

  3. #3
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: HPWM with zero duty cycle on PIC18F2550

    if dutycycle left > 255 then
    dutycycleleft = 0
    endif

    Or whatever -- HPWM value must be 0 to 255.
    Last edited by SUNFLOWER; - 27th February 2014 at 01:24.

  4. #4
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: HPWM with zero duty cycle on PIC18F2550

    if dutycycle left > 32777 then
    dutycycleleft = 0
    elseif dutycycle left > 255 then dutycycleleft = 255
    endif

    Or whatever -- HPWM value must be 0 to 255.

Similar Threads

  1. Duty Cycle
    By Gord11 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th September 2011, 08:53
  2. how to generate 83.33khz with 16.7% duty cycle?
    By donatelo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd September 2008, 17:08
  3. How can I measure Duty cycle ?
    By MaxiBoost in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 28th December 2006, 15:02
  4. PWM _ Duty Cycle in Tenths
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 17th May 2004, 12:09
  5. Duty Cycle Dilemmas
    By crankshaft in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th February 2003, 12:40

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