driving a motor

Hi there,

building a robot, and need help:
a PIC gets PWM signal from an R/C Rx,
I’m not sure what is the best option for processing the signal,
for controlling a small DC motor.

option 1: simplifying it to something like:
if(channel_X > 127)
motor1 = 1;
motor2 = 0;

(you get the point)

plus using a motor driver.

option 2:another option is to keep it as PWM,
calculating the values for both engines,
the problem is later interpreting that PWM signal for the motors.
I know you can get that result using a transistor,
but I have no experience with that.

and I cant afford "Victor 884"s
any other suggestions?


Could you explain what tools do you use in this curcit? (motors, Victors, Spikes, etc…)

OK, I’m sorry if it’s not clear, (I shouldn’t post threads at those hours).

I’m using a small PIC 16f690 as a microcontroller,
I have 2 small everyday DC motors (those you find in RadioShack for around 0.5$)
my PIC receives a PWM signal from an R/C receiver,
and my problem is that I’m not sure which is the best way to control the motor,
I have explained 2 options above :slight_smile:

How small is small? Can you live with like 5A max drive, 1A or so continuous?

Do they need to go forwards AND backwards (please say no!). If they need FWD and REV operation, then you’ll need to build up a H-bridge… which if your motor currents are like the ones mentioned above, you’d be fine with something like a 15030 transistor or the like.

Does your pic device have any ECCP modules? If so, you can set up that module to run all four lines of a full bridge… if you just need to go up to 5A, you should be able to run the lines to the transistor’s bases straight out of the PIC.

Hope that gets you started…


Just checked, your chip has ONE eccp module, so… you can run up to two half bridges like that. See your datasheet for details on how to split the four output lines between two half-bridges.


You don’t mention what chip or circuit you have in mind to serve as the motor driver. Since a PIC typically outputs around 25mA on any given pin (enough for an LED, and actually a rather skookum output for a microcontroller, but nowhere near enough for a motor) you need to amplify that output signal somehow.

It can be done with discrete components… a transistor and such… but I have had very good luck using the L293DNE with my Engineering 11 students when we build our mini sumo robots. The cool thing about using this chip is that because it is an H-drive it now makes it very easy to drive the motors both “forwards” and “backwards”. You can even use it to do speed control if you set it up correctly.

That doesn’t mean the L293 is necessarily the best choice for you… it is rated to 600mA and works well with the small motors in the Tamiya Dual Motor Gearbox, but the 3953 can go higher. Other chips are also available… perhaps you have something in mind already.

Good luck with the project,


thank you Qbranch and dtengineering.
I decided to go with the L293DNE connected to the PIC (only X axis input)
I’ll be using the Tamiya Dual Motor Gearbox, so it’s OK, no need for anything
over 1A.

thanks a lot :slight_smile:

hmmmm those are some nifty chips dtengineering … think i might be using a few of those in my future… sometimes you do just need a little current, and that sure is the right price…



Thanks for the kind words Qbranch… and you should have good luck with the Tamiya gearbox and L293 3Dude… over the past five or six years we must have made more than 100 mini robots using this set up in my shop alone.

One issue that you might come across is that depending on what your power supply is, when you start the motor it may pull the supply voltage down below the minimum voltage that the PIC requires to operate. As soon as the PIC shuts down, so does the motor… the PIC reboots… tries to restart the motor… and, well… you can see a loop there. The solution we use is to put the logic voltage on one circuit (a 5v regulated 9V battery) and the drive voltage on another (4 x AA battery pack). This is far from the only solution, but this situation and solution is quite common… witness the backup battery for the RC on your team’s robot for the exact same situation.

I’ll attach an older .pdf of one of my handouts… some of the stuff is a bit out of date… we don’t use the 16f84a chip anymore, so the crystal and such aren’t necessary, but the last two pages have some info on how we hook up the electronics that should be relevant to your project.

I’ll also include a worksheet I give my students on the Sony IR protocol. Any Sony remote (or any multi-brand remote set to emulate a Sony) can easily be read by a PIC if you attach a PNA4602m (less than a buck each, if I recall) to one of the pins on the PIC and throw in a few lines of code.

You might find this a fun and cheap alternative to RC.

Have fun,


Worksheet 08 - Pic Control of a Mini-Sumo.pdf (440 KB)
Worksheet 11B - Sony IR Protocol and PIC Basic.pdf (77.1 KB)

Worksheet 08 - Pic Control of a Mini-Sumo.pdf (440 KB)
Worksheet 11B - Sony IR Protocol and PIC Basic.pdf (77.1 KB)

One thing you should add are 10K resistors on the pic IO’s to the motor chip. Check the spec sheet to make shure your version includes internal clamping diodes. The TI sn754410 does. If you are going to run the motors at close to full load get a clip on heat sink for the motor chip. You could add a diode for reverse battery protection. The pic chip mention I don’t believe has the capability of generating 2 PWM signals to control the motor speed . You would have to choose a pic with an ECCP. The other way to go is buy a motor control board that has a pic on it and comunicats with the pic chip by serial ttl commands. Some boards have current draw feed back and status monitoring. Check this link. http://www.pololu.com/products/elec.html#motocon

thanks you both dtengineering and Gdeaver, for your replies.

about the voltage, the PICs and the motors are fed seperatly,
so no worries here. :slight_smile:

and I know there are alternatives for the R\C sysytem,
but, I already have one, it’s handy, easy, and I have experience with it.
so, no worries here as well, (money IS an issue :smiley: ).

GDEAVER, thanks you,
I’m not getting near using full load,
actually, I’m working right now, choosing the best waveform to send to the motor driver.
It WON’T BE PWM, but something very similiar.


**Edit:**I thought of sending the motor-driver, a pulse of 10mS, every 30mS, (“1” for 10mS, then “0” for 20mS).
so it won’t have long peak times, nor motor-grinding-quick changes.
I used that as a reference, what do you think?