311/317
10 - Second Application: a Sailing Computer
The three calibration parameters are read from the position of the three trimmers. The three
voltages are read and converted into the proper numeric values to work appropriately when
used in the calculations. These parameters are produced by the following function:
void InitCalibration ( void )
{
ADCSR = ( 1 << ADON ) | WIND_CALIB_CHANNEL ;
while ( ( ADCSR & ( 1 << COCO ) ) == 0 ) ;
/* Wait for end of
conversion */
WindFactor = ( ( ( (float)ADCDR - 128.0 ) / 640.0 ) + 1 ) *
NOMINAL_WIND_FACTOR ;
ADCSR = ( 1 << ADON ) | BOAT_CALIB_CHANNEL ;
while ( ( ADCSR & ( 1 << COCO ) ) == 0 ) ;
/* Wait for end of
conversion */
BoatFactor = ( ( ( (float)ADCDR - 128.0 ) / 640.0 ) + 1 ) *
NOMINAL_BOAT_FACTOR ;
ADCSR = ( 1 << ADON ) | VANE_CALIB_CHANNEL ;
while ( ( ADCSR & ( 1 << COCO ) ) == 0 ) ;
/* Wait for end of
conversion */
VaneAdjust = ( (signed char)ADCDR - 128.0 ) / 4 ;
}
The first two parameters vary from one end of the trimmer to the other end from 0.8 to 1.2
times the nominal calibration parameter. The second varies from -32 to +32 which represents
-45° to +45°.