HPWM on 16F877A


Closed Thread
Results 1 to 3 of 3

Thread: HPWM on 16F877A

  1. #1
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24

    Default HPWM on 16F877A

    I made a board for a dual h-bridge design based on a breadboard I put together on the bench.
    I noticed on the new board that I was getting jittery motors as my analog In from the joystick approached 5.00vdc. I thought sure it was mosfet gate noise on the new board, but tracing it back showed that it was actually the PWM sig. coming out of the PIC. To prove this I went back to the breadboard and got the same effect when driving a single motor. So I removed the motor and just put an LED on CCP1 output and got a jittery LED as ADIN approached 4.90vdc.
    I looked at the ADIN with a scope and it was solid. I should have noticed this a long time ago.
    I tried to look at the PWM sig out of the PIC with the scope but the trace kept dropping out as I approach the magic 4.90vdc Input. Possibly due to losing the trigger due to a dropped pulse.
    I've spent the last few hours searching the forum to try to find similar problems to no avail. I did find a post by a gentleman who indicated that your being very optimistic if you put your HPWM command within your main program loop and did not expect to get dropped pulses due to rewriting HPWM every trip through.
    I did notice that changing the frequency within the HPWM command had an affect on the extent of the jitteriness. I've also tried changing from Word to Byte. Thanks in advance for any help on this.
    Code:
    @ DEVICE HS_OSC                     
    DEFine OSC 20                       '20Mhz Crystal
    '******************************************************************
    'Set Up The Ports
    TRISA=%11111111                     'Set Up I/O for PortA
    TRISB=%11001001                     'Set Up I/O for PortB
    'TRISC=%00001111                     'Set Up I/O for PortC       
    TRISD=%00001111                     'Set Up I/O for PortD
    TRISE=%00000000                     'Set Up I/O for PortE
    '******************************************************************
    'Define A/D Parameters
    define ADC_BITS     8               'Set Number of Bits in Result
    DEfine ADC_CLOCK    3               'Set Clock Source (3=RC)
    define ADC_SAMPLEUS 50              'Set Sampling Time in usec
    ADCON1=0                            'Set PortA to Analog and Left Justify Result
    '******************************************************************
    'Define Variables
    advalx var byte
    advaly var byte
    dutyx var word
    dutyy var word
    '******************************************************************
    Main:
    
    adcin 0,advaly                  'Pin2 "Y" Dir Voltage In
    'adcin 1,advalx                  'Pin3 "X" Dir Voltage In
    pause 120
    if advaly>254 then advaly=255
    'if advaly<5 then advaly=1
    
    'Start Left or "Y" Motor Drive
    if advaly>127 then 
    PortB.4=0:PortB.5=1:goto FWDLEFT
    else 
    PortB.4=1:PortB.5=0:goto REVLEFT
    endif
    
    FWDLEFT:
    dutyy=(advaly-127)*2
    goto GENPWMLEFT
    
    REVLEFT:
    dutyy=(127-advaly)*2
    goto GENPWMLEFT
    
    GENPWMLEFT:
    HPWM 1,dutyy,4500
    
    goto main
    JRudd

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    HPWM accept duty value from 0 to 255. in your formula when advaly is 255 then dutyy becomes 256 which is an invalid value and very likely will be seen a zero, and I think this will produce the jittering reported. Try dutyy=(advaly-128)*2

    Cheers

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    aratti,
    Thanks. Yes that solved the problem. Interestingly, in adding that fix, I discovered that I have to limit the duty cycle value to 254. 255 equates to 100% which means no pulses which means the charge pump on the IR2110 driver drops voltage and drops the gate drive and the motor drops out.
    JRUDD
    JRudd

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