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




Bookmarks