beautypg.com

Low-level analog input, Analog input in the background – Measurement Computing TempBook rev.3.0 User Manual

Page 34

background image

6-2 Standard API Programming of the TempBook with C

TempBook User’s Manual

Get 10 scans of channels 0 to 7, triggered by the pacer clock with a 1kHz sampling frequency and unity
gain, then print the scan data.

tbkRdScanN(0, 7, data2, 10, TtsPacerClock, 0, 1000, TgainX1);
sprintf(tempstr"\r\nResults of tbkRdScanN Channels 0 - 7:");
strcat (response, tempstr);

for (scan=0 ; scan<8 ; scan++){
sprintf(tempstr"\r\nScan %d: ", scan);
strcat (response, tempstr);

for (chan=0 ; chan<8 ; chan++){
sprintf(tempstr"%4d ", data2[(scan * 8) + chan]>4);
strcat (response, tempstr);
}
}

Low-Level Analog Input

The following excerpt from TBKEX.C shows the usage of several low-level analog input routines.

unsigned int buf[80], scan, chan;

Set the default operating mode to single-ended, bipolar. These parameters will affect all scanned channels.

tbkSetMode(0, 1);

Setup the scan sequencer for channels 0 to 7 with each channel in the scan at unity gain.

tbkSetMux(0, 7, TgainX1);

Set the scan frequency for 1kHz.

tbkSetFreq(1000);

Make the Pacer Clock the trigger source. This will also arm and trigger the system.

tbkSetTrig(TtsPacerClock, 0, 0, 1);

Read 10 scans of data into the language buffer buf, then print the 8 scan values.

tbkRdNFore(buf, 10);
sprintf(tempstr"\r\nResults of tbkRdNFore Channels 0 - 7:\r\n");
strcat (response, tempstr);

for (scan=0 ; scan<8 ; scan++)
{
sprintf(tempstr"\r\nScan %d: ", scan);
strcat (response, tempstr);

for (chan=0 ; chan<8 ; chan++){
sprintf(tempstr"%4d ", buf[(scan * 8) + chan]>4);
strcat (response, tempstr);
}
}

Analog Input in the Background

The following excerpt from TBKEX.C shows the usage of background acquisition functions. These
functions setup the TempBook to collect data in the background while your program continues to process
new lines of code in the foreground.

unsigned int data[80], chans[8], i, scan, chan;
unsigned chargains[8], polarities[8], active;
unsigned longcount;