HPWM with zero duty cycle on PIC18F2550


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    10

    Default HPWM with zero duty cycle on PIC18F2550

    I am helping some Jr High students with a robot for science olympiad. We are using some potentiometers to control the duty cycle of a HPWM output for the drive motor. The HPWM runs an N channel mosfet that switches the 0V signal to the motor. It works fine until the analog value becomes zero, setting the duty cycle to zero in the code. When that happens the motors appear to run at full speed. We don't have an oscilloscope to check the actual output from the chip but we do have an LED connected in parallel with the mosfet. Its brightness correlates perfectly with the motor speed, even when the duty cycle is zero. It is as bright as it gets at the same time the motor is running full speed.

    Does anyone know how the HPWM works with a zero duty cycle? It doesn't appear to be caused by some reaction in the mosfet because we see it in the LED. I thought about putting a pull down resistor on the output to make sure it goes off but it has a 1K current limiting resistor connected to the LED.

    Look forward to anyone's help and suggestions.

  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

    To bad you don't have a scope. But the symptom suggests that the HPWM pin is going high, or at least to a very high duty cycle. It should go to zero volts(gnd). If the HPWM command is not playing nice, then you might try using the MIN operator to limit the ADC value to 1.

    As far as as pull down resistor goes, a 47K resistor going from GND directly to the gate of the MOSFET base will keep the FET off in case for some reason the HPWM pin floats. 47K will also prevent glitching when the device is powered up. It will not affect the gave drive voltage or the LED. This is pretty much standard practice. I assume you are using a logic level FET?

    Are you sure that the value is at zero when this happens and that the duty VAR is not somehow overflowing to 255? . A simple test would be a bare minimum program that simply does something like below. It should be on 2 sec then off 2 sec.
    Code:
    ' Defines here  
    
    DO
    
            HPWM 1, 0,1000. 
            PAUSE 2000
            HPWM 1,255,1000
            PAUSE 2000
    
    LOOP
    A schematic diagram and a posting of your code would be helpful.

  3. #3
    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

  4. #4
    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

  5. #5
    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.

  6. #6
    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 : 1

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