beautypg.com

Zero compensation example – Measurement Computing TempBook rev.3.0 User Manual

Page 54

background image

7-4 Software Calibration and Zero Compensation

TempBook User’s Manual

int tbkZeroSetupConvert ()

uint nscan

The number of readings in a single scan.

uint zeroPosition

The position of the zero reading within the scan.

uint

readingsPosition

The position of the readings to be zeroed.

uint nReadings

The number of readings per scan to be zero compensated.

uint *counts

The raw data from one or more scans.

uint scans

The number of scans of raw data in the counts array.

Zero Compensation Example

In this example, several TempBook channels will be read and zero compensated. 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. Also within the scan sequence, the TempBook’s internal shorted channel would be read once at
each gain used for channel measurement. Then, tbkZeroSetup and tbkZeroConvert (or
tbkZeroSetupConvert

) would be called once for each group of channels at a particular gain making

sure that the corresponding shorted channel reading for that gain is passed.

void main(void)
{

unsigned int data[9], chans[9], i;
unsigned char gains[9], polarities[9];
printf(“/nAdcex5.c/n”);

/* Initialize the channels, gains, and polarities arrays*/

chans[0] = 18;

/* Shorted channel */

gains[0] = TgainX1

/* Same gain as analog input channels */

polarities[0] = 1;

/* Bipolar */

for(i=0; i<8; i++)

{
chans[i] = i-1;

/* Analog input channels 0 - 7 */

gains[i] = TgainX1

/* Unity gain */

polarities[i] = 1;

/* Bipolar */

}

/*Set error handler and initialize TempBook */

tbkSetErrHandler(myhandler);
tbkInit(LPT1, 7);

/* Set the default operating mode to differential, bipolar */

tbkSetMode(1,1);

/* Set the scan sequencer */

tbkSetScan(chans, gains, polarities, 9);

/* Configure trigger source and issue software trigger */

tbkSetTrig(TtsSoftware, 1, 0, 0);
tbkSoftTrig();

/* Read the ADC data */

tbkRdNFore(data, 1);

/* Print the uncompensated samples using a 12-bit format.*/

printf(“/nResults of tbkRdNFore before zero compensation:/n”);
for(i=0; i<8; i++)

printf(“Channel: %2d Data: %4d/n”, i, data[i]>4);

/* Setup and perform zero compensation of the data */

tbkZeroSetup(9,

/* 9 readings within a scan */

0,

/* Shorted channel at position 0 */

1,

/* First reading to be compensated at position 1 */

8,

/* Compensate 8 readings per scan */

tbkZeroConvert(data, /*Pointer to array of readings */

1);

/* 1 scan in that array */