{ ***************************************************************************** PASCAL LANGUAGE SAMPLE 4: SAMPLE4.PAS The following program demonstrates the use of driver task 19, Multiple Conversions with Analog Trigger. In this sample, point 0 in the point list is used to trigger A/D conversions. The program makes four calls to the task to demonstrate high-side and low-side triggering on both bipolar and unipolar ranges. LAST MODIFICATION: 2/4/98 ***************************************************************************** } USES Crt; {$L A12GDRV.OBJ} {$F+} procedure a12gdrv(task,params,statcode:integer);external; { These variable MUST be declared as global. They are the ones whose offsets are passed to the A12GDRV routine. If they are not global then the driver will not find their segment. } VAR statcode,task : word; param : array[1..5] of integer; datbuf : array[1..24] of integer; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (0000-FFFF) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if (error=0) then begin Success := 1; Dummy := NewOne; end else if (Msg = '') then begin GotoXY(AddrInputPosX, AddrInputPosY); WriteLn(OldOne); Msg := OldOne; Success := 1; Val('$' + Msg, Dummy, Error); end; until (Success = 1); AskForBaseAddress := Dummy; end; { end of AskForBaseAddress } { ***************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a12gdrv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ***************************************************************************** } FUNCTION call_driver:integer; VAR Char_Input : char; BEGIN { this section extracts the offset of the parameters that we will pass to the assembly driver } a12gdrv(ofs(task),ofs(param[1]),ofs(statcode)); { this section checks for an error code } call_driver := statcode; if statcode > 0 then begin if keypressed then Char_Input := Readkey; WriteLn('TASK ',task,' has returned an error code of ',statcode,'.'); WriteLn('Press ''C'' to continue, any other key to exit.'); Char_Input := UpCase(Readkey); If Char_Input = 'C' Then call_driver := 0 Else call_driver := statcode; end; END; { end call_driver } { ***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package, with the first 16 point addresses. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ***************************************************************************** } FUNCTION setup:INTEGER; VAR ch:char; status:word; Address:word; BEGIN ClrScr; WriteLn(' SAMPLE4.PAS : AD12-8G DEMONSTRATION DATA ACQUISITION '); WriteLn; WriteLn('The following program demonstrates the use of driver task 19.'); WriteLn('This demonstration includes high-side and low-side triggering,'); WriteLn('in both bipolar and unipolar modes.'); WriteLn; WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper IRQ5 must be installed (required)'); WriteLn(' -- The voltage source must be adjustable (required)'); WriteLn(' -- Connect voltage source to pins 19 and 37 (required)'); WriteLn(' (channel 0 inputs)'); WriteLn(' -- All remaining jumper settings are irrelevant'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press any key to run the program.'); while not keypressed do; ch := readkey; clrscr; task := 0; param[1] := Address; { starting board address } param[2] := 5; { IRQ5 } param[3] := 1; { set for programmable gains } status := call_driver; { call routine to call ext module } setup := status; END; { end setup } { ***************************************************************************** * FUNCTION: get_readings -- local routine * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * ***************************************************************************** } FUNCTION get_readings:INTEGER; VAR I,status,offdatbuf: word; ch : char; BEGIN offdatbuf := ofs(datbuf); WriteLn('First case: Bipolar with high-side trigger. Conversions will begin'); WriteLn('when the input voltage exceeds 2.5v.'); WriteLn('Press any key to start.'); ch := readkey; task := 19; param[1] := offdatbuf; { Offset to the memory storage location. } param[2] := 24; { Number of conversions to perform. } param[3] := 1024; { Trigger level in counts. Corresponds to +2.5v in a bipolar 10 volt range (+/-5v). } param[4] := 1; { High side trigger. Tells the driver to trigger when the data in the channel exceeds the trigger value. } param[5] := 0; { Which data point to trigger on. } status := call_driver; if status <> 0 then exit; for I := 1 TO 24 DO BEGIN write(datbuf[I]:5,' '); if ((I+1) MOD 8) = 0 then WriteLn; END; WriteLn; WriteLn('Second case: Bipolar with low-side trigger. Conversions will begin'); WriteLn('when the input voltage drops below 2.5v.'); WriteLn('Press any key to start.'); ch := readkey; task := 19; param[1] := offdatbuf; { Offset to the memory storage location. } param[2] := 24; { Number of conversions to perform. } param[3] := 1024; { Trigger level in counts. Corresponds to +2.5v in a bipolar 10 volt range (+/-5v). } param[4] := -1; { Low side trigger. Tells the driver to trigger when the data in the channel drops lower than the trigger value. } param[5] := 0; { Which data point to trigger on. } status := call_driver; if status <> 0 then exit; for I := 1 TO 24 DO BEGIN write(datbuf[I]:5,' '); if ((I+1) MOD 8) = 0 then WriteLn; END; WriteLn; WriteLn('Third case: Unipolar with high-side trigger. Conversions will begin'); WriteLn('when the input voltage exceeds 2.5v.'); WriteLn('Press any key to start.'); ch := readkey; task := 18; param[1] := 9; status := call_driver; if status <> 0 then exit; task := 19; param[1] := offdatbuf; { Offset to the memory storage location. } param[2] := 24; { Number of conversions to perform. } param[3] := 1024; { Trigger level in counts. Corresponds to +2.5v in a unipolar 10 volt range (0-10v). } param[4] := 1; { High side trigger. Tells the driver to trigger when the data in the channel exceeds the trigger value. } param[5] := 0; { Which data point to trigger on. } status := call_driver; if status <> 0 then exit; for I := 1 TO 24 DO BEGIN write(datbuf[I]:5,' '); if ((I+1) MOD 8) = 0 then WriteLn; END; WriteLn; WriteLn('Fourth case: Unipolar with low-side trigger. Conversions will begin'); WriteLn('when the input voltage drops below 2.5v.'); WriteLn('Press any key to start.'); ch := readkey; task := 19; param[1] := offdatbuf; { Offset to the memory storage location. } param[2] := 24; { Number of conversions to perform. } param[3] := 1024; { Trigger level in counts. Corresponds to +2.5v in a unipolar 10 volt range (0-10v). } param[4] := -1; { Low side trigger. Tells the driver to trigger when the data in the channel drops lower than the trigger value. } param[5] := 0; { Which data point to trigger on. } status := call_driver; if status <> 0 then exit; for I := 1 TO 24 DO BEGIN write(datbuf[I]:5,' '); if ((I+1) MOD 8) = 0 then WriteLn; END; WriteLn; get_readings:=status; END; { end get_readings } VAR status : integer; ch : char; BEGIN status := setup; { set up program and the driver } if (status <> 0) then exit; { is status > 0 then board error } repeat status := get_readings; { display current A/D values } if (status <> 0) then exit; { if status > 0 then error } { check for program exit } WriteLn; WriteLn('Press E to exit the program. Press any other key to rescan the data...'); while not keypressed do; ch := readkey; { read the char } until ((ch = 'E') OR (ch = 'e')); END. { end main program }