Sie sind auf Seite 1von 2

Pulse Measurement

Sensors used for industrial and commercial control applicationsfrequently produc


e pulses that contain information about thequantity sensed. Varying the sensor o
utput frequency, using aconstant duty cycle but variable frequency pulses to ind
icatechanges in the measured variable, is most common. Varying theduration of the
pulse width, resulting in constant frequencybut variable duty cycle, is also us
ed. In this section, we examineprograms that deal with both techniques.
Measuring Frequency
Timers T0 and Tl can be used to measure external frequenciesby configuring one t
imer as a counter and using the secondtimer to generate a timing interval over w
hich the first cancount. The frequency of the counted pulse train is then:Unknow
n frequency = Counter/ timerFor example, if the counter .counts 200 pulses over
an intervalof .1 second gen-erated by the timer, the frequency is:UF = 200/.1 =
2000 HzCertain fundamental limitations govern the range of frequenciesthat can b
e measured. An input pulse must make, a I-to-Otransition lasting two ma-chine cy
cles, or f/24, to be counted.This restriction on pulse deviation yields a maximu
m frequencyo(500~ilohertz using our 12 megahertz crystal (as-suming asquare wave
input). The lowest frequency that can be counted islimited by the duration of t
he time interval generated, whichcan be exceedingly long using all the RAM to co
unt timerrollovers (65.54 milliseconds x 2"32768). There is no practicallimitati
on on the lowest frequency that can be counted.Happily, most frequency-variable
sensors generate signals thatfall inside of
0 to 500 kilohertz. Usually the, signals have a rangeof 1,000 to 10,000 hertz.A
timing interval of 1 second gener-ates a frequency count accurate to the nearest
1 hertz; an intervalof .1 second yields a count accurate to the nearest 10 hert
z.
FREQ
A program that measures an unknown frequency on pin 3.4(TO), named
freq,
is shown next. The unknown frequency iscounted in TO configured as a16-bitcounte
r. TO is reset andbegins counting the unknown frequency. A de-lay of .1 secondis
done, and Tstopped. The count in TO is the unknown fre-quency divided by 10.Tl
is used, in an interruptmode, as a timerwith an exact delay of .0001 seconds. Ba
nk 1 registerS RO andRl count 1,000 Tl interrupts to yield a delay of. 1 second.
TOand Tl are reset and enabled to count and time at T = 0 in theprogram. After
the .1 second delay is up, TO is stopped, andtcontents of TO displayed on PI (LS
B) and P2 (MSB).
LESSON 17:DESIGN CASE STUDY OF 8051
Pulse Width Measurement
Theoretically, if the input pulse is known to be a perfect squarewave, the pulse
frequency can be measured by finding the timethe wave is high (Th).
The frequency is then UF=1/TH*2
IMAGE
If Th is 200 microseconds, for example, then UF is 2500 hertz.The accuracy of th
e measurement will fall as the input wavedeparts from a 50% duty cycle.Timer X m
ay be configured so that the internal clock is countedonly when the correspondin
g INTX pin is high by setting theGATE X bit in TMOD. The accuracy of the measure
ment iswithin approximately one timer clock period, or 1 microsecondfor a 12 meg
ahertz crystal. This accuracy can only be at-tained if the measurement is starte
d when the input wave is low andstopped when the input next gbes low. Pulse widt
hs greaterthan the capacity of the counter, which is 65.54 milliseconds fora 12
megahertz crystal, can be mea-sured by counting theoverflows of the Timer flag a
nd adding the final contents in thecounter.The width of an unknown pulse is meas
ured byenabling a timer when the pulse generates an interrupt on oneof the INTX
pins. The interrupt is pro-grammed to occur on ahigh-to-low edge on the INTX pin
. The counter begins,counting when the unknown pulse goes high, enabling thecoun

ter to count when INTX goes high. The next pulse edgestops the counter. The coun
ter will contain the width of thepulse to the nearest microsecond for a 12 MHz c
rystal.
Width
A program, named width measures the width of a pulse fed topin 3.3 (INTI). Timer
Tl is enabled to count on the first pulseedge, counts when the pulse is high, a
nd stops on the secondedge. Ports PI (LSB) and P2 (MSB) show, in hex, the width
of the pulse in microseconds.
Notes

Das könnte Ihnen auch gefallen