You are on page 1of 5

1104 IEEE TRANSACTIONS ON INSTRUMENTATION A N D MEASUREMENT, VOL 38. NO 6.

DECEMBER 1989

Design of a High Performance Digital Tachometer


with a Microcontroller
RICHARD BONERT, MEMBER, IEEE

Abstract-The paper presents the design of a very flexible, low cost


speed evaluation system. The system provides a fast dynamic response
and a high accuracy over a wide speed range. The proposed design is
Encoder
capture i n p .
pulse acc.
1 speed
,signal
digital
suitable for a wide range of applications and can he integrated as part
of an existing tachometer assembly. Hardware requirements and ap-
propriate software structures for a microcontroller implementation are
discussed. The algorithm used to calculate the speed is based on the
0:
method of constant elapsed time. Finally the predicted performance is
verified experimentally. c l o c k 2 MHa speed
( 8 MHz crystal) signal
analog
I. INTRODUCTION Fig. 1. Tachometer configuration.

A DIGITAL tachometer consists of a shaft encoder and


electronic circuits as shown in Fig. 1. The output of
the shaft encoder provides electric pulses. The frequency
3) constant elapsed time (CET) [I],
4) pulse time measurement using a variable number of
of these pulses is proportional to the rotational speed. A counted pulses [2].
speed signal is obtained by processing the pulses from the The methods 1) and 2) are the same as used in any timer/
encoder using an additional electronic circuit. The direc- counter instrumentation. The methods 3 ) and 4) are a
tion of the speed can be evaluated using two quadrature
combination of encoder pulse counting and time measure-
pulses from the encoder. ment.
This paper proposes a new solution for the processing The CET method has the following advantages. It re-
of the pulses from the encoder to derive the speed signal.
quires a short measurement time which varies little
The solution takes advantages of new single chip low cost
throughout the speed range. Moreover, prior information
programmable microcontrollers. It is shown how' to use
pertaining to the actual speed range is not required, which
hardware and software combined with a suitable method
makes this method preferable to that of method 4).In ad-
for the speed evaluation to design a high performance
dition the CET method provides an optimal compromise
tachometer.
between resolution and measurement time, which cannot
Several methods can be used to derive the speed signal
be achieved with the simpler methods 1) and 2). A com-
from the encoder pulses of which the method of constant
parison of the CET method with the standard methods 1)
elapsed time provides the best performance. Details of this and 2) is provided in Table I.
method and competing methods are discussed in Sections
The performance standards used for comparative pur-
I1 and 111. Section IV discusses the hardware and software
poses are the maximum relative speed error A n / n of the
requirements for a single chip microcontroller speed eval- measured speed n , and the response time, at low and high
uation circuit and establishes the achievable performance
speed. The entries in Table I are calculated according to
and the limitations.
[I], assuming a count error of one pulse. The tachometer
Finally, a design example is given and experimental re- data used for the example are the same as used in the
sults are provided in Section V to illustrate the perfor-
design example.
mance of the digital tachometer.
111. THE CONSTANT ELAPSED TIME(CET) METHOD
11. SELECTION OF THE METHODOF SPEEDEVALUATION
The CET method is a combination of encoder pulse
The following known methods can be used to evaluate counting and time measurement. The time is measured by
the value of the speed:
counting clock pulses of the clock pulse period T,. The
1) direct pulse counting, measured time interval is selected such that it is larger
2) single pulse time measurement [ 3 ] , than or equal to the desired CET T,,, and that it contains
an integer number of encoder pulses.
Manuscript received December 12, 1988; revised May 9, 1989. The basic counting process is shown in Fig. 2(a). The
The author is with the Department of Electrical Engineering, University
of Toronto, Toronto. Ont., Canada M5S 1A4. pulse counter and the time counter are both started at a
IEEE Log Number 8930978. rising edge of the encoder pulse. The counters are stopped

0018-9456/89/1200-1104$01.OO 0 1989 IEEE

Authorized licensed use limited to: UNIVERSITAS GADJAH MADA. Downloaded on November 27,2023 at 13:57:53 UTC from IEEE Xplore. Restrictions apply.
BONERT: DIGITAL TACHOMETER WITH A MICROCONTROLLER 1105

starta I stop started. If the encoder pulse length exceeds the time T,,
rising edge I pulse counter I pulse counter

the speed signal is set to be zero. The speed at which the


