{**************************************************************************** * PASCAL LANGUAGE SAMPLE 3: SAMPLE3.PAS * * * * This sample exercises the AD12-8G's programmable gain amplifier by * * reading a user selected channel repeatedly at each gain. * * * * LAST MODIFICATION DATE: 2/4/98 * ****************************************************************************} {$L a12gdrv.obj} {$F+} USES crt; PROCEDURE a12gdrv(task,params,stat:integer);External; { These variable MUST be declared as global. They are the ones whose offsets are padded to the A12GDRV routine. If they are not global then the driver will not find their segment. } VAR pntbuf,datbuf : ARRAY[0..199] OF INTEGER; statcode,task : INTEGER; params : ARRAY[1..5] 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 : WORD; 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(params[1]),ofs(statcode)); { this section checks for an error code } call_driver := statcode; if statcode > 0 then begin 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: Initializes driver. * * * * INPUT: None. * * * * CALLS: call_driver(), local routine * * * * OUTPUT: Returns error code supplied by the driver routine. * * * ****************************************************************************} FUNCTION setup : WORD; VAR status : WORD; ch:char; Address: word; BEGIN { This function performs board initialization by calling task 0 of the driver. } ClrScr; WriteLn(' SAMPLE3.PAS : AD12-8G PROGRAMMABLE GAIN AMPLIFIER'); WriteLn; WriteLn('This program demonstrates the use of driver Task 18, Set Programmable'); WriteLn('Gain. After prompting for a channel number, the program performs nine'); WriteLn('reads from the card, using a gain at each read. The data is constantly '); WriteLn('refreshed until a key is pressed.'); WriteLn; WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn('-All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Please press any key to run the program.'); while not keypressed do; ch := readkey; ClrScr; task := 0; { TASK0 - Initialize driver. See manual for a complete task description. } statcode := 0; { Clear the global status variable before the call to the driver. } params[1] := Address; { Stores the card base address. } params[2] := 5; { Stores IRQ5 - Not needed in this sample. } params[3] := 0; { Stores the sub-multiplexer mode. In this case, no sub-multiplexer is needed. } status := call_driver; if (status > 0) THEN BEGIN setup := status; exit; END; task := 11; { Set the settle time for fast computers.} params[1] := 4; params[2] := 100; status := call_driver; setup := status; END; {**************************************************************************** * FUNCTION: get_readings() -- local routine * * * * PURPOSE: With a user selected channel, this routine takes a total of * * nine readings, using a different gain level each time. This * * routine utilizes TASK18, set programmable gains, to accomplish* * this. Note: This sample will only work with an AD12-8G. * * * * INPUT: None. * * * * CALLS: call_driver, local routine * * * * OUTPUT: Returns error code supplied by the driver. * * * ****************************************************************************} FUNCTION get_readings : WORD; VAR CH : CHAR; X : INTEGER; status, user_channel, gain_value, bipolar : INTEGER; BEGIN repeat gotoxy(1,17); WriteLn(' '); gotoxy(1,6); FOR x := 0 TO 7 DO BEGIN user_channel := x * 16; gain_value := x; { Set the gain value. } if (gain_value <> 0) THEN gain_value := gain_value + 7; { Because of the skip in gain codes, an offset should be applied to get the correct code. } task:=18; params[1]:= gain_value; { Send the current gain value to the driver} status:=call_driver; if (status>0) THEN BEGIN get_readings := status; exit; END; task:=6; { Read a point from the card. } params[1]:=user_channel; status:=call_driver; if (status>0) THEN BEGIN get_readings := status; exit; END; WriteLn('counts on channel ',round(user_channel/16),' Gain code of ',gain_value,' : ', params[2],' '); END; WriteLn; Writeln('Press any key to continue.'); if (status>0) THEN BEGIN get_readings := status; exit; END; until keypressed; ch := readkey; get_readings := status; END;{ get readings } { MAIN PROGRAM } VAR status : WORD; ch : CHAR; BEGIN status := setup; { set up program and the driver } if (status = 0) THEN repeat status := get_readings; 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 restart...'); ch := readkey; { read the char } until (ch = 'E') OR (ch = 'e'); END. { end main program }