3.3 Interrupt-Based AD Sample or Scan
Interrupt-based analog input operations are necessary when conversions must be performed at high sampling rates. They differ in operation from standard A/D samples and scans in that they perform a preset number of conversions per function call, rather than taking a single sample or scan. There are a number of different options that can be set for interrupt-based operations; these are explained in the interrupt-based operations chapter. The Universal Driver functions for A/D sample and scan operations are dscADSampleInt and dscADScanInt.
Create and initialize an A/D settings structure (DSCADSETTINGS).
Call dscADSetSettings and pass it a pointer to this structure in order to setup the driver for A/D operations.
Create and initialize an analog I/O interrupts structure (DSCAIOINT).
Initialize the sample_values buffer in the DSCAIOINT structure by allocating sufficient memory to store the results of the interrupt operations. The memory required is:
Memory = sizeof(WORD) * num_conversions
Call dscADSampleInt or dscADScanInt and pass it a pointer to the above-mentioned DSCAIOINT structure to begin interrupt operation. The interrupt operations will now run in a separate system thread until either they reach the maximum number of conversions specified (one-shot mode only) or they are cancelled by a call to dscCancelOp.
/* Step 1 */
// These are example values; your application will vary.
// See DSCADSETTINGS struct and hardware manuals for details.
dscadsettings.current_channel = 0;
dscadsettings.gain = GAIN_1;
dscadsettings.range = RANGE_5;
dscadsettings.polarity = UNIPOLAR;
dscadsettings.load_cal = 0;
/* Step 2 */
if ((result = dscADSetSettings(dscb, &dscadsettings)) != DE_NONE)
/* Step 3 */
dscaioint.num_conversions = 1024;
dscaioint.conversion_rate = 10000;
dscaioint.cycle = FALSE;
dscaioint.internal_clock = TRUE;
dscaioint.low_channel = 0;
dscaioint.high_channel = 3;
dscaioint.external_gate_enable = FALSE;
dscaioint.internal_clock_gate = FALSE;
dscaioint.fifo_enab = TRUE;
dscaioint.fifo_depth = 256;
dscaioint.dump_threshold = 512;
/* Step 4 */
dscaioint.sample_values = (WORD*) malloc(sizeof(WORD) * dscaioint.num_conversions);
memset(dscaioint.sample_values, 0, sizeof(WORD) * dscaioint.num_conversions);
/* Step 5 */
if ((result = dscADScanInt(dscb, &dscaioint)) != DE_NONE)
NOTE: Boards can only achieve interrupt rates that divide evenly into their onboard counters, so the driver will attempt to find the rate closest to that which you specified.