By measuring motor current, you can monitor and control torque, manage load changes, and protect the motor from potential overload conditions. Effective current measurement also helps to maintain energy efficiency and prevent excessive heating.
Usually it is done in expensive industrial servo motors, electric car motors and anything that needs high performance and torque control.
But it can also be done on the simplest of DC motors with minimal hardware and software. In this guide, we will explain how to do it.
Controlling a DC motor is much simpler compared to stepper or BLDC motors. In a DC motor, speed is controlled by adjusting the DC voltage applied to it, and torque is controlled by varying the current. It doesn’t require complex feedback mechanisms or commutation techniques because the brushes automatically switch the current direction, keeping the motor spinning. This makes DC motors easier to control for tasks requiring variable speed and torque but without the need for precise positioning.
In contrast, stepper motors require precise control of current pulses to achieve accurate, incremental movements, which demands more complex electronics. BLDC motors need electronic commutation (often through feedback sensors) to control the rotor’s position, making them more efficient and suitable for high-speed applications but more challenging to control.
H-bridge to control the motor
To control a DC motor, we use an H-bridge circuit. For current measurement, a shunt resistor, called Rsense, is placed in line with the motor terminals.
To regulate the voltage at the DC motor’s terminals, we use PWM, which controls the switching of the H-bridge switches. By closing specific switches, we can change the motor’s direction. For example, if the motor is spinning in the forward direction, switches Q1 and Q4 are closed. Without PWM, the full voltage, , is applied across the motor terminals, causing it to spin at its maximum speed. PWM allows us to control the average voltage across the terminals, effectively adjusting the motor speed.
For smaller DC motors, drivers such as the DRV8251 or TB67H450FNG are often used. These drivers require only two PWM inputs: one controls Q1 and Q4, while the other controls Q2 and Q3. This setup enables efficient control over motor speed and direction.
Equivalent circuit of a DC motor
The equivalent circuit of a DC motor can be represented as a coil and resistor connected in series. The resistor represents the internal resistance of the motor windings, while the coil represents the motor's inductance.
When voltage is applied across the motor terminals, the current builds up over time due to the inductive element, creating a magnetic field that generates torque. This torque is what drives the motor shaft. Additionally, as the motor spins, it produces a back electromotive force (EMF), which opposes the applied voltage. This back EMF is directly proportional to the motor's speed and acts as a natural feedback mechanism, helping to balance the current and control the speed at steady state.
PWM and effect on inductance
When using PWM (Pulse Width Modulation) to control a DC motor, the inductance of the motor windings prevents the current from changing instantly in response to rapid switching. Instead, the current forms a sawtooth pattern, as it gradually ramps up and down with each PWM cycle.
This sawtooth waveform is due to the inductive nature of the motor, which resists sudden changes in current. The inductance effectively smooths the current waveform, reducing electrical noise and helping maintain consistent torque.
In this case, a higher switching frequency is generally better because it smooths the current waveform, resulting in more stable motor performance, reduced current ripple and less noise.
Average current is formed in that sawtooth pattern and it is represented with a dotted line on the image below.
In DC motor control, the motor armature current is directly related to torque production.
The motor torque equation is: T = Kt * Ia
where Ia is the armature current, which in terms of our DC motor equivalent circuit represents the average current. Kt is the motor’s torque constant (in Nm/A), which depends on the motor design. To precisely measure motor current, we need to sample it at the midpoint of the the ON time of our PWM period or OFF time of our PWM period as shown below.
To be able to do that it is best to use a center aligned PWM mode:
Why do i need to measure exactly in the middle of PWM period?
If you look at the image below, you can see a clear representation of the current ripple and the sawtooth waveform. As you can see, in both waveforms, the average current is the same, but the current ripple differs. If we measure our current at the midpoint of the ON or OFF cycle in both cases, we will get the same current value. However, imagine measuring at random points during the cycle—due to the high current ripple, our measurements could vary significantly and become unreliable. One solution would be to measure multiple points during the entire PWM period and average them. However, doing so would significantly reduce the bandwidth of our current loop.
What hardware to use to measure the current?
To actually measure the current, we need to use a bidirectional current sense amplifier because the motor’s current depends on whether it is spinning forward or backward, and whether it is acting as a motor or a generator. This means we will need to measure positive and negative currents! Amps like the INA240, INA241, or INA180 can be used.
The output of the amplifier will be fed to the ADC of our MCU, which can then use this value in the code.
Learn more and References:
- https://www.portescap.com/-/media/project/automation-specialty/portescap/portescap/pdf/whitepapers/wp_understanding_the_effect_of_PWM.pdf
- https://www.motioncontroltips.com/what-is-current-decay-in-a-stepper-drive/
- https://www.nxp.com/docs/en/application-note/AN2955.pdf