# AB-021 : Measuring RPM from Back EMF

### Introduction

Measuring the speed of a motor can be an important requirement for some applications. For example, DC and gearmotors that are moving loads may require close monitoring or adjustment of the output speed.

External sensors are typically used for speed measurements, such as Hall sensors with a magnet mounted on the shaft, or transoptors with a slotted plate (also mounted on the motor shaft).

These sensors that can give accurate information about motor speed, required space and increase cost of parts. Sometimes it’s impossible to add an external sensor to a motor due to space or pricing restrictions.

We can properties of the motor itself for a low-cost RPM measurement, which is based on the back EMF. In fact, the back EMF is a very important measurement for haptic feedback chips when driving vibration motors and LRAs.

We’ll explain a sensorless method, where we use an Analogue to Digital Converter which is onboard our microcontroller that generates the PWM drive signal. We haven’t included any additional measurement chips or components.

### What is Back EMF?

Back electromotive force (back EMF, BEMF) is a voltage that appears in the opposite direction to current flow as a result of the motor’s coils moving relative to a magnetic field. It is this voltage that serves as the principle of operation for a generator.

The back EMF is directly related to the speed of the motor, so knowing the value of back EMF allows us to calculate the speed of that motor.

Let’s review the brushed DC motor equivalent circuit:

Brushed DC Motor Equivalent

We can represent the motor as a series connection of resistance, inductance and the back EMF voltage source. It is this voltage source that we want to measure.

When the motor is powered from constant DC voltage and not running (i.e. rotor is stalled, or motor is starting) the only resistance to current flow is coil resistance. The inductance impedes the current when the voltage is not constant DC, for example when powered from a PWM source.

This resistance and inductance are very small by design, which explains why the start-up current of a DC motor is typically a few times greater than in normal operation. If the motor is stalled then the high current can destroy windings unless it is limited by external circuitry.

The role of the inductance is a little complicated to explain, so we will start by reviewing the equation which describes current through the coil $$I= \frac{dV}{dt}$$.

The inductance tries to preserve constant current in the circuit, so it only has an effect when there is a changing voltage i.e. $$\frac{dV}{dt} \neq 0$$. The inductance reduces the current’s rate of increase when a voltage is applied to the coil, then when that same voltage is disconnected the inductance generates a high voltage in an attempt to maintain the steady-state current value.

If a voltage is applied to a stalled motor, the inductance will reduce the current for a short time, however, the current will quickly reach a steady state value. When the current is non-changing, the inductance of the coils has no effect and the only limit to the current in the resistance of the coils.

Once the motor starts to rotate, the coils are switched on and off by the commutator. Immediately after a connection is made, the inductance of the coils slows down the rising current. After a disconnection, the inductance generates high voltage spikes.

When using PWM to control a motor, we observe voltage spikes when the gating transistor is switched off. This partly explains why high-frequency PWM can exhibit non-linear control characteristics, because a low duty-cycle at high frequency creates a narrow pulse in time. The rate of change of current is too small, and the current can’t rise fast enough to reach its steady state value.

In a stall condition, the coil inductance has much less influence on current than the coil resistance.

When the motor is spinning the back EMF has a much bigger influence on current than resistance and inductance.

As the back EMF is generated from the rotor is moving through the magnetic field generated by the permanent magnets, the back EMF is directly proportional to the motor speed, and the motor voltage constant. The motor voltage constant includes parameters like magnetic field strength which are also constant.

$$backEMF = \frac{RPM}{Kv}$$

Back EMF always acts to reduce the changing magnetic field through the coils. It does so by generating a voltage which opposes the supply voltage, thus reducing the current.

In ideal DC motor where R=0 and L=0, and RPM is constant with no load, back EMF will be exactly the same as the supply voltage.

### Back EMF vs RPM on the 106-002 DC Motor

We can calculate the back EMF by measuring the current in steady state with no load and comparing it to a calculated value for the stall current. We can then use this value with the no-load speed and the motor’s constants to calculate the speed for the given back EMF.

The 106-002 has the following properties:

Rated Voltage: 3V

N/L Current: 20mA

N/L Speed: 23,000 RPM

Coil resistance: 16 Ω

If the motor is stalled and is powered with rated voltage, the current through the windings is limited only by resistance:

$$I_{stall} = \frac{V_{supply}}{R}$$

$$\frac{3V}{16 \Omega} = 187.5mA$$

When the motor is rotating the back EMF works against the power voltage and thus reduces current to 20mA. Therefore the size of the back EMF is equal to the reduction in current times the terminal resistance:

$$V_{BEMF} = (I_{stall} – I_{N/L}) \times R$$

Substitute $$I_{stall}$$ from above:

$$V_{BEMF} = (\frac{V_{supply}}{R} – I_{N/L}) \times R$$

$$V_{BEMF} = V_{supply} – (I_{N/L} \times R)$$

$$V_{BEMF} = 3V – (0.02A \times 16\Omega)$$

$$V_{BEMF} = 2.68V$$

The back EMF constant $$k_{b}$$ is the relationship between the back EMF and the speed (converted to radians per second). At no load:

$$k_{b} = \frac {rads^{-1}}{V_{BEMF}}$$

$$k_{b} = \frac { ( \frac{23,000 \times 2\Pi ) }{60} ) } {2.68V}$$

$$k_{b} = \frac {2408rads^{-1}}{2.68V}$$

$$k_{b} = 898.7$$

And Speed Constant $$k_{s}$$

$$k_{s} = \frac{1}{k_{b}}$$

