Calibration setup and conversion, Calibration example – Measurement Computing TempBook rev.3.0 User Manual
Page 52

7-2 Software Calibration and Zero Compensation
TempBook User’s Manual
Calibration Setup and Conversion
Once the cal constants have been read from the cal file, they can be used by the tbkCalSetup and
tbkCalConvert
functions. The tbkCalSetup function will configure the order and type of data to be
calibrated. This function requires all data to be calibrated to be from consecutive channels configured for
the same gain, polarity and channel type. The calibration can be configured to use only the gain calibration
constant and not the offset constant. This allows the offset to be removed at runtime using the zero
compensation functions described later in this chapter.
int
tbkCalSetup ()
uint nscan
The number of readings in a single scan.
uint readingsPos
The position of the readings to be calibrated within the scan.
uint nReadings
The number of readings to calibrate.
uint chanType
The type of channel from which the readings to be calibrated are read. This
should be set to 1 when calibrating a CJC channel and 0 when reading any
other channel.
uint chanGain
The gain setting of the channels to be calibrated.
uint bipolar
Non-zero if the TempBook is configured for bipolar readings.
uint noOffset
If non-zero, the offset cal constant will not be used to calibrate the readings.
The tbkCalConvert function performs the actual calibration of one or more scans according to the
previously called tbkCalSetup function. This function will modify the array of data passed to it.
int
tbkCalConvert ()
uint *counts
The raw data from one or more scans.
uint scans
The number of scans of raw data in the counts array.
For convenience, both the setup and convert steps can be performed with one call to
tbkCalSetupConvert
. This is useful when the calibration needs to be performed multiple times
because data was read from channels at different gains.
int
tbkCalSetupConvert ()
uint nscan
The number of readings in a single scan.
uint readingsPos
The position of the readings to be calibrated within the scan.
uint nReadings
The number of readings to calibrate.
uint chanType
The type of channel/board from which the readings to be calibrated are read.
This should be set to 1 when calibrating a CJC channel and 0 when reading
any other channel.
uint chanGain
The gain setting of the channels to be calibrated.
uint bipolar
Non-zero if the TempBook is configured for bipolar readings.
uint noOffset
If non-zero, the offset cal constant will not be used to calibrate the readings.
uint *counts
The raw data from one or more scans.
uint scans
The number of scans of raw data in the counts array.
Calibration Example
In this example, several TempBook channels will be read and calibrated. This example assumes that the
calibration file has been created according to the initializing calibration constants section of this chapter.
Although all of the channels in this example are read at the same gain, the same principles apply to
calibration of channel readings at different gains. In that situation, channels to be read are grouped by gain
within the scan sequence. Then, tbkCalSetup and tbkCalConvert (or tbkCalSetupConvert)
would be called once for each group of channels at a particular gain.
void main(void)
{
unsigned sample, buf[10], data[8];
int i, scan, chan;
printf(“/nAdcex4.c/n”);
/* Set error handler and initialize TempBook*/
tbkSetErrHandler(myhandler);
tbkInit(LPT1, 7);