PDA

View Full Version : Driving a DC motor /w 16f84a



Lilmanmgf
- 29th April 2007, 14:53
I'm trying to drive a DC motor with a 16f84a. I am currently using a push pull circuit with a tip125 and tip122. For a few seconds it should function as it should, but the PIC shortly stops executing the program. I am assuming this is because I used the same power supply for both the PIC and the motor. Due to the specifications of the project I am working on I am only able to use a total of 9 volts. I do not really need speed control as this is supposed to be a "sumo bot," capable of pushing another robot. Would a PIC function with only 4.5 volts? Also do you guys have any recommendation for Mosfets? The transistors are getting quite hot, and even with a large heat sink I'm not sure I would be able to dissipate enough heat. Thank you in advance.


-Chris

mister_e
- 29th April 2007, 15:07
Depending which version of PIC, some may work down to 2-3 volts. Usually it's written on the first datasheet. I have quoted it for you...

CMOS Enhanced FLASH/EEPROM
Technology:
• Low power, high speed technology
• Fully static design
• Wide operating voltage range:
- Commercial: 2.0V to 5.5V
- Industrial: 2.0V to 5.5V

We need to know what kind of power supply you're using, motor's current need, and if possible your schematic. I have few idea, but guessing is not always my cup of tea.

malc-c
- 29th April 2007, 17:22
On the assumption you are using PP3 type 9v batteries, and that the FETs are getting hot, I would conclude that a fair amount of amps are being drawn and possibly taking the voltage down causing the PIC to shut down. Again, as Steve says, without a schematic and or details of the code its hard to give a more exact answer.

Lilmanmgf
- 29th April 2007, 17:56
I don't know how to post pictures here, so here is a link to the circuit. Sorry it looks bad, but I only had ms paint.

http://69.65.40.73/lilman/motorpushpull.jpg

At the moment I was just using on-off to keep the motor on. I wasn't sure if the 16f84a was capable of PWM. The circuit will only run for 15 second intervals. Thank you for all the help.
-Chris

Edit- I'm using two AA batteries to power the PIC. The datasheet said it can operate between 2v and 5.5v. I was thinking of using a separate 5v or 6v battery for the motor and transistors.

malc-c
- 29th April 2007, 18:21
I came across this on a web site, which sounds similar to what you describe. Note it suggest the use of a seperate supply to the motor

http://www.tigoe.net/pcomp/code/archives/bx-24/000294.shtml

Charles Linquis
- 29th April 2007, 18:24
A couple of things:

Unless you want the motor to have dynamic braking, you don't need the "bottom" transistor.

You could reduce your dissiplation (heat generation) somewhat by putting the PNP transistor in the "top" position, and connecting the emitter directly to the +5V source, and the collector to the motor. If you build the circuit this way, you should also connect a 1K (or so) from the base to the emitter to guarantee that the transistor completely shuts off. Pulling the base LOW will turn the motor on. Make certain that you leave the 1K resistor (that you already show in your schematic) in place.

The darlington transistors you use will certainly dissipate more heat than FETs in this application because the transistors will have a saturation voltage of at least 1V. If the motor draws 2A, then you will dissipate 2A X 1V = 2W.
The motor will also get a maximum of 4V (or so) in this circuit as well.

FETs will improve the circuit. Choose "logic level" FETS with a low ON resistance. If you use an N-channel FET (recommended), put it in series with the GROUND side of the motor. You won't need a resistor between the PIC output pin and the FET gate, although a 1-10K resistor between the gate and 5V will improve the circuit because it will insure a full 5V on the gate when the PIC pin is high. The ON resistance of the FET can be as low as 20 milli-ohms. That means that if your motor draws 2A, then the voltage drop across the FET will be 40mV and the dissipation will be .040 * 2 = 80mW. It will barely get warm - even without a heatsink.

Regardless of the transistors used, you should always put a diode across the motor in the "reverse" direction. This is just good practice and prevents turn-off transients from destroying the transistors.

And as to whether or not your chip supports PWM - any PIC can do PWM in software. You could have looked in the manual and found if supports hardware PWM in less time than it took you to make your post.

