PDA

View Full Version : HPWM on 16F877A



jrudd
- 16th December 2010, 11:32
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.


@ 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

aratti
- 16th December 2010, 19:03
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.

jrudd
- 19th December 2010, 06:40
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