measured signal is set zero can be called the “minimum
:(-------- T ________
>I I
measurable speed” nminwithin a given maximum re-
:<start end>; next rising edge sponse time. This minimum measurable speed is a prop-
const. time interval of encoder pulse
atop8 counting erty of all digital tachometers and is defined as

b) read Cpl disable read C disable nmin = 1/(Tmax + m ) . (4)


interrupt I P2 interrupt
IV. PRINCIPLE IMPLEMENTATION OF THE SPEED
EVALUATION CIRCUIT
It g A . Acquisition of the Time Interval and Pulse Count
-t , _--” I read Ct
enable int. wt. enable int.
It is not necessary to repeatedly restart and stop the en-
Fig. 2 . Method of CET operation of counters.
coder pulse counter and the time counter when imple-
menting the CET method. Repetitive starting and stop-
TABLE I ping is rather disadvantageous in that it requires a
RELATIVE
ERROR
A n / n A N D RESPONSE
TIMEOF DIFFERENT
SPEED
EVALUATION METHODS reinitialization of the counters. This process takes time
and reduces the sample rate of the speed measurement
An In Pulse Counting Pulse Time Measuring CET system.
at 30 rpm 85.0 % 0.025 % 0.025 %
A better approach is to measure time intervals at a con-
at 3000 rpm 0.85 % 2.5 % 0.05 % tinuously running time counter and to read the incre-
response time mented pulse counter at the end of each time interval. Fig.
2(b) shows the timing diagram for this approach. At a
at 30 rpm 2.3 ms 1.95 ms 1.95 ms rising edge of the encoder pulse the time t l is registered
at 3000 rpm 2.3 ms 0.02 ms 1.02 ms
and the value Cpl of the encoder pulse counter is read.
After the minimum response time T,, has elapsed, the next
by the first rising edge of the encoder pulse occurring after rising encoder edge will register the time t2 and the value
the CET interval T,, . The content of the pulse counter is C of the pulse counter. The speed can then be deter-
f2
then C, which is the number of encoder pulses measured. mined using (3) with C, being the difference of the read-
The content of the time counter is C,, which is the number ings of the time counter at time t2 and time t , , and with
of time clocks measured. Cp being the difference between Cp2and Cpl.
The rotational speed can be calculated from the quo- As the clock period of the time counter is typically less
tient A 4 / A t . A 4 is the increment of the rotational angle than a microsecond, the reading of the time count has to
during the time interval A t , where be implemented by a hardware function. Several micro-
controllers provide such a hardware function in the form
A 4 = Cp * 2 * r/m (1) of a free running counter and capture registers. Capture
registers store the count in the free running counter at a
A t = C, T, (2) rising edge of a selected external signal. The encoder
and m is the number of encoder marks per turn. pulses are counted with a pulse accumulator. A pulse ac-
Using (1) and (2) the rotational speed n can be calcu- cumulator is a standard feature of many microcontrollers.
lated as follows: The basic concept to measure the time interval and to
count the encoder pulses can be described as follows.
n = C p / ( C t. m *(3)T,).
Upon recognizing a rising edge the capture register saves
Considering the measurement process, it is clear that the content of the time counter and generates an interrupt.
the measurement or response time A t changes in relation The interrupt service routine takes the reading of the en-
to the measured speed. The widest variation in response coder pulse counter and subsequently disables the capture
time is less than 1 : 2, as long as the duration of an encoder register function until the time T,, has elapsed. Thereafter
pulse period is less than the time T,, . the capture register function is enabled again in order to
At very low speed the duration of an encoder pulse in- respond to the next rising edge of the encoder pulse.
creases and exceeds finally the usual variation in response
time of 2 * T,, . Consequently, at this low speed the CET B. Limitation at High Speed
method is identical to the single pulse time measurement Reading the encoder pulse counter and disabling the
method 2). capture register function is done by software in an inter-
If the speed goes to zero the encoder pulse length and rupt service routine. The time available for the execution
the resulting response time go to infinity. As a practical of these tasks is the encoder pulse period. This comes
control system requires a response within a certain time, about as a result of the capture register function having to
a maximum response time Tmaxis defined, in which a ris- be disabled before the next rising edge occurs. This time
ing pulse edge has to occur after the counters have been constraint determines the maximum encoder pulse fre-

Authorized licensed use limited to: UNIVERSITAS GADJAH MADA. Downloaded on November 27,2023 at 13:57:53 UTC from IEEE Xplore. Restrictions apply.
1106 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 38, NO. 6, DECEMBER 1989