Lilmanmgf
- 29th April 2007, 19:54
FETs will improve the circuit. Choose "logic level" FETS with a low ON resistance. If you use an N-channel FET (recommended), put it in series with the GROUND side of the motor. You won't need a resistor between the PIC output pin and the FET gate, although a 1-10K resistor between the gate and 5V will improve the circuit because it will insure a full 5V on the gate when the PIC pin is high. The ON resistance of the FET can be as low as 20 milli-ohms. That means that if your motor draws 2A, then the voltage drop across the FET will be 40mV and the dissipation will be .040 * 2 = 80mW. It will barely get warm - even without a heatsink.


What FET would you recommend in this application?

Charles Linquis
- 29th April 2007, 20:21
Sorry, I'm an engineer, not a secretary.

Charles Linquis
- 29th April 2007, 20:36
But.. Just to insure you don't get it hooked up wrong.

Source to GROUND
Gate to PIC
Drain to motor (-)
Motor (+) to 5V

1-10K resistor from Gate to +5

Lilmanmgf
- 30th April 2007, 04:03
I have a TRF510, but I was unable to get it to work. I'm really not sure how to read mosfets. It says the gate threshold voltage is from 2v to 4v. I'm assuming this means at least 2 volts is required to turn the mosfet on. In my current setup the PIC is powered by a 3 volts, so shouldn't this be sufficient to turn it off? Perhaps I unknowingly fried it previously.

skimask
- 30th April 2007, 04:16
It says the gate threshold voltage is from 2v to 4v.

If we're both reading the same datasheet, then you may also notice that in this case, it says that the gate voltage (Vgs) is equal to the drain-source voltage (Vds) and the current (Id) is only 250uA.
In your case, you're probably trying to draw too much load without enough Vgs (see Figure 5,6,7 of the datasheet).
You would want to find a 'logic level' n-channel enhancement mode mosfet with enough current capability at low gate threshold voltages.
I use an STN2E10L (sot-223 package) in most of my stuff. I can pull over 5 amps thru it @ 5v using a 5v (which ends up being about 4.5v) PIC pin to drive it.

Charles Linquis
- 30th April 2007, 06:42
An International Rectifier IRF3706 would be a good choice.

Archangel
- 30th April 2007, 20:44
Hi Lilmanmgf,
This Sumobot you are building, Is it going to have reverse and forward, or only forward and stop? I ask because if you want it to have reverse, then an H-Bridge is what you are looking for. If it only goes forward, you might do as well or better with a fast acting relay, and lose the heatsink, MOSFETs and some of the confusion, you would likely still need a small switching transistor and a snubber diode. I know these bots are pretty small, and the space and weight saved might be useful for something else.
JS

Lilmanmgf
- 1st May 2007, 01:46
Yeah, it just needs to go forward and stop.

ALFRED
- 9th May 2007, 09:36
If you find MOSFETs confusing you may wish to use an H-Bridge IC. The SN754410 is a full H-bridge in a DIP package. I have successfuly used this chip to drive two motors forwards and backwards on a small robot. Heat dissipation has not been an issue. The operation of this chip is extremely easy to understand and the inputs can be driven directly from the PIC.
If you would prefer to put your own H-bridge together you should definantly use MOSFETs. If you are having trouble with the on gate voltage from the PIC being to low you may try to connect a pull-up resistor from the gate of the MOSFET to the positive supply (this is assuming you are still running off of 9v). The pull-up would bring the gate to a full 9v when the PIC signal goes high but when the PIC ouput goes low the gate would be driven low. You should test your ideas out on a breadboard and find what works best.
Hope this Helps.

CluckShot
- 15th May 2007, 01:44
here are a few tricks you may wish to try.
(1) MOSFETS love to be in parallel. This allows you to get the heat down a lot.
(2) Overdriving the control a bit on MOSFETS (50% or less) is generally safe and causes really fast response. Read the specs on you MOSFETS yours may be able to do this.
(3) Just for fun on the DC segment rather than killing the current entirely while running leave a modest few milliamperes hanging in the main drive coil at all times you are running the motor. It will drag the coil slightly but may affect current demand in the circuit a lot. This might well be worth the effort. This is a trick to prevent the collapse of the magnetic field in the coil of the DC motor. If it requires a voltage reversal, time this reversal when you are already into the next drive position some.

