You are on page 1of 2

REAL TIME EMBEDDED SYSTEMS

LESSON 17:
DESIGN CASE STUDY OF 8051

Pulse Measurement
Sensors used for industrial and commercial control applications
frequently produce pulses that contain information about the
quantity sensed. Varying the sensor output frequency, using a
constant duty cycle but variable frequency pulses to indicate
changes in the measured variable, is most common. Varying the
duration of ‘the pulse width, resulting in constant frequency
but variable duty cycle, is also used. In this section, we examine
programs that deal with both techniques.
Measuring Frequency
Timers T0 and Tl can be used to measure external frequencies
by configuring one timer as a counter and using the second
timer to generate a timing interval over which the first can
count. The frequency of the counted pulse train is then:
Unknown frequency = Counter/ timer
For example, if the counter .counts 200 pulses over an interval
of .1 second gen-erated by the timer, the frequency is:
UF = 200/.1 = 2000 Hz
Certain fundamental limitations govern the range of frequencies
that can be measured. An input pulse must make, a I-to-O
transition lasting two ma-chine cycles, or f/24, to be counted.
This restriction on pulse deviation yields a maximum frequency
o(500~ilohertz using our 12 megahertz crystal (as-suming a
square wave input). The lowest frequency that can be counted is
limited by the duration of the time interval generated, which
can be exceedingly long using all the RAM to count timer
rollovers (65.54 milliseconds x 2"32768). There is no practical
limitation on the lowest frequency that can be counted.
Happily, most frequency-variable sensors generate signals that
fall inside of 0 to 500 kilohertz. Usually the, signals have a range
of 1,000 to 10,000 hertz.A timing interval of 1 second gener-
ates a frequency count accurate to the nearest 1 hertz; an interval
of .1 second yields a count accurate to the nearest 10 hertz.
FREQ
A program that measures an unknown frequency on pin 3.4
(TO), named freq, is shown next. The unknown frequency is
counted in TO configured as a16-bitcounter. TO is reset and
begins counting the unknown frequency. A de-lay of .1 second
is done, and Tstopped. The count in TO is the unknown fre-
quency divided by 10.Tl is used, in an interruptmode, as a timer
with an exact delay of .0001 seconds. Bank 1 registerS RO and
Rl count 1,000 Tl interrupts to yield a delay of. 1 second. TO
and Tl are reset and enabled to count and time at T = 0 in the Pulse Width Measurement
program. After the .1 second delay is up, TO is stopped, and Theoretically, if the input pulse is known to be a perfect square
tcontents of TO displayed on PI (LSB) and P2 (MSB). wave, the pulse frequency can be measured by finding the time
the wave is high (Th).
The frequency is then

© Copy Right: Rai University


72 3.375/3A.375/3B.375
If Th is 200 microseconds, for example, then UF is 2500 hertz. Notes

REAL TIME EMBEDDED SYSTEMS


The accuracy of the measurement will fall as the input wave
departs from a 50% duty cycle.
Timer X may be configured so that the internal clock is counted
only when the corresponding INTX pin is high by setting the
GATE X bit in TMOD. The accuracy of the measurement is
within approximately one timer clock period, or 1 microsecond
for a 12 megahertz crystal. This accuracy can only be at-tained if
the measurement is started when the input wave is low and
stopped when the input next gbes low. Pulse widths greater
than the capacity of the counter, which is 65.54 milliseconds for
a 12 megahertz crystal, can be mea-sured by counting the
overflows of the Timer flag and adding the final contents in the
counter.The width of an unknown pulse is measured by
enabling a timer when the pulse generates an interrupt on one
of the INTX pins. The interrupt is pro-grammed to occur on a
high-to-low edge on the INTX pin. The counter begins,
counting when the unknown pulse goes high, enabling the
counter to count when INTX goes high. The next pulse edge
stops the counter. The counter will contain the width of the
pulse to the nearest microsecond for a 12 MHz crystal.
Width
A program, named width measures the width of a pulse fed to
pin 3.3 (INTI). Timer Tl is enabled to count on the first pulse
edge, counts when the pulse is high, and stops on the second
edge. Ports PI (LSB) and P2 (MSB) show, in hex, the width of
the pulse in microseconds.

© Copy Right: Rai University


3.375/3A.375/3B.375 73

You might also like