{***************************************************************************** * SAMPLE1.PAS DATA ACQUISITION * * * * This is a demonstration program to be used with the AD12-16 A/D * * board. The program will display sixteen channels using timer driven * * data acquisition. The program demonstrates initializing the driver * * (task 0), setting the scan limits(task 1) and performing data * * acquisition(task 4). * * * * The board should be set as follows: * * -- IRQ5 is used for interrupts * * -- Polarity set to bipolar * * -- DMA channel 1 * * -- On board clock set to 1 MHz * * * * Place a jumper from pin 25 (IPO) to pin 28 (ground). After the program * * has started, remove this jumper to allow A to D conversions to start. * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************} program startup; {$L a16drv} {$F+} 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 A16DRV 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 a16drv(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: a16drv - entry point to driver package. * * * * 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; a16drv(t_off,p_off,st_off); { this section checks for an error code } if status > 0 then begin WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package to read all 16 A/D channels. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************} procedure setup(Address : word); var I :integer; begin { initialize the board } task := 0; params[1] := Address; { starting board address } params[2] := 5; { IRQ5 } params[3] := 1; { DMA channel 1 } call_driver; { call routine to call ext module } if status <> 0 then exit; end; {procedure setup } {***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Reads the 16 A/D channels and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************} procedure get_readings; var I,data,channel :integer; begin { set the scan limits from channel 0 to 15 } task := 1; params[1] := 0; { lower scan limit } params[2] := 15; { upper scan limit } call_driver; { call routine to call ext module } ClrScr; task := 4; params[1] := 16; { number of points to gather } params[2] := ofs(datbuf[1]); { destinstion buffer } params[3] := 1; { use timer for start ATD trigger } params[4] := 0; { one pass only } call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } WriteLn; WriteLn(' CHANNEL VALUE'); WriteLn(' ------- ------'); for I := 1 to 16 do begin channel:= datbuf[I] and $000f; { extract the channel } data := (datbuf[I] xor $8000); { sign correct for bipolar } data := data div 16; { right shift by 4 bits } WriteLn(channel:10,data:12); 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. * * * **************************************************************************} var Address : word; begin ClrScr; WriteLn(' SAMPLE1.PAS Data Acquisition'); WriteLn; WriteLn('This is a demonstration program to be used with the AD12-16 A/D'); WriteLn('board. The program will display sixteen channels using timer driven'); WriteLn('data acquisition. The program demonstrates initializing the driver'); WriteLn('(task 0), setting the scan limits(task 1) and performing data'); WriteLn('acquisition(task 4).'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- IRQ5 is used for interrupts (required)'); WriteLn(' -- Polarity set to bipolar (required)'); WriteLn(' -- DMA channel 1 (required)'); WriteLn(' -- On board clock set to 1 MHz (required)'); WriteLn(' -- Place a jumper from pin 25 (IPO) to pin 28 (ground). After the program'); WriteLn(' has started, remove this jumper to allow A to D conversions to start.'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn('Press any key to continue, or press E to exit the program.'); ch := ReadKey; setup(Address); { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin { display current values for the 8 channels } get_readings; 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 }