$$k_{s} = \frac{1}{898.7}$$

$$k_{s} = 0.001113$$

Remember these are both based on calculations from the back EMF – not the applied voltage (so appear inverted to the normal calculations for DC motor constants).

As the relationship is linear we can use these constants to calculate the speed of the motor for a measured back EMF.

Let’s check the values we have calculated, if the motor was turning at 12,500 RPM (1309 rads^(-1)) what would the back EMF and current be?

$$k_{b} = \frac {rads^{-1}}{V_{BEMF}}$$

$$V_{BEMF} = rads^{-1} \times k_{b}$$

$$V_{BEMF} = 1309 \times 0.001113$$

$$V_{BEMF} = 1.46 V$$

$$I = \frac{V_{s} – V_{BEMF}}{R}$$

$$I = \frac{3 V – 1.46 V}{ 16 \Omega }$$

$$I = 0.096 A$$

Now reading the Typical Performance Chart on the 106-002, at ~96 mA we can see the speed is ~12,500 RPM. We now have a way of calculating the back EMF and then in turn the speed of the motor from the measured current draw.

### Simple Hardware for BEMF Measurement

Let’s construct a simple circuit for measuring the back EMF of a DC motor. We’ve chosen the 110-003 with these parameters:

Rated Voltage: 1.3V

No Load Current @ 1.3V: 65mA

No Load Speed @ 1.3V: 9500rpm

Coil resistance: 3.2Ω

$$k_{b}$$ = 0.00158

Motor-powered from constant DC voltage source

We will use an ATmega168A microcontroller which will generate PWM signal for the 110-003 motor.

The MOSFET is switching the motor on by connecting motor negative terminal to ground. When the transistor is ON current from power supply flows through the motor to ground, and we can’t measure the back EMF.

When the transistor is OFF the motor negative terminal is floating, and back EMF measurement is possible. For measurement, we will use an Analogue to Digital Converter on the microcontroller, in addition to an oscilloscope so we have a visual representation of the behaviour.

Note that the back EMF voltage is in reference to the power supply but our ADC measure voltage is in reference to ground. When motor is stopped and back EMF = 0 our control voltage Vs = Vc. A lower value on the ADC input represents a high back EMF.

The oscilloscope is also connected to point Vs to measure back EMF with reference to ground as well as the ADC. Set the PWM frequency to 100Hz, although this is very low it gives more time for ADC conversion. Also note the supply voltage is 4.2V and rated voltage for 110-003 is 1.3V, therefore the PWM duty cycle shouldn’t be greater than 40%.

The 110-003 motor is started with a duty cycle of 12.5%, we can check the circuit through the oscilloscope:

On this screenshot, we can see a voltage spike when the MOSFET is turned OFF, after this spike the measured voltage is equal to Vc-Vbemf.

When the motor load increases (which we do manually), the speed decreases and back EMF signal is also lower.

### Back EMF Speedometer with Microcontroller

So now we measure the RPM using Atmega168, making use of the analogue to digital converter.

The measurement accuracy depends upon the microcontroller’s max PWM frequency and maximal pulse width. The ADC in the Atmega168 takes 13 ADC clock cycles, which is dependant upon the system clock and prescaler settings – it can’t be greater than 200kHz.

We use an internal RC clock 8MHz, so our maximal clock value is 125kHz (= 8MHz / 64). This gives an ADC clock period 8µs and minimal conversion time 13 * 8µs = 104µs.

The interrupt service routine also takes another few microseconds and some time is needed for the back EMF to stabilise, so we don’t measure the inductance spikes. Accounting for everything, the determine minimal pulse width must be greater than ~120µs for an 8MHz clock.

For PWM control we use Timer 1 as PWM generator and enable OCIE1A interrupt to trigger ADC measurement. For simplicity, ADC conversion is started immediately after OCIE1A interrupt but one or more of the first samples are rejected. This makes our routines simpler and gives time for back EMF stabilisation.

Here’s example code for the Timer 1 configuration on the ATmega168:

//------------------------ Init Timer 1 as PWM --------------------------------------------

void InitTimer1(void){

TCCR1A = (1<<COM1A1)|(1<<WGM11); // Toggle OC1A on compare 9Bit

TCCR1B = (1<<WGM12); // 9bit

TCCR1B = (1<<CS10)|(1<<CS11); // clk/64  8Mhz/64 = 125kHz    125kHz/9bit = 244Hz

TIMSK1 |= (1<<OCIE1A); // on compare to trigger ADC

OCR1A = 10; // initial pwm value

}

And the Analog to Digital Converter set-up routine:

//---------------------------- Init ADC ------------------------------------

void InitADC(void){

 ADCSRA  |= (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1);

// enable ADC, prescaller  8000000 hz / 64 = 125kHz

 ADMUX   |= (1<<REFS0);   // reference AVCC

 DIDR0    = (1<<ADC0D);  // disable digital input

}

For better accuracy, it’s good to average the measurement from a few samples, so our RPM reading frequency will be lower. This is important when using a PID controller for motor speed control, which can all be achieved with H bridge as the output stage.

If you’re interested in seeing the full code, it’s available for download in the link below. Although it is originally written for the 103-001, there is nothing that constrains it to this model and can easily measure the speed of other motors.  The results are sent using the USART to another device, of course, you may want to use the values directly on the ATmega168!

The only thing to note is that if you are using the PWM to power a motor from a different (and much higher) voltage source take special care that the back EMF won’t be too high for the ADC. Otherwise, you may end up damaging your microcontroller.