{*************************************************************************** * PASCAL LANGUAGE SAMPLE 2: SAMPLE2.PAS * * * * This is a demonstration program to be used with the AIO8 A/D card. * * The program will display eight channels of data taken from the card * * using the interrupt functions of the AIO8DRV.OBJ driver module supplied* * with the card. * * * * LAST MODIFICATION: 2/4/98 * * * ***************************************************************************} program startup; {$L aio8drv} {$F+} USES crt; { all of the parameters passed to the AIO8DRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; params : array[1..5] of integer; ch : char; pntbuf : array[1..10] of integer; datbuf : array[1..10] of word; procedure aio8drv(t_off:word;p_off:word;st_off:word);external; 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 } {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver module. * * * * INPUT: None. * * * * CALLS: aio8drv - entry point to driver module. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; var t_off,p_off,st_off : word; begin { this section extracts the offset of the parameters that we will pass to the assembly driver } t_off := ofs(task); p_off := ofs(params[1]); st_off := ofs(status); status := 0; aio8drv(t_off,p_off,st_off); { this section checks for an error code } if (status > 0) and (status <> 14) then begin WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {************************************************************************** * PROCEDURE: setup -- local routine * * * * PURPOSE: Initializes the driver to work for the sample program. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver module. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var I :integer; Address :word; begin ClrScr; WriteLn(' Sample 2 : AIO8'); WriteLn; WriteLn('This sample takes the eight analog inputs from the AIO8'); WriteLn('and displays them for you. Counter 2 is used to supply the'); WriteLn('interrupts.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- Jumper EXT should be installed (required)'); WriteLn(' -- Jumper pin 24 to pin 6 on the I/O connector (required)'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Please press ENTER to continue.'); ReadLn; task := 0; params[1] := Address; { starting board address } params[2] := 1; { manual initialization } params[3] := 1; { use manual mode for AIM-16 gains when no AIM-16 } call_driver; { call routine to call ext module } if status = 0 then begin { setup the counter to trigger the interrupts } task := 14; params[1] := 2; { set up up counter 2 } params[2] := 3; { to mode 3 } params[3] := 10000; { divide bus clock by 10000 to get interrupt rate } call_driver; { call routine to call ext module } { scale all point address to read +/- 5 volts } for I := 0 to 7 do begin task := 10; params[1] := 3; params[2] := I * 16; params[3] := -5000; { -5000 to 5000 is a 10 volt range } params[4] := 5000; { which for this program is +-5V } call_driver; { call routine to call ext module } end; { set up the sample and hold settle time } task := 11; params[1] := 5; params[2] := 25; call_driver; { call routine to call ext module } end; end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads the eight A/D channels and displays them. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver module. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I :integer; data :real; begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } if status = 0 then begin { first tell driver to start acquisition } task := 9; params[1] := 1; { sub task 1, interrupt scan } params[2] := 5; { IRQ 5 } params[3] := 8; { number of points to gather } params[4] := OFS(datbuf); params[5] := OFS(pntbuf); call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } begin { now wait for end of scan } params[2] := 0; repeat task := 9; params[1] := 2; { sub task 2, wait for end of scan } call_driver; { call routine to call ext module } until (params[2] = 0) or (status > 0); if status = 0 then { if status > 0 then error } begin { now list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE'); WriteLn(' ------- ------'); for I := 1 to 8 do begin { upper bits are ch number } channel := (pntbuf[I] and $ff00) div 256; data := datbuf[I] * 0.001; { scale millivolts to volts } WriteLn(channel:10,data:12:3); end; end; end; end; end; { get_readings } {************************************************************************** * PROCEDURE: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - read the A/D channels and display. * * * * OUTPUT: None. * * * **************************************************************************} BEGIN ch := ' '; setup; { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin get_readings; { display current values for the 8 channels } if status = 0 then begin { if status > 0 then error } { check for program exit } WriteLn; WriteLn('Press E to exit the program. Press any other key to rescan for data...'); ch:=readkey; { wait for key press } end; end; END. { main program }