PWM DC Motor Controller for PIC12F683

DC Motor Controller


There are lots of designs on the Internet for DC power controllers using Pulse Width Modulation (PWM) to control the speed of a motor or power to a resistive load.  Most of these use analogue methods to generate the PWM signal which in turn drives a power MOSFET or transistor.

DC Motor Controller

When I wanted a speed controller for the PCB drill I use to make all my PIC Projects what else could I do but design a PWM Power Controller around a PIC – a practical PIC project for sure.

I came up with a fairly straightforward design based on a PIC12F683 using the Capture/Compare/PWM
(CCP) peripheral inside the PIC to generate a PWM output.  An ‘N’ Channel Logic Level MOSFET in a low side configuration is driven by the PIC to control the output power to the motor.

A variable resistor provides a voltage input to the PIC which is converted to a digital value using the onboard Analogue to Digital convertor, this in turn is used to set the PWM duty cycle.  Since the PWM duty cycle is adjusted using a voltage signal input to the PIC it is possible to use an alternative analogue front-end instead of VR1 to provide this voltage input and therefore control of the duty cycle.

In the original version of this project the input from the Analogue to Digital Converter (ADC) was fed directly to the duty cycle register of the PWM module on the PIC, therefore the PWM output duty changed linearly in direct proportion to the change in input voltage to the ADC; much the same as an analogue PWM.  The switch input allowed the PWM period to be selected in one of three ranges; 15.6Khz, 3.8Khz and 980Hz.

The significant feature in the new version of the firmware which sets it apart from analogue PWM is that it now uses the input from the ADC as an index to a data table.  This table contains the required output duty cycle and period.  By creating a suitable table of data you can map any value at the input of the ADC to any duty cycle and one of 3 fixed periods at the PWM output.

The switch input now cycles through 3 mapping tables.  The default tables supplied with the code have a one-to-one mapping of input voltage to duty cycle output and fixed periods of 15.6Khz, 3.8Khz and 980Hz respectively to keep it backward compatible with the original version of the code.

More details of this and example map table files can be found in the Operation section.

A push button cycles through three different mapping tables.  The mapping table in use is saved to EEPROM so it always powers up using the last selected table; an LED indicates the current setting.

There is also a digital control input that allows the output driver to be turned off.  When pulled low the PWM output is set to 0%.

Circuit Description

The PIC12F683, IC1 has an internal hardware PWM peripheral that is used to generate the PWM signal. The duty cycle of the PWM signal is controlled by VR1 which via R1 presents a voltage on pin 3 of IC1. With 0V on the input the duty cycle is 0% (off) up to 100% with 5 volts at the input. The PWM signal is output from pin 5 of IC1 and drives the gate terminal of Q1 through R3. Resistor R4 connects the gate terminal of Q1 to ground. This ensures that Q1 remains off when the circuit is first powered on as the I/O pins of IC1 are all set to inputs until the firmware initialises them as outputs. Diode D1 is required when driving inductive loads and provides a path for the inductive flyback current. For loads up to 3 amps Q1 does not require a heatsink, above this you may need to use one.

Read more: PWM DC Motor Controller for PIC12F683

Leave a Comment

Your email address will not be published. Required fields are marked *