{*************************************************************************** * PASCAL LANGUAGE SAMPLE 2: SAMPLE2.PAS * * * * This is a demonstration program to be used with the AD12-8 A/D * * board. The program will display channels of data polled from an AIM-16* * board using the A12DRV.OBJ driver module supplied with the AD12-8. * * * * LAST MODIFICATION: 2/3/98 * * * ***************************************************************************} program startup; {$L a12drv} {$F+} USES crt; { all of the parameters passed to the A12DRV 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..200] of integer; datbuf : array[1..200] of word; buffr : array[0..4000] of word; 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 a12drv(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: a12drv - 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; a12drv(t_off,p_off,st_off); { this section checks for an error code } if status > 0 then begin writeln; 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 package. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var I :integer; Address :word; begin ClrScr; WriteLn('Sample 2 AD12-8'); WriteLn; WriteLn('This samples the analog inputs from an AIM-16 attached to the'); WriteLn('AD12-8 and displays them for you.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration Requirements:'); WriteLn; WriteLn(' -- RANGE: 5 Volt Range '); WriteLn(' -- POLARITY: Bipolar '); WriteLn(' -- IRQ: 5 '); WriteLn(' -- The TMR jumper must be in the TMR position. '); WriteLn(' -- The EXT EOC jumper must be in the EOC position. '); WriteLn(' -- The AUTO jumper must NOT be installed. '); WriteLn(' -- AIM-16 set to Programmable Gains '); WriteLn(' -- All remaining jumper settings are irrelevant'); WriteLn; WriteLn('Please press ENTER to continue.'); ReadLn; task := 0; params[1] := 1; { manual initialization } params[2] := Address; { starting board address } params[3] := 5; { IRQ5 } params[4] := 5; { 5V range } params[5] := 1; { bipolar mode } call_driver; { call routine to call ext module } if status = 0 then begin { now reset the task list } task := 11; params[1] := 2; call_driver; { call routine to call ext module } if status = 0 then begin { now assign the point range for 1 AIM-16 board attached to AD12-8 channel 0 and AD12-8 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 { if status > 0 then error } begin { program the counters that trigger the A/D. } task := 14; params[1] := 1; { set up up counter 1 } params[2] := 3; { to mode 3 } params[3] := 2; { with period 4.47 uSecs } call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } begin task := 14; params[1] := 2; { set up up counter 2 } params[2] := 3; { to mode 2 } params[3] := 2237; { with period 9.999 mSecs } call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } begin { assign ouput range to poits 0 thru 16 that will convert counts to mVolts at a gain of 1. Based on 0-4095 count A/D = -5 to +5 volts. } task := 10; params[1] := 3; params[2] := 0; params[3] := -5000; { -5000 to 5000 is 10 volt bipolar range } params[4] := 5000; { which for this program is +-5V } call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } begin { now replicate point 0 to points 1 thru 16 } task := 10; params[1] := 4; params[2] := 0; { replicate this point } params[3] := 1; { starting at this point } params[4] := 16; { and up to this point } call_driver; { call routine to call ext module } if status = 0 then { if status > 0 then error } begin { now set gain to 5 for points 1 thru 16 } task := 4; params[1] := 1; { start at this point } params[2] := 15; { end at this point } params[3] := 5; { using gain code of 5 } call_driver; { call routine to call ext module } end; end; end; end; end; end; end; 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,gain :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] := 17; { number of points to gather } params[3] := SEG(buffr); params[4] := OFS(buffr); 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 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 { if status > 0 then error } begin { now if OK list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE GAIN'); WriteLn(' ------- ------ ----'); for I := 1 to params[4] do begin { upper bits are ch number } channel := (pntbuf[I] and $ff00) div 256; data := datbuf[I] * 0.001; { scale millivolts to volts } gain := (pntbuf[I] and $00ff); WriteLn(channel:10,data:12:3,gain:7); end; 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 { 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 }