(**************************************************************************** * Pascal SAMPLE #1: SAMPLE1.PAS * * * * This sample will prompt the user for a voltage between 0 and 10 volts, * * then calculate the actual voltage based on the resolution of the DAC and* * output the voltage to the desired DAC channel. * * * * The following setup of the board is expected: * * -- Reference voltage for the DACs should be -10V. * * * ****************************************************************************) program sample1; uses crt; var key_entered:char; function AskForBaseAddress(Oldone : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin 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} (**************************************************************************** * * * FUNCTION: write_DAC - local routine * * * * PURPOSE: Prompts the user for DAC number and voltage, then calculates * * the actual output voltage based on resolution, displays it * * and writes the value to the DAC. * * * * INPUT: None. * * * * CALLS: None. * * * * OUTPUT: None. * * * ****************************************************************************) Procedure write_DAC(Address:word); var volt_value_expected,volt_value_entered :real; counts_entered,dac_number :word; ch :char; code :integer; begin (* prompt for the DAC number and desired voltage. *) WriteLn;WriteLn; repeat GotoXY (1,3); ClrEol; Write('Enter the DAC number you wish to output to (0 or 3 only): '); ch := ReadKey; Writeln(ch); val(ch,dac_number,code); until (dac_number>=0) and (dac_number<=3); WriteLn;WriteLn;WriteLn; repeat GotoXY (1,7); ClrEol; WriteLn('If your card is not set for 0-10V DAC outputs,'); WriteLn(' the value will be proportional.'); Write('Enter a voltage between 0.000V to 9.97V: '); ReadLn(volt_value_entered); until (volt_value_entered>=0) and (volt_value_entered<=9.997); WriteLn;WriteLn; (* compute the digital output needed for this value and the actual voltage that will be expected, and display the voltage. *) counts_entered := trunc(volt_value_entered/0.002441); volt_value_expected := counts_entered * 0.002441; WriteLn('Due to the 12-bit resolution of the DAC, you should expect'); WriteLn('to see a voltage of ',volt_value_expected:4:3,'.'); (* prepare the control word and Write to the DAC *) PortW[Address+4+(2*dac_number)] := counts_entered; end; (* write_DAC *) (**************************************************************************** * * * FUNCTION: main program - global routine * * * * PURPOSE: Controls overall program execution and determines exit. * * * * INPUT: None. * * * * CALLS: None. * * * * OUTPUT: None. * * * ****************************************************************************) var Address:word; begin ClrScr; WriteLn(' Pascal SAMPLE #1: SAMPLE1.PAS '); WriteLn(' '); WriteLn(' This sample will prompt the user for a voltage between 0 and 10 volts, '); WriteLn(' then calculate the actual voltage based on the resolution of the DAC and'); WriteLn(' output the voltage to the desired DAC channel. '); WriteLn; WriteLn(' Board Configuration: '); WriteLn; WriteLn(' -- The Base Address should be set to the address which will'); WriteLn(' be entered during program execution.'); WriteLn(' -- DACs should be in the 10V unipolar mode.'); WriteLn(' -- If the DAC''s are in any other mode, the values will'); WriteLn(' be proportionally incorrect.'); WriteLn; WriteLn; WriteLn; Address := AskForBaseAddress('300'); Port[Address+4] := 0; { set DAC0 to 0 volts } Port[Address+6] := 0; { set DAC1 to 0 volts } Port[Address+8] := 0; { set DAC2 to 0 volts } Port[Address+$0a] := 0; { set DAC3 to 0 volts } Port[Address+$18] := 1; {Enable the DACS for output} WriteLn; repeat ClrScr; write_DAC(Address); WriteLn;WriteLn; Write('Would you like to output another value (Y or N)? '); ReadLn(key_entered); until ((key_entered = 'N') or (key_entered = 'n')); ClrScr; end. (* main *)