DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT "****************************************************************************" PRINT "* QSAMPLE1.BAS : DA1616 *" PRINT "* *" PRINT "* This sample will prompt the user for a voltage between 0 and 10 volts, *" PRINT "* then calculate the actual voltage based on the resolution of the DAC and*" PRINT "* output the voltage to the desired DAC channel. *" PRINT "* *" PRINT "* Board Configuration: *" PRINT "* -- The Base Address should be set to the address which will be entered *" PRINT "* during program execution. *" PRINT "* -- Reference voltage for the DACs should be -10V. (required) *" PRINT "* -- All remaining jumper settings are irrelevant. *" PRINT "* *" PRINT "****************************************************************************" PRINT : PRINT Address% = AskForBaseAddress!(&H350) PRINT : PRINT : PRINT INPUT "Press ENTER to continue"; Msg$ '**************************************************************************** '* FUNCTION: main program - global routine * '* PURPOSE: Controls overall program execution and determines exit. * '**************************************************************************** FOR channelnum = 0 TO 16 ' set all 16 buffers to 0 OUT Address% + (2 * channelnum), 0 OUT Address% + (2 * channelnum + 1), 0 NEXT channelnum channelnum = INP(Address% + 10) ' remove from simultaneous ' mode and update all ' channels DO CLS GOSUB writeDAC PRINT PRINT PRINT PRINT "Would you like to output another value (Y or N)? " key$ = INPUT$(1) LOOP UNTIL key$ = "N" OR key$ = "n" OUT Address% + (2 * DACnumber), 0 OUT Address% + (2 * DACnumber + 1), 0 CLS END ' PROGRAM '**************************************************************************** '* FUNCTION: writeDAC - 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. * '**************************************************************************** writeDAC: ' prompt for the DAC number and desired voltage. PRINT : PRINT : PRINT INPUT "Enter the DAC number (0 through 15 only): ", DACnumber WHILE DACnumber < 0 OR DACnumber > 15 LOCATE 4, 43 PRINT " " LOCATE 4, 43 INPUT DACnumber WEND PRINT : PRINT : PRINT : PRINT : PRINT INPUT "Enter a voltage between 0.000v to 9.997v: ", voltage# WHILE voltage# < 0 OR voltage# > 9.997 LOCATE 10, 43 PRINT " " LOCATE 10, 43 INPUT voltage# WEND PRINT PRINT ' compute the digital output needed for this value and the actual voltage ' that will be expected, and display the voltage. counts# = voltage# / .000152 cnts& = counts# expected# = cnts& * .000152 PRINT "Due to the 16-bit resolution of the DAC, you should expect " PRINT USING "to see a voltage of #.### "; expected# ' Prepare and write values to control word lowbyte% = cnts& MOD 256 hibyte% = INT(cnts& / 256) OUT Address% + (2 * DACnumber), lowbyte% OUT Address% + (2 * DACnumber + 1), hibyte% RETURN FUNCTION AskForBaseAddress (OldOne AS INTEGER) Msg$ = "" NewOne% = 0: Success = 0: Dummy% = 0 AddrInputPosX = 0: AddrInputPosY = 0 PRINT "Please enter the Base Address (0000-FFFF) for your card (in hex)" PRINT "or press ENTER for "; HEX$(OldOne%); "." PRINT ">"; AddrInputPosX = POS(0): AddrInputPosY = CSRLIN WHILE Success = 0 LOCATE AddrInputPosY, AddrInputPosX PRINT " " LOCATE AddrInputPosY, AddrInputPosX LINE INPUT Msg$ NewOne% = VAL("&H0" + LEFT$(Msg$, 4)) Success = 1 Dummy% = NewOne% IF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION