Design Idea
Circuit for measuring motor speed uses low-cost components
A microcontroller-based circuit provides both an LCD readout and an analog motor-speed output.
R García-Gil, J Castelló, and JM Espí, Escola Tècnica Superior d’Enginyeria, University of Valencia, Spain; Edited by Charles H Small and Fran Granville -- EDN, 11/8/2007
This Design Idea uses a microcontroller, a 16×2-key LCD, and a rotary encoder to measure and visualize the speed of a motor (Figure 1). You measure the rotor speed of the motor using an incremental encoder coupled to the motor shaft, which provides quadrature pulses with a frequency proportional to the rotor speed. The 1024-pulse rotary encoder is the RS-32-0/1024ER.11KB from Hengstler. You can calculate the rotational speed of the motor, ωR, by counting the number of revolutions that the encoder axis, nV, makes during a certain time period, tP. You calculate nV by counting the number of pulses, nP, that the encoder generates during this fixed period, tP: nV=nP/1024 for this encoder. And the rotational speed is

where δ=60/(tP×1024) rpm represents the resolution of the measured speed. To obtain a resolution of 1 rpm for this application, the fixed period you use as a timebase is 60/1024=58.59 msec. In this Design Idea, a low-cost microcontroller, the PIC16F873, IC1, from Microchip performs these operations. This microcontroller also drives the LCD, IC2, which shows the rotational speed in rotations per minute.
In a similar fashion to the circuit in Reference 1, you apply the quadrature pulses of the encoder to IC1’s RB0/INT input, which generates a high-priority interrupt at the rising edge of the pulse. These interruptions allow you to compute nP by increasing a counter, which initializes after it reaches fixed period tP. Moreover, the microcontroller’s internal 8-bit timer, Timer 0, registers tP, which generates a tM (timer interruption) each 286 µsec for a clock frequency, fCLK, of 14.3 MHz: tM=4×28/fCLK/4=286 µsec. This calculation means that fixing the timebase, tP, requires 205 timer interruptions (tP/tM). When the counter reaches this time, the count, nP, determines the rotational speed, according to the equation. Finally, this value appears on the screen of the LCD.
In addition, a digital-to-analog conversion is necessary if the control system must measure the rotational speed. You can do this conversion without adding an expensive DAC by applying a PWM (pulse-width-modulation) output of the microcontroller to a lowpass filter comprising R2, R3, C4, C6, and IC3. The frequency of the PWM signal is 20 kHz, and the cutoff frequency of the lowpass filter is 160 Hz, which is much lower than the PWM frequency. In this design, the maximum duty cycle of the PWM signal corresponds to a rotational speed of 1500 rpm.
You can download the source code for IC1’s program and assemble the software with MPLab from Microchip. You can alter constants within the software according to the encoder you use and your required resolution from the equation.
| Reference |
|














