Directly controlling Gearmotor with a PIC

I’m about to start my first robotic project (yes, very nooby) and I was hoping I could get some advice on how to directly control a 201:1 Micro Metal Gearmotor (item #1096) with a PIC microcontroller (ideally using PICBasic or PICBasic Pro code, as that’s what I use).

I’d like to use an H-Bridge so I can control the motor’s direction, but how do I control the speed? This simple code just turns on and off the motor (at full speed, I presume):

start:
pause 500
high 1 ' rotate motor in one direction
pause 1000
low 1 ' stop motor
pause 1000
high 0 'Rotate motor in opposite direction
pause 1000
low 0
goto start

Ideally, I’ll use a pot and buttons as inputs to change the speed and direction (unlike the sample above which just loops through changing the motor’s direction at what I presume is the full speed)

  • Can I use a PWN command to set the motor speed?
  • Apart from the capacitors connected across the motor leads, do I need any other type of components?

I have a Trex Jr controller but it seems like overkill for this simple need.

Any help would be much appreciated. I’ve tried looking for some sample PICBasic code here but didn’t find much, so any links to some sample code would also be great.

Hello,

Do you already have an H-bridge driver board or circuit that you plan to use? In general, PWM is often used with H-bridges to control the speed of a motor. I am not sure if any of us at Pololu has worked with PICBASIC much, and unfortunately, we do not have any guides or example programs for controlling a motor with PICBASIC. However, a Google search brought up this guide, which might serve as a decent starting point (although I have not looked at it too closely).

- Kevin

Thanks Kevin! I bought the motor controller mentioned in that doc (SN754410) from Pololu and I’ll be using that excellent tutorial to get me started.