{***************************************************************************** * SAMPLE3.PAS : DATA ACQUISITION USING DMA * * * * The program will display sixteen channels using timer driven DMA. * * * * The board should be set as follows: * * -- Polarity set to bipolar -- S2 TO BIP * * -- On board clock set to 1 MHz -- CLOCK JUMPER TO 1MHZ * * -- 16 channel single ended -- S3 TO 16CH * * -- DMA channel 1 -- S1 TO 1 * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************} program startup; {$L aa16drv} {$F+} USES crt; type param_array = array[1..7] of integer; dat_array = array[1..200] of integer; pnt_array = array[1..200] of word; { all of the parameters passed to the 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 aa16drv(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: aa16drv - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; begin aa16drv(ofs(task),ofs(params[1]),ofs(status)); { 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; var Address : word; begin ClrScr; WriteLn(' SAMPLE3.PAS : DATA ACQUISITION USING DMA'); WriteLn; WriteLn(' The program will display sixteen channels using timer driven DMA.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- RANGE: 5 Volt Range (required)'); WriteLn(' -- POLARITY set to bipolar--S2 to BIP (required)'); WriteLn(' -- On board clock set to 1 MHz -- CLOCK JUMPER TO 1MHZ (required)'); WriteLn(' -- 16 channel single ended -- S3 TO 16CH (required)'); WriteLn(' -- DMA channel 1 -- S1 TO 1 (required)'); WriteLn(' -- All other jumper settings are irrelevant'); WriteLn; WriteLn; WriteLn; WriteLn('Press any key to continue, or E to exit.'); ch := readkey; { initialize the board } task := 0; params[1] := Address; { starting board address } params[2] := 5; { 5 volt range } call_driver; if status <> 0 then exit; { Set up the timers to divide the 1MHz clock by 1000 } task := 14; params[1] := 1; { set up counter 1 } params[2] := 3; { use mode 3 } params[3] := 100; { use 100 as divsor } call_driver; if status <> 0 then exit; task := 14; params[1] := 2; { set up counter 2 } params[2] := 3; { use mode 3 } params[3] := 10; { use 100 as divsor } call_driver; if status <> 0 then exit; { set the sample and hold settle count, this is only needed for faster computers such as 386's etc. } task := 11; params[1] := 5; { sub task 5, set settle count } params[2] := 50; { set settle count to 50 } call_driver; if status <> 0 then exit; { set up the scan register on the board. } task := 1; params[1] := 0; { lower scan limit } params[2] := 15; { upper scan limit } call_driver; { call routine to call ext module } if status <> 0 then exit; { set the AIM-16P to channel 0 } task := 12; params[1] := 0; { output 0 to digital bits } call_driver; 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 :integer; begin { set up to do timer driven DMA. The timer will start conversions at a 100Hz rate. The destination segment could be any unused area of memory. Make sure it is unused! } task := 17; params[1] := 16; { number of points to gather } params[2] := $7000; { destinstion register } params[3] := 1; { use timer for start ATD trigger } params[4] := 0; { one pass only } params[5] := 1; { use timer for start ATD trigger } params[6] := 5; { one pass only } call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { repeatedly check status of background task until the driver indicates that it is done } task := 9; params[1] := 2; { sub task 2, check background task status } repeat call_driver; until (params[2] = 0); { 0 indicates background task complete } { we now can convert the values taken by task 17 into channel and counts and store in seperate arrays. This needs to be done because the board returns a conversion with the count in the upper 12 bits of a 16 bit integer and the channel number in the lower 4 bits. } task := 18; params[1] := 16; { number of transfers } params[2] := $7000; { task 5 destination segment } params[3] := 0; { start with first value in segment } params[4] := ofs(datbuf[1]); { offset to data buffer } params[5] := ofs(pntbuf[1]); { offset to channel bufffer } call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { display results to screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE'); WriteLn(' ------- ------'); for I := 1 to 16 do WriteLn(pntbuf[I]:10,datbuf[I]:12); 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 setup; { 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 { check for program exit } begin { if status > 0 then error } 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 }