Can the PIC12F675 drive motors directly from its GPIO pins?

As I mentioned in my previous post, my project student Kevin Chubb is developing tiny ultra low cost robots using a PIC12F microcontroller. One of the things that’s great about PICs is that they can source and sink relatively high current through their digital i/o pins. Kevin and I have been hoping that it might be possible to build a robot that powers its actuators directly from the microcontroller pins, so that was a big factor in choosing the PIC12F. Anyway, yesterday I received a package of tiny “coreless” motors in the post from AliExpress, so I’ve just carried out an experiment to see if they can be powered directly from the GPIO pins of a PIC12F.

I received two types of motors in yesterday’s delivery, but the ones I’m using in this experiment are these ones:

To begin with, I measured the current drawn by one of the motors when it was running unloaded at 3V, which turned out to be approximately 31 mA. Although that’s slightly higher than the rated pin current on the PIC12F (25 mA), I decided it was worth taking a chance and I set up an experiment with two of the motors connected directly to a PIC12F675. Here’s the video:

The complete code is used is shown below:

//
// PIC12F675 example: motors on GP4 and GP5
// Written by Ted Burke - 20-4-2017
//
// To compile:
//
//    xc8 --chip=12F675 main.c
//
 
#include <xc.h>
 
#pragma config FOSC=INTRCIO,WDTE=OFF,MCLRE=OFF,BOREN=OFF
 
void main(void)
{
    TRISIO = 0b11001111; // Make pins GP4 and GP5 outputs
    ANSEL  = 0b00000000; // Disable all analog inputs
     
    while(1)
    {
        GP4 = 1;         // Set pin GP4 high
        GP5 = 0;         // Set pin GP5 low
        _delay(500000);  // 0.5 second delay
        GP4 = 0;         // Set pin GP4 low
        GP5 = 1;         // Set pin GP5 high
        _delay(500000);  // 0.5 second delay
    }
}
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Can the PIC12F675 drive motors directly from its GPIO pins?

  1. Interesting… I’d be inclined to check the stall current drain of the motors too.
    Might be wise to add reversed diodes across the motors to protect the PIC from their back-EMF – 1N4148s or similar should do the trick.

    • batchloaf says:

      Yes, those are both good suggestions. However, what I was interested in doing here is seeing what I could get away with. I’m pretty sure the motor current exceeds the rated pin current even under moderate load, let alone when stalled. Adding the diodes would complicate things a bit because (assuming bidirectional motor control) there should be 4 diodes per motor (i.e. 8 in total). I know there must be voltage spiked happening, but I didn’t check how big they were. Anyway, surprisingly it seemed to function ok without the diodes. That mightn’t be true with more extensive testing though.

      Ted

Leave a reply to batchloaf Cancel reply