quency, and therefore, the maximum speed which can be


processed. This limit will typically be higher than 90 kHz
for standard microcontrollers.
tZ It3
s t a r t or Tnax expired speed
C. Initialization Below Minimum Measurable Speed and stand still speed = 0 calculated

at Stand Still Fig. 3. Start up or acceleration from below minimum speed or stand still.

Below the speed nmina speed signal cannot be deter-


mined within the maximum response time T,,,. This par-
ticular case is illustrated in Fig. 3.
I START
set INIT FLG I
At operation below nminor at start up the tachometer capture function
circuit waits for a rising encoder pulse edge to initialize and interrupt
disabled
the counter values. The counters are initialized at the ris-
ing edge occurring at time to (Fig. 3). After initialization I I J I
set I
the time T,, elapses and the circuit waits for the next rising I

edge to read the counters. As no further edge occurs be- -


6
INIT FLAG ? set
L
fore T,,, expires, no speed can be determined and a new A SPEED
initialization of the counters is required. This new initial- P L
so
ization occurs at time t , . After the time T,, elapses, at time E O
D P
t 2 , the circuits waits again for a rising edge to read the
counters. This rising edge occurs at time t3 before Tmax T Tel ELAPSED
I
expires. Following this a speed signal can be calculated.

D. Calculation of the Speed Value


Speed can be calculated using (3). For accuracy rea-
I I ENABLE CAPTURE

sons, a 16-bit wordlength is used and the algorithm is ex-


interrupt service
ecuted in such a way as to minimize the truncation errors. routine
The necessary calculations can be quite readily completed interrupting WAIT LOOP
in real time during the time T,, , as the execution time for READ PULSE COUNTER 1
DISABLE CAPTURE
the calculations for a typical microcontroller is less than
half a millisecond. RESET WAIT FLAG

E. Program Structure
Fig. 4. Principle structure of the tachometer program.
The program structure for evaluating the speed is shown
in Fig. 4. The program executes a wait loop. This loop
can be interrupted by a rising encoder pulse edge. If no calculation. Software execution time effects only the max-
edge occurs within the maximum response time T,,,, the imum measurable speed as described.
speed value is set to zero and the INIT FLAG is set. The The program will wait most of the time in the elapsed
INIT FLAG indicates that the next rising encoder pulse time loop at point B shown in Fig. 4. This time can be
edge will initialize the counters to start a speed measure- used for other tasks, for example, to communicate the
ment interval. speed value to other processors, to do additional speed
The exit of the wait loop occurs subsequent to a rising related calculations, or to provide values for a display.
encoder pulse edge. On the occurrence of a rising edge
the content of the free running timer is stored by the cap- V . ILLUSTRATED EXAMPLE OF A TACHOMETER DESIGN
ture register and an interrupt is generated. The interrupt A tachometer utilizing an encoder with 1024 marks per
routine reads the pulse counter, disables the capture func- turn and a microcontroller type 6 8 H C l l was built. The
tion, and further interrupts and resets the WAIT FLAG. specification for the maximum response time and elapsed
The WAIT FLAG facilitates the exit from the wait loop time are 2.3 and 1 ms, respectively. The choice of the
to the elapsed time loop, as shown in Fig. 4. maximum response time results in a measurable minimum
The elapsed time loop starts the timing of T,, and T,,, speed of 25.5 rpm.
based on the last time counter reading. A speed value is The 2-MHz processor clock is used for time counting.
calculated, if the system was initialized. After the time This provides a time increment T, of 0.5 ps. The mini-
T,, elapsed, the loop is terminated and the capture register mum time required to read the pulse counter was found to
function and the interrupt are again enabled. be 12 ps, which limits the maximum measurable speed to
The proposed program structure ensures that initial- 4883 rpm. The speed range of the tachometer is, there-
ization occurs without delay and is only required below fore, 25.5-4883 rpm or 1 : 190.
minimum measurable speed. The execution time of the The direction of the speed is determined by feeding a
statements has no influence on the accuracy of the speed quadrature pulse of the encoder to a strobed port of the

Authorized licensed use limited to: UNIVERSITAS GADJAH MADA. Downloaded on November 27,2023 at 13:57:53 UTC from IEEE Xplore. Restrictions apply.
BONERT: DIGITAL TACHOMETER WITH A MICROCONTROLLER 1107

