{**************************************************************************** * PASCAL LANGUAGE SAMPLE 2: SAMPLE2.PAS * * * * This is a demonstration program to be used with the AD12-8G A/D board. * * The program uses timer driven interrupts to read 17 channels of data. * * This program is running in the manual gain mode for whichever mux board * * is attached. The following pins must be jumpered on the AD12-8G. * * 1) PIN 6, CTR2 OUT JUMPERED TO PIN 4, CTR1 CLK * * 2) PIN 5, CTR1 OUT JUMPERED TO PIN 24, INT IN * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program startup; {$L a12gdrv} { link the driver module } {$F+} { force far calls } USES crt; type param_array = array[1..5] of integer; dat_array = array[1..200] of integer; pnt_array = array[1..200] of word; { all of the parameters passed to the A12GDRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; params : param_array; ch : char; pntbuf : pnt_array; datbuf : dat_array; 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 a12gdrv(t_off:word;p_off:word;st_off:word);external; {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a12gdrv - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; var t_off,p_off,st_off : word; 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(status)); { this section checks for an error code } if status > 0 then begin WriteLn('TASK ',task,' has returned an error code of ',status,'.'); WriteLn('Press ''C'' to continue, any other key to exit.'); Char_Input := UpCase(Readkey); If Char_Input = 'C' Then status := 0; end; end; { call_driver } {**************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver for 17 point address and sets up the * * counters that sync the interrupts. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************} procedure setup; var I :integer; Address :word; begin ch := ' '; ClrScr; WriteLn(' SAMPLE2.PAS : TIMER DRIVEN DATA ACQUISITION'); WriteLn; WriteLn('This is a demonstration program to be used with the AD12-8G A/D board.'); WriteLn('The program uses timer driven interrupts to read 17 channels of data.'); WriteLn('This program is running in the manual gain mode for whichever mux board'); WriteLn('is attached.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- IRQ5 is used for interrupts (required)'); WriteLn(' -- The following pins must be jumpered on the AD12-8G: (required)'); WriteLn(' 1) PIN 6, CTR2 OUT JUMPERED TO PIN 4, CTR1 CLK'); WriteLn(' 2) PIN 5, CTR1 OUT JUMPERED TO PIN 24, INT IN'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press any key to run the program.'); while not keypressed do; ch := readkey; task := 0; params[1] := Address; { starting board address } params[2] := 5; { IRQ5 } params[3] := 0; { non-programmable gains} call_driver; { call routine to call ext module } if status <> 0 then exit; { reset the point list } task := 11; params[1] := 2; call_driver; { call routine to call ext module } if status <> 0 then exit; { now assign the point range for 1 mux board attached to AD12-8G channel 0 and AD12-8G channel 1 is a direct input. } task := 5; params[1] := 0; { point range is 0 thru 16, for a total of 17 points } params[2] := 16; call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { program the counters that trigger the interrupts. The output freq of the two counters is 1000 hz. } task := 14; params[1] := 2; { set up up counter 2 } params[2] := 3; { to mode 3 } params[3] := 1000; call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } task := 14; params[1] := 1; { set up up counter 2 } params[2] := 3; { to mode 2 } params[3] := 5; call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } { set driver settle time count */ task := 11; params[1] := 4; params[2] := 25; call_driver; { call routine to call ext module } end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads the first 17 points in the point list and displays * * them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I :integer; begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } if status <> 0 then exit; { first tell driver to start acquisition } task := 9; params[1] := 1; { sub task 1, interrupt scan } params[2] := 17; { number of points to gather } params[3] := 0; params[4] := 0; call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } repeat task := 9; params[1] := 2; { sub task 2, wait for end of scan } call_driver; { call routine to call ext module } if status <> 0 then exit; until (params[2] = 0) or (status > 0); { now get the read information } task := 9; params[1] := 3; { sub task 3 - get the data } params[2] := ofs(datbuf[1]); { offset to data buffer } params[3] := ofs(pntbuf[1]); { offset to point bufffer } params[4] := 17; { number of samples returned here } call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { now if OK list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE'); WriteLn(' ------- ------'); for I := 1 to params[4] do begin { upper bits are ch number } channel := (pntbuf[I] and $ff00) div 256; WriteLn(channel:10,datbuf[I]:12); { The subtraction in the above line is for bipolar offset } end; end; { get_readings } { MAIN PROGRAM } BEGIN setup; { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin get_readings; { display current values } 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 the data...'); ch:=readkey; { wait for key press } end; end; end. { main program }