(**************************************************************************** * 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. * * * * Board Configuration: * * -- The Base Address should be set to the address which will be entered * * during program execution. * * -- Reference voltage for the DACs should be -10V. (required) * * -- All remaining jumper settings are irrelevant. * ****************************************************************************) 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 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 } (**************************************************************************** * 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. * ****************************************************************************) procedure write_DAC(Address : word); var counts_entered,volt_value_entered,volt_value_expected :real; dac_number :word; begin (* prompt for the DAC number and desired voltage. *) WriteLn;WriteLn; repeat GotoXY (1,3); ClrEol; Write('Enter the DAC number (0 through 15 only): '); ReadLn(dac_number); until (dac_number>=0) and (dac_number<=15); WriteLn;WriteLn;WriteLn; repeat GotoXY (1,7); ClrEol; Write('Enter a voltage between 0.000v to 9.997v: '); ReadLn(volt_value_entered); until (volt_value_entered>=0) and (volt_value_entered<=9.997); WriteLn;WriteLn; volt_value_entered := volt_value_entered / 0.00015259; (* compute the digital output needed for this value and the actual voltage that will be expected, and display the voltage. *) counts_entered:= volt_value_entered; volt_value_expected := counts_entered * 0.00015259; WriteLn('Due to the 16-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+(2 * dac_number)] := trunc(counts_entered); (* Write low byte *) end; (* write_DAC *) (**************************************************************************** * FUNCTION: main program - global routine * * PURPOSE: Controls overall program execution and determines exit. * ****************************************************************************) var Channel, Address : Word; BEGIN ClrScr; WriteLn(' SAMPLE1.PAS : DA1616 '); 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; WriteLn(' Board Configuration: '); WriteLn; WriteLn(' -- The Base Address should be set to the address which will be entered '); WriteLn(' during program execution. '); WriteLn(' -- Reference voltage for the DACs should be -10V. (required) '); WriteLn(' -- All remaining jumper settings are irrelevant. '); WriteLn; WriteLn; Address := AskForBaseAddress('350'); WriteLn; WriteLn; WriteLn('Press ENTER to continue'); ReadLn; (* Set all sixteen buffers to 0 *) for Channel := 0 to 16 Do PortW[Address + Channel * 2] := 0; (* Take card out of simultaneous update mode and update all channels *) Channel := Port[Address + 10]; repeat ClrScr; write_DAC(Address); WriteLn;WriteLn; Write('Would you like to output another value (Y or N)? '); read(key_entered); until ((key_entered = 'N') or (key_entered = 'n')); ClrScr; END. (* main *)