300/317
10 - Second Application: a Sailing Computer
10.5 PROGRAM ARCHITECTURE
The program performs the following tasks:
Read the values of wind speed and direction and boat speed
Compute the absolute values and the VMG
Display these values
On request from the PC, send the appropriate data
The values based on frequency are read from the timer and converted in an interrupt service
routine each time a capture is performed.
The display, as explained above, must be refreshed at precise intervals. It is controlled by a
periodic interrupt service routine triggered by a timer. This routine also performs the reading of
the wind direction through the Analog to Digital Converter, and the low-pass filtering of the
value to both increase resolution and reduce instability.
The serial interface is entirely driven by an interrupt service routine triggered by the inputs and
outputs of characters to or from the PC.
10.5.1 Reading and conversion of the speeds
As explained earlier, the wind and boat speeds are both input as a square wave with a variable
frequency that is proportional to the speed. The frequencies are too low to be able to measure
them by counting the periods in a sufficiently short time. This is why in this application the
speeds will be calculated from the inverse of the period duration. Actually, this conversion will
be done in the calculation block, for an interrupt service routine must be fast and division is the
longest of all arithmetic operations.
The timer has a provision for triggering an interrupt request when either of its capture inputs
has received an active transition. The interrupt service routine will check the Status Register to
direct the reading to either the boat speed or the wind speed. If the interrupt cause is the over-
flow, the high words of both capture values are incremented.
Since in the 72311, only Timer B has two capture inputs, the boat speed will be connected to
ICAPT1_B and the wind speed to ICAPT2_B. The code is the following:
#pragma TRAP_PROC SAVE_REGS
void TimerBInterrupt ( void )
{
tCapture Capture1, Capture2 ;
static LWord LastCapture1, LastCapture2 ;
if ( TBSR & ( 1 << ICF1 ) )
/* Is this is a capture 1 interrupt ? */
{
/* yes */
asm
{
Содержание 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 ...