Sample programs, High-level analog input – Measurement Computing TempBook rev.3.0 User Manual
Page 40

6-8 Standard API Programming of the TempBook with C
TempBook User’s Manual
tbkSetTrig(TtsSoftware, 1, 0, 0);
Configure and perform Thermocouple Linearization with block averaging on the raw ADC counts. The raw
counts are in the data buffer, data. The converted temperature values will be returned in the buffer temp.
With block averaging enabled one temperature, the average of all 100 scans, will be returned for each
channel.
tbkTCSetup(11, 2, 8, TbkTypeJ, 1, 0);
tbkTCConvert(data, 100, temp, 8);
The converted temperatures can now be printed to the screen.
for (i=0 ; i<8 ; i++){
sprintf(tempstr, "%8.1f ", (float)temp[i] / 10.0);
strcat(response, tempstr);
}
sprintf(tempstr, "\r\n");
strcat(response, tempstr);
SendDlgItemMessage(myDlg, 101, WM_SETTEXT, 0, (LONG)(LPSTR)response);
EmptyMessageQueue(myDlg);
Sample Programs
High-Level Analog Input
/***********************************************
File:Adcex1.c
Description:This example demonstrates the use of TempBook/66s highest level
ADC functions. These functions have combined scan sequencer setup and ADC
data collection.
Functions Used:tbkRd(unsigned chan, unsigned *sample, unsigned char gain)
tbkRdN(unsigned chan, unsigned *buf, unsigned count, unsigned char trigger,
unsigned char oneShot, float freq, unsigned char gain) tbkRdScan(unsigned
startChan, unsigned endChan, unsigned * buf, unsigned char gain)
tbkRdScanN(unsigned startChan, unsigned endChan, unsigned * buf, unsigned
count, unsigned char trigger, unsigned char oneShot, float freq, unsigned
char gain)
***********************************************/
unsigned sample, buf[10], data[7], data2[80];
int i, scan, chan; sprintf(response,"\r\nAdcex1.c\r\n\r\n");
/* Set the default operating mode to single-ended, bipolar */
tbkSetMode(0, 1);
/* Get 1 ADC sample from channel 0 at unity gain. */
tbkRd(0, &sample, TgainX1);
/* Print results using a 12 bit data format */
sprintf(tempstr,"Result of tbkRd : %4d\r\n\r\n", sample>4);
strcat(response,tempstr);
/* Get 10 samples from channel 0, trigged by the pacer clock with a */
/* 1000 Hz sampling frequency at unity gain. */
tbkRdN(0, buf, 10, TtsPacerClock, 0, 1000, TgainX1);
/* Print the results using a 12 bit data format */
sprintf(tempstr,"Results of tbkRdN:");
strcat(response,tempstr);
for(i=0;i<8;i++) {
sprintf(tempstr,"%4d ", buf[i]>4);
strcat(response,tempstr);
}
/* Get 1 sample from channels 0 through 7 at unity gain. */