{***************************************************************************** * SAMPLE4.PAS : D to A OUTPUT * * * * This is a demonstration program to be used with the AD12-16 A/D * * board. The program will prompt the user for a voltage, output it to D/A * * channel 0, then read the voltage back in on channel 0. * * * * 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 * * * * A jumper is required from pin 8 to pin 10. * * A jumper is required from pin 9 to pin 37. * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************} program startup; {$L a16drv} {$F+} USES crt; type param_array = array[1..5] of integer; { 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; procedure a16drv(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 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 channel 0. * * * * 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: Prompts for a voltage, writes it to D/A 0 and read A/D chan 0. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************} procedure get_readings; var volts :real; I :integer; begin ClrScr; { set the scan limits for channel 0 } task := 1; params[1] := 0; { lower scan limit } params[2] := 0; { upper scan limit } call_driver; { call routine to call ext module } { fetch the voltage to output and calculate counts needed } WriteLn;WriteLn; write('Enter the voltage to output: '); readln(volts); volts := (volts / 5) * 4095; params[2] := trunc(volts); { write the counts to the D/A } task := 15; params[1]:= 0; call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { delay for a little } I := 0; while I < 1000 do I:=I+1; { read the A/D channel 0 } task := 3; call_driver; { now compute the proper volts from the counts } volts := (params[1] / 2047) * 5; WriteLn; WriteLn('The value read back is:',volts:8:3); 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(' SAMPLE4.PAS : DAC Output'); WriteLn; WriteLn('This is a demonstration program to be used with the AD12-16 A/D'); WriteLn('board. The program will prompt the user for a voltage, output it to D/A'); WriteLn('channel 0, then read the voltage back in on channel 0.'); WriteLn; 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(' -- Range is from 0 to 5 volts (required)'); WriteLn(' -- DMA channel 1 (required)'); WriteLn(' -- On board clock set to 1 MHz (required)'); WriteLn(' -- A jumper is required from pin 8 to pin 10.'); WriteLn(' -- A jumper is required from pin 9 to pin 37.'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press any key to continue, or press E to exit.'); 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 program. Any other key to continue...'); ch:=ReadKey; { wait for key press } end; end; END. { main program }