'*-------------------------------------------------------------------- '* QSAMPLE3.BAS '* '* Sample program to demonstrate access to DA12-16 Automatic and '* Simultaneous Update modes. '* '* Last Modified: 22 March 1995. SMG '*-------------------------------------------------------------------- DECLARE FUNCTION AskForBaseAddress% (OldOne AS INTEGER) DECLARE FUNCTION Deci% (DS AS STRING) DECLARE SUB WaitForUser () ' 'Introductory screen ' CLS PRINT "" PRINT "Sample 3 DA12-16 " PRINT "" PRINT "" PRINT "Sample demonstrates mode switching and channel programming for the " PRINT "DA12-16 card." PRINT PRINT "DA12-16 configuration for this program: " PRINT PRINT " þ All DAC voltage ranges should be set to ñ5v bipolar." WaitForUser ' ' Prompt user for DA12-16 base address and set global address ' accordingly. ' BaseAddr% = &H350 BaseAddr% = AskForBaseAddress(BaseAddr%) ' ' Release zero latch PortVal% = INP(BaseAddr + 15) ' ' Hardware clear?? ' CLS PRINT "" PRINT "Do you wish to perform a hardware-reset clear?" PRINT "" PRINT " Answer 'Y' if the card has just been powered up, or 'N' if" PRINT " you've already performed this operation since the last reset." PRINT "" ResetDAs: Key$ = INKEY$ Key$ = UCASE$(Key$) IF Key$ = "Y" THEN FOR Channel% = 0 TO 15 OUT BaseAddr% + (Channel% * 2), &H0 OUT BaseAddr% + (Channel% * 2) + 1, &H8 NEXT Channel% PortVal% = INP(BaseAddr% + 10) CLS PRINT "" PRINT " All channels have been updated to bipolar zero (800 hex)" PRINT "Assuming power-on condition, nothing should have changed." PRINT "(Incidentally, any channels set to a uniploar range should" PRINT "have simultaneously changed to +2«v outputs." WaitForUser ELSEIF Key$ <> "N" THEN GOTO ResetDAs END IF CLS PRINT "" PRINT "Press any key to output +2«v on all channels, non-simultaneously." WaitForUser ' ' Remove from Simultaneous mode (offset 10 would also work) ' PortVal% = INP(BaseAddr% + 10) ' ' These changes will now take place immediately ' FOR Channel% = 0 TO 15 OUT BaseAddr% + (Channel% * 2), &H0 OUT BaseAddr% + (Channel% * 2) + 1, &HC NEXT Channel% CLS PRINT "" PRINT "All channels have been updated to +2«v in Automatic Mode." WaitForUser ' 'Place in Simultaneous mode ' PortVal% = INP(BaseAddr% + 0) ' 'The following outputs do not take effect immediately because we are ' now in Simultaneous mode. ' FOR Channel% = 0 TO 15 OUT BaseAddr% + (Channel% * 2), &HFF OUT BaseAddr% + (Channel% * 2) + 1, &HF NEXT Channel% CLS PRINT "" PRINT "All channels have been loaded with FFF hex, but the outputs have" PRINT "not yet changed. Press any key to initiate simultaneous update" PRINT "of all channels. Outputs will simultaneously change to +4.9998vdc" WaitForUser ' 'Simultaneously update all channels ' PortVal% = INP(BaseAddr% + 8) CLS PRINT "" PRINT "All channels have been simultaneously updated to full scale values." WaitForUser FOR Channel% = 1 TO 7 STEP 2 OUT BaseAddr% + (Channel% * 2), &H0 OUT BaseAddr% + (Channel% * 2) + 1, &H8 NEXT Channel% CLS PRINT "" PRINT "Channels 1,3,5,7 have been written to zero but their outputs" PRINT "have not yet changed. Press any key to update all channels." WaitForUser PortVal% = INP(BaseAddr% + 10) PortVal% = INP(BaseAddr% + 15) CLS PRINT "" PRINT "Channels 1,3,5,7 have been updated" WaitForUser PortVal% = INP(BaseAddr% + 10) PortVal% = INP(BaseAdd% + 15) ProgCh: CLS PRINT "Now you may specify a DAC channel and a DAC count value to set" PRINT "a desired channel to a specified value" PRINT "Enter channel value of 99 to quit." PRINT "" ChIn: INPUT "Enter channel (0-15): "; Channel% IF Channel% = 99 THEN GOTO Quit END IF IF (Channel% < 0) OR (Channel% > 15) THEN PRINT "Value out of range. Please try again." GOTO ChIn END IF GetVoltage: INPUT "Enter a voltage between -4.997v to 4.997v: ", voltage# PRINT IF (voltage# < -4.997) OR (voltage# > 4.997) THEN BEEP PRINT "Invalid voltage! Please try again." GOTO GetVoltage END IF ' Compute the digital output needed for this value and the actual voltage ' that will be expected, and display the voltage. counts# = (voltage# + 5!) / .002442 cnts& = counts# expected# = (cnts& * .002442) - 5! ' Prepare and write values to control word lowbyte% = cnts& MOD 256 hibyte% = INT(cnts& / 256) OUT BaseAddr% + (2 * Channel%), lowbyte% OUT BaseAddr% + (2 * Channel%) + 1, hibyte% PRINT PRINT "DAC has been programmed." PRINT "Due to the 12-bit resolution of the DAC, you should expect " PRINT USING "to see a voltage of #.### "; expected# WaitForUser GOTO ProgCh Quit: CLS PRINT "Quick Basic sample #3 complete." END 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 FUNCTION Deci% (DS AS STRING) Deci% = VAL("&H" + DS) END FUNCTION SUB WaitForUser LOCATE 23, 1 PRINT "Press any key to continue ... " Key$ = "" WHILE Key$ = "" Key$ = INKEY$ WEND END SUB