Josuetas
- 15th May 2007, 05:00
I didnīt read much of it, but you could do so many things!!.

First of all i would recommend a PWM always for this DC motors, they are really Current eaters, if the 16f84 donīt has it (it doesnīt) you can provide something with a simple timer, and a word counter. increase the counter on each interrupt an play with its value to decide if the pin goes HIGH or LOW. I really recommend to meet at last the 16f628 ;) you get so many more stuff that you will never go back to 16f84, youīll get for example a great PWM in one sentence.

I have in my hands the irf530 right now, it should make the work; I donīt have the greatest memory but i do remember that this Motor is an inductor and it will help you to use a diode (1n4004 or a Switcher if using PWM) to reduce peak currents on the level change from ON to OFF, you might have used this diode on relays for the same purpose.

If you canīt use different batteries for the motor and control (if you can then use an optocoupler) then be sure to add some capacitors to the uC Vcc-Vdd as close as possible (this is a classic one).

Donīt know if you are also using a Vreg if you are he is the one shutting down after heating.

Working with small batteries and getting power out of them is a real challenge, if you can go for a better source (you can usually do this for college asignments)

fazan83
- 15th May 2007, 09:08
I didnīt read much of it, but you could do so many things!!.

First of all i would recommend a PWM always for this DC motors, they are really Current eaters, if the 16f84 donīt has it (it doesnīt) you can provide something with a simple timer, and a word counter. increase the counter on each interrupt an play with its value to decide if the pin goes HIGH or LOW. I really recommend to meet at last the 16f628 ;) you get so many more stuff that you will never go back to 16f84, youīll get for example a great PWM in one sentence.

I have in my hands the irf530 right now, it should make the work; I donīt have the greatest memory but i do remember that this Motor is an inductor and it will help you to use a diode (1n4004 or a Switcher if using PWM) to reduce peak currents on the level change from ON to OFF, you might have used this diode on relays for the same purpose.

If you canīt use different batteries for the motor and control (if you can then use an optocoupler) then be sure to add some capacitors to the uC Vcc-Vdd as close as possible (this is a classic one).

Donīt know if you are also using a Vreg if you are he is the one shutting down after heating.

Working with small batteries and getting power out of them is a real challenge, if you can go for a better source (you can usually do this for college asignments)

I don't understand by what you guys mean PIC16F84a doesn't have PWM.
We can use the pulseout command right?

PULSOUT Pin,Period

I have create a robot using the DC servo motor using PIC16F84a and the Motor speed (modified DC motor) and position can be controlled using the PWM command.

To control DC Motor speed and to safe the power consumption we also can use the PWM method. But for DC motor we cannot easily control the angle of the rotation as the DC servo motor.

ra68gi
- 15th May 2007, 12:39
I don't understand by what you guys mean PIC16F84a doesn't have PWM.
We can use the pulseout command right?

PULSOUT Pin,Period

By PWM they mean hardware PWM module see data sheet of 16f8xx.
pic basic pro has got a command to use this its..
HPWM Channel, dutycycle, frequency.

PIC 16F84 does not have this hardware module so you can't use this command. But you do have a software pwm command..
PWM pin, duty, cycle. but the disadvantage is...
The PIC has to keep churning out pulses all the time not able to do other important things like adc measurement or rpm measurement etc which will be the feedback to control your motor. The second thing is the software pwm is only for a limited no of cycle & to keep it ON you need to give it or invoke the command again after the cycle is over.

Pulseout command is commonly used as clock or some cases in hobby projects to control servo motors. but in all these cases the micro is made to spend all its time only to generate pulse. Log on to rentron.com & you will find some nice examples to use pwm to fire IR leds.

Regards
Raghunathan.