DC Motor Low Side Drive


Driving a DC (direct current) motor from a microcontroller can be very useful for rotational applications that do not require precision positioning. A useful example is controlling the speed of a cooling fan. This tutorial walks you through how to use the MPLAB® Xpress board to control a DC motor with a low side drive circuit.


Hardware Tools (Optional)

Tool About Purchase
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Windows Linux Mac OSX
Integrated Development Environment

Exercise Files

File Download
Windows Linux Mac OSX
Board Schematic


This project drives a DC motor with a PIC16F18855 microcontroller on the MPLAB Xpress Development Board.

The project uses the following hardware:

Useful Pre-Knowledge:


Step 1

This tutorial focuses on driving the motor in a single direction using low-side control, meaning the MOSFET is placed between the motor and ground. MOSFETs are nothing more than an electronically controlled switch. Because micro controller I/O pins generally cannot directly provide the current necessary to drive a motor, the MOSFET allows the microcontroller to control the current to the motor without directly supplying it. For more information you can refer to the application note AN898 "Determining MOSFET Driver Needs for Motor Drive Applications". The following schematic demonstrates the low-side control circuit used for this tutorial:


Pay attention to which of the MTP50N06V pins correspond to Gate, Drain, and Source. The Gate pin should be connected to pin RA4 through the 10 KΩ resistor. R1 is placed there as a current limiting resistor to protect the microcontroller, while R2 pulls the MOSFET gate LOW unless the microcontroller drives the gate HIGH. The Drain pin should be connected to a power supply. Finally, the Source pin should be connected to the positive terminal of the motor and the source of the diode.


Step 2

We will use the Pulse Width Modulation (PWM) module to control the gate of the MOSFET. Sending the 3.3 V signal from the PIC16F18855 to the gate of the MOSFET will turn ON the MOSFET allowing current to flow between the Drain and Source. The current flowing is proportional to the duty cycle value of the PWM signal.

From MPLAB Xpress IDE, click the MCC icon to open the Microchip Code Configurator. From there, choose the PWM6 module from under PWM in Device Resources:


The default settings for the module will work for this application.


Step 3

The PWM module needs a timer, and therefore we will use Timer2 for this application. Choose the TMR2 under Timer in Device Resources:


This will open the TMR2 configuration window. The timer period is changed to 100 ms. The Clock Source needs to be changed to FOSC/4. To change the period, we must also increase the Prescaler to 1:128. Check your settings with the completed window below:


Changing the prescaler value will change the Actual Period to 15.872 ms, which is reflected in the PWM module window below:



Step 4

These two modules are all that is needed to get the motor driving in one direction. Once the modules are set up, click generate. The software source and header files will be generated under Project in the MPLAB Xpress IDE:



Step 5

Generate a .hex file by clicking Make and Program Device


Program the MPLAB Xpress board by dragging the generated project .hex file from the downloads section of the browser and dropping the file onto the XPRESS drive.


The Programmer LED on the MPLAB Xpress board should quickly flash from green to red and then back to green indicating that the .hex file was successfully programmed to the PIC16F18855.


The MPLAB Xpress board will control the the gate of transistor Q1 and send a 50% duty cycle to rotate the motor at the fixed speed in one direction. To change the speed, the PWM signal needs to be changed. A smaller duty cycle will slow down the motor and a longer duty cycle will speed up the motor. This is caused by the averaging affect of the Q1 output signal.

To be able to control direction of the motor an H-Bridge drive circuit is recommended. The Bi-directional Motor Control page explains how to control direction with an H-Bridge setup.

© 2017 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.