Fig. 5. Experimental Result: showing the measured speed as function of


time for a speed reversal from 800 to -800 rpm.

microcontroller. The speed output at the microcontroller


is in signed 12-bit code. This output signal is connected
to a bipolar D/A converter. Fig. 1 illustrates the connec-
tions between the components of the tachometer.
j
The error of the tachometer is determined by the error
in the measurement of the increment of the rotational an-
gle A + , the error in A t , and the calculation error. The
maximum relative error for A t based on one missing count
is 0.05 percent. It is determined by T,/T,, . The maximum
relative error in A+ caused by nonequidistant encoder I 1 25ms I
pulses was specified according to the information of the
manufacturer to be 0.07 percent. The calculation error due
c I ~I
to truncation is 0.003 percent. Summing up all these er-
rors results in a total maximum relative error of 0.123
,
percent, which is mainly caused by the encoder. - - - - - I d

The error for A t decreases to 0.02 percent and the speed Fig. 6 . Experimental results, detail A from Fig. 5.
range extends to 1 :406, from 12 to 4883 rpm, if the
elapsed time T,, is chosen to be 2.5 ms.

DETAIL B
A . Experimental Vuijication
The shaft encoder was mounted to a 5-hp dynamometer
which was coupled by a drive shaft to a 3-hp dc motor tI
with a rated speed of 1000 rpm.
To demonstrate the performance of the tachometer the
speed of the dc motor operating initially at approximately
25.6 rpm ' 1
J

800 rpm was suddenly reversed to - 800 rpm. The change


of the speed as a function of the time was observed with
0 rpm
-6.25 ms
a digital oscilloscope connected to the output of the D/A
converter and recorded on a digital plotter. The measured
results are shown in Figs. 5-7.

B. The Experimental Results


Fig. 7. Experimental results, detail B from Fig. 5.
Fig. 5 shows the speed reversal from 800 to -800 rpm.
Zero speed is reached within 200 ms. The fast reversal
excites mechanical oscillations in the motor dynamometer The details of the oscillation as shown in Fig. 6 dem-
system at the beginning of the transient. To demonstrate onstrate the high resolution of the digital tachometer. Fig.
details of the tachometer performance Figs. 6 and 7 show 7 illustrates the properties of the tachometer at low speed.
enlarged sections of Fig. 5 marked with A and B . Moreover this figure verifies that the response time at very

Authorized licensed use limited to: UNIVERSITAS GADJAH MADA. Downloaded on November 27,2023 at 13:57:53 UTC from IEEE Xplore. Restrictions apply.
1108 IEEE TRANSACTIONS ON INSTRUMENTATION A N D MEASUREMENT. VOL. 3X. NO. 6. DECEMBER 1989

low speed increases to the maximum allowed response encoder becomes the critical factor in determining the
time of 2 . 3 ms. The figure shows that the speed output overall achievable accuracy of the tachometer system.
drops to zero as soon as the measurable minimum speed The proposed circuit could in future be integrated to-
of 25.5 rpm is reached. gether with the pulse shaping circuitry into the encoder
housing thus providing a compact tachometer unit. More-
over, if a D/A converter is also integrated, the unit would
VI. CONCLUSIONS emulate a dc tachometer.
The proposed concept for a digital tachometer provides
REFERENCES
a meed measurement svstem with high accuracv and ex-
v

cellent dynamic perfomance. The concept only one 111 R. Bonert, “Digital tachometer with fast dynamic response imple-
mented by a microprocessor,” IEEE Trans. Ind. A p p l . , vol. IA-19,
single chip low cost microcontroller and the CET method. pp. 1052-56, 1983,
It is easy to achieve a speed range larger than 1 : 400 [2] G. F. Pierce, “Frequency determining apparatus,” Canadian General
with a response tirne of less than 5 ms, and a relative Electric Company, Canadian Patent 1144 986, 1983; U . S . Patent
4 420 809.
Of the ’peed Of less than 0.02 percent. With 131 J . Duennwald, “Digitale Drehzahlerfassung elektrischer Antnebe mit
this low error in speed evaluation the accuracy ofthe shaft Mikrorechner,” Tech. Mes., Heft 3 , 1981.

Authorized licensed use limited to: UNIVERSITAS GADJAH MADA. Downloaded on November 27,2023 at 13:57:53 UTC from IEEE Xplore. Restrictions apply.

You might also like