PDA

View Full Version : HPWM problem .. pls help!



Samuel
- 18th March 2005, 06:02
I'm using PIC16F877A to control two motors using an H-Bridge (L293D). Its a robot project for my engineering thesis design project. The ocsillator im using is 20Mhz. The following is my picbasic pro code. If i define my osc as 20Mhz, my motors run at FULL power and DO NOT change direction as per the code below. They just keep going forward. But if i have it as below, they run at a very good speed, and go thro each subroutine perfectly (ie: forward>stop>reverse>stop>main). One problem with this is when the motors are turning forward and revers, i get this high pitch sound. How can i fix this? Also if i wanna change the speed do i change dutcycle (150) or frequency (400)? And what about my DEFINE OSC value?? 4 or 20? Because my serial code (SERIN with T9600) seems to work well with DEFINE OSC 4. Should i sjust change my actualy osc to 4Mhz?!

Any help will be gratly appreciated!!
Thanks so much!
Samuel.


DEFINE OSC 4
TRISC = %00000000

HPWM 1, 150, 400
HPWM 2, 150, 400

TRISB = %00000000

main:

gosub fwd
pause 5000
gosub halt
pause 5000
gosub rever
pause 5000
gosub halt
pause 5000

goto main
end

anj
- 18th March 2005, 08:13
Problem one. At 20MHz, as per the manual, min HPWM freq you can get is 1221Hz
You are trying to run at 400, so its probably screwing up the internal math.

To change motor speed you change duty cycle.

As to noise, The motor windings are vibrating at roughly the PWM freq and this is what you hear. To get rid of the whine, you need to use a freq that is out of hearing range ( so above 16KHz or below 50Hz ).

As to oscillator, try using yr 20MHz first ( with Define OSC 20 )
then use
HPWM 1, 150, 16000
HPWM 2, 150, 16000
see how that runs.
Andrew

Samuel
- 18th March 2005, 17:47
Thanks a lot anj!! I did that, i.e OSC 20 and HPWM 1 150 16000, but the motors were turning alternatively.. i.e one wud turn, and then the other and this keeps going in a loop as per my code. But they didnt turn together as they should be. (see code above) I then bumped the frequency down to 5000 and both motors worked well and at a good speed and went thro the subroutines well. i.e forward>halt>rev>halt>main. But now my robot is not going straight!!! it seems like both wheels are not going at the same speed or not starting at the same instant. Is this because HPWM 1 starts and is "followed" by HPWM 2 so there is a delay? but it doesnt seem to be just the start time .. i feel the actual speeds differ ... in the forward direction, one motor goes slower, and in the revers direction the other goes slower .. get it? playing with the frequency seems to affect this .. how do find the right frequency? Trial and error?

Thanks a lot for your help!

Samuel
- 18th March 2005, 19:39
someone help! HPWM duty cycle of 110 and frequency 1400 is giving me good results but my hbridge (L293D, motor driver) is getting HOT! and i'm hearing the high pitch sound!

If i increase the frequency to above 16000, the sound is gone but then both motors dunt turn together, they turn alternatively!

NavMicroSystems
- 18th March 2005, 20:21
The frequency limit for the L293D is 5kHz !!

see Datasheet !

Samuel
- 18th March 2005, 20:44
ohh thanks! i just checked the L293D data sheet and it doesnt talk about the limit of 5KHz .. But i guess it makes sense.

A duty cycle of anything below 100 doesnt push my motors. So the range for my duty cycle would be between 100 and 255? And the PIC with a 20Mhz OSC cannot go below 1221Hz, and my L293D doesnt go above 5KHz. So my frequency range would be between 1221Hz and 5000Hz? Much better .. now that i've narrowed down to something ...

I like ure signature "There are only 10 types of people: Those who understand binary, and those who don't ..."!!

anj
- 18th March 2005, 21:10
i just checked the L293D data sheet and it doesnt talk about the limit of 5KHz
My datasheet ( Unitrode ) doesnt give this limitation either.
16KHz gives a period of 62.5uS. Fig1 in the application info shows rise/fall times and these are less than 0.5us, so the chip shld cope with 16KHz easily

Re getting hot, at low duty cycle ( ie just getting started or creeping ), the motor is not very efficient and can draw a lot higher than normal current. For this, the datasheet is indispensable, as these chips do get hot and they do need thermal heatsinking.
I have done a lot of testing with "small" motors and PWM and found the best low speed performance was at very low period ( I go down to 28Hz for one motor ). I have never tested with larger motors so cant help there.
If you still want to use a 20MHz osc and HPWM but get a much lower output freq, you can run the signal through a deecade counter typ chip, and just pinch the relevant output that suits yr needs.
Or i just found this, never tried it but ut looks interesting
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=6
Andrew

NavMicroSystems
- 19th March 2005, 11:58
L293D Datasheet (http://www.alltronics.com/download/1330.pdf)

anj
- 19th March 2005, 21:49
Gday
Interesting.
I have an original Unitrode datasheet, and a quick search brings up the current texas one http://focus.ti.com/docs/prod/folders/print/l293d.html
Neither of these specify a 5KHz limit.
They mention doing their rise/fall time measurements at 5KHz, but thats all.
Based on the actual rise/fall times ( your link vs texas link ), they appear to be close, so i am at a loss to understand the difference.
I certainly have run my 293D at higher than 5KHz before.
Dunno

Samuel
- 21st March 2005, 03:08
Well right now after playing for a whole afternoon with different conbinations of duty cycle and frequency, the HPWM 1, 135, 3000 seems to work well for me .. at high frequencies my motors start doing funny stuff .. I feel this may have to do with the how the 293D is setup. I have my two PWM lines, one going into each of the enable. And then 4 control lines, 2 for each motor. There is another way of setting up, which can reduce the number of lines by using an Inverter. Since this setup is working for me, and i have enough ports on my PIC controller, i'm not gonna try that for now ... I just have to find someway to keep the 293D cool .. Someone suggested to use some kinda paste .. tooth paste??? And then what?

anj
- 21st March 2005, 06:17
Someone suggested to use some kinda paste .. tooth paste???
Thermal transfer paste ( heatsink paste ). And a big heatsink.


And then what?
Go for a dedicated H Bridge using N and P channnel mosfets.
Using one PWM channel and some pulldown diodes ( from between the gates current limiting resustor and the gate, back to a PIC pin ), you can control where the PWM goes, hence dirn.
Andrew

Bronurstomp
- 1st February 2006, 15:30
Micrel makes a very good set of mosfet gate driver chips. Find their data sheets here. http://www.micrel.com/_PDF/mic4423.pdf
They are dual output, so you would need 2 of them for 4 outputs. Again these will drive N-channel Mosfets (low side is motor to ground connection).

If you want to use P channel Mosfets on the high side (Motor to power connection), then you'll need some kind of high-side driver like Linear's LT1161, which does all the charge pumping for you.
Their datasheet is here.

http://www.linear.com/pc/productDetail.do?navId=H0,C1,C1003,C1142,C1041,P13 87

Happy motoring!