292/317
10 - Second Application: a Sailing Computer
To achieve the required accuracy, a clocking frequency of at least 2.048 kHz is required, so as
to produce a count of 20 points or more at the highest speed, meeting the required resolution
of 5%.
10.2.1.3 Using a common timer for both speed measurement devices
In order to save one of the two timers for other purposes, we need to use only one timer for
both measurement devices above. This is no problem, since each 16-bit timer has two capture
inputs: each one can serve one of the above instruments.
We found above that each instrument implies a minimum clock frequency to achieve the re-
quired resolution. Actually, both also have a maximum clock frequency, if we want to keep the
measurements within the range of a 16-bit word. These limits are as shown in the table below:
We can see that there is a common area within these ranges, so that any clock between 30
kHz and 51.2 kHz would fit. Unfortunately, the lowest clock frequency that can be applied to
the input of the timer is the CPU clock divided by 8, that is 500 kHz using a 8 MHz crystal.
The solution consists in expanding the range of the timer to more bits by software, using the
interrupt on overflow. At that frequency, the timer would overflow less than eight times per
second, so the interrupt service routine would not overload the processor. The captured value
would then represent the low-order word of a 32-bit value, and the overflow interrupt would in-
crement the high-order word by one.
With that frequency, the formula to calculate the speed in knots is:
where
n
is the difference between two successive counts captured.
The fine-tuning of each of the devices, necessary to take into account the variation from unit
to unit, is done by varying the constant used in the formula. For this purpose, two trimmers are
connected to two analog inputs, and the value read is scaled so that the coefficients above are
Rounded clock frequency
(kHz)
Device
Minimum
Maximum
Speedometer
30.000
87.380
Wind gauge
2.048
51.199
Device
Formula
Speedometer
66666 / n
W ind gauge
390625 / n
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...