Controlling a Motor

Motor control is the task of controlling one or more aspects of a motor. Speed control is the goal in many motor control applications. Controlling a motor’s speed requires at least two steps:

  1. Calculating the motor's current speed.
  2. Running a control algorithm based upon the speed of the motor to determine what adjustments need to be made in order to achieve or maintain the desired speed.

Speed Measurement

Determining a motor’s speed is achieved by identifying when a rotor reaches a particular location, then determining how much time it takes for the rotor to return to the same position on the next rotation.

There are two methods of determining the location of a motor:

Sensored Feedback

When sensored feedback is used, a sensor is attached to the motor which then asserts digital signals as the rotor reaches a predetermined location. The MCU observes the sensor's output and calculates the motor's speed.

Hall effect sensors are frequently used on motors with magnetic rotors. Attached to the stator, the hall effect sensors signal the MCU when the rotors magnetic field is detected. Once asserted, the signal from a hall effect sensor stays high for 180 electrical-degrees. Using three hall effect sensors attached at 60 electrical-degree intervals provides the MCU with the ability to track the motor as it commutates through the electrical rotation (see the graph). Knowing the speed and relative position in the electrical rotation allows the MCU to be more responsive to changes in motor speed.


Some motors offer a quadrature encoder sensor. These sensors assert two signals which can be used to calculate both the location and the direction of the motor. Many dsPIC® DSCs have a Quadrature Encoder Input (QEI) peripheral which can perform the speed and direction calculations of QEI signals without using the CPU resources. When using the QEI peripheral, the speed of the motor is retrieved by reading an MCU register.

Sensored feedback requires the additional cost of sensor and cabling.

Sensorless Feedback

According to Faraday’s Law of Induction, electric motors act as both generators and motors. As the rotor moves through the magnetic stator field, a voltage is induced across the coils. This voltage opposes the original applied voltage and is called back Electromotive Force (back-EMF). The value of a motor’s back-EMF is dependent upon the speed of the rotor and its location within the field. The phenomena of back-EMF allows you to determine the location of the rotor by simply using the MCU’s Analog-to-Digital Converter (ADC) peripheral to measure the voltage of a winding which is not activated.

Filtering and reading the back-EMF allows the MCU to determine the location of the rotor.


The back-EMF voltage can also be connected to a comparator to trigger a digital input at a certain voltage (i.e. motor location).


Sensored feedback costs less but uses more CPU resources.

Control Algorithms

In closed-loop control applications, there are several algorithms that can be used to implement control. Among the most commonly used algorithms are the Proportional Integral (PI) and the Proportional Integral Differential (PID). Control algorithms and the parameters passed to them are used to model the expected behavior of the system being controlled.

The selection of the control algorithms and their parameters is typically under the purview of the mechanical engineering team and is the subject of much discussion in the motor control community. A considerable amount of time and effort is spent on fine-tuning the control algorithms and selecting the parameters. Microchip's motorBenchTM Development Suite supports the most common motor control algorithms and also provides an easy to use interface to allow fine-tuning of the algorithmic parameters.

Load Dynamics

Motor control has an additional concern not found in all control applications: the load dynamics. Depending upon the material the motor is moving, the force exerted on the rotor by the load will change with the speed of the motor. This variation is not always a linear function of the speed. Fans and pumps typically experience loads with non-linear load variations. Fine-tuning the parameters for an application, especially those with a variable load, is not a trivial task.

© 2024 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.