'********************************************************************* '* * '* QuickBASIC SAMPLE 4:QSAMPLE4.BAS * '* * '* AD12-8G Demonstration Data Acquisition Program * '* * '* This program demonstrates the following: * '* - How to initialize and configure the AD12-8G driver * '* - How to use Task 19 to do analog triggered A/D conversions * '* '* LAST MODIFIED: 2/4/98 '********************************************************************* ' Dimension the parameter passing variables. DIM task%, STAT%, PARAM%(5) ' Dimension some buffers. You need data and point buffers. DIM DATBUF%(200), PNTBUF%(200) COMMON SHARED PARAM%, DATBUF%, PNTBUF% ' This is the driver entry point declaration DECLARE SUB A12GDRV (task%, BYVAL PARAM%, STAT%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT " QSAMPLE4.BAS : AD12-8G DEMONSTRATION DATA ACQUISTION" PRINT PRINT "The following program demonstrates the use of driver task 19. This" PRINT "demonstration includes high-side and low-side triggering, in both polar" PRINT "and unipolar modes. An adjustable voltage source is needed to perform" PRINT "this task. To exit the task prematurely, press any key." PRINT : PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is at "; HEX$(Address%); " hex" PRINT " -- The voltage source must be adjustable (required)" PRINT " -- Connect voltage source to pins 19 and 37 (required)" PRINT " (channel 0 inputs)" PRINT " -- All remaining jumper settings are irrelevant" PRINT : PRINT : PRINT : PRINT PRINT "Press any key to start." ch$ = INPUT$(1) '--------------------------- ' Initialize Driver task% = 0 PARAM%(1) = Address% '<- assign the base address. PARAM%(2) = 5 'interrupt number is 5 - has no effect on this sample PARAM%(3) = 1 'programmable gains on the sub-multiplexer GOSUB handler 'program the base address and int # C$ = " " DO UNTIL C$ = CHR$(27) CLS PRINT "First case: Bipolar with high-side trigger. Conversions will begin" PRINT "when the input voltage exceeds 2.5v." PRINT "--Press any key to start." ch$ = INPUT$(1) task% = 19 PARAM%(1) = VARPTR(DATBUF%(1)) 'Offset to the memory storage location. PARAM%(2) = 24 'Number of conversions to perform. PARAM%(3) = 1024 ' Trigger level in counts. Corresponds to +2.5v ' in a bipolar 10 volt range (+/-5v). PARAM%(4) = 1 ' High side trigger. Tells the driver to trigger ' when the data in the channel exceeds the trigger ' value. PARAM%(5) = 0 ' Which data point to trigger on. GOSUB handler I% = 1 DO UNTIL I% = 25 PRINT USING "##### "; DATBUF%(I%); IF (I% MOD 8) = 0 THEN PRINT I% = I% + 1 LOOP PRINT : PRINT PRINT "Second case: Bipolar with low-side trigger. Conversions will begin" PRINT "when the input voltage drops below 2.5v." PRINT "--Press any key to start." ch$ = INPUT$(1) task% = 19 PARAM%(1) = VARPTR(DATBUF%(1)) 'Offset to the memory storage location. PARAM%(2) = 24 'Number of conversions to perform. PARAM%(3) = 1024 ' Trigger level in counts. Corresponds to +2.5v ' in a bipolar 10 volt range (+/-5v). PARAM%(4) = -1 ' Low side trigger. Tells the driver to trigger ' when the data in the channel is below the trigger ' value. PARAM%(5) = 0 ' Which data point to trigger on. GOSUB handler I% = 1 DO UNTIL I% = 25 PRINT USING "##### "; DATBUF%(I%); IF (I% MOD 8) = 0 THEN PRINT I% = I% + 1 LOOP PRINT PRINT PRINT "Third case: Unipolar with high-side trigger. Conversions will begin" PRINT "when the input voltage exceeds 2.5v." PRINT "--Press any key to start." ch$ = INPUT$(1) task% = 18 PARAM%(1) = 9 GOSUB handler task% = 19 PARAM%(1) = VARPTR(DATBUF%(1)) 'Offset to the memory storage location. PARAM%(2) = 24 'Number of conversions to perform. PARAM%(3) = 1024 ' Trigger level in counts. Corresponds to +2.5v ' in a unipolar 10 volt range (0-10v). PARAM%(4) = 1 ' High side trigger. Tells the driver to trigger ' when the data in the channel exceeds the trigger ' value. PARAM%(5) = 0 ' Which data point to trigger on. GOSUB handler I% = 1 DO UNTIL I% = 25 PRINT USING "##### "; DATBUF%(I%); IF (I% MOD 8) = 0 THEN PRINT I% = I% + 1 LOOP PRINT PRINT PRINT "Fourth case: Unipolar with low-side trigger. Conversions will begin" PRINT "when the input voltage drops below 2.5v." PRINT "--Press any key to start." ch$ = INPUT$(1) task% = 19 PARAM%(1) = VARPTR(DATBUF%(1)) 'Offset to the memory storage location. PARAM%(2) = 24 'Number of conversions to perform. PARAM%(3) = 1024 ' Trigger level in counts. Corresponds to +2.5v ' in a unipolar 10 volt range (0-10v). PARAM%(4) = -1 ' Low side trigger. Tells the driver to trigger ' when the data in the channel is below the trigger ' value. PARAM%(5) = 0 ' Which data point to trigger on. GOSUB handler I% = 1 DO UNTIL I% = 25 PRINT USING "##### "; DATBUF%(I%); IF (I% MOD 8) = 0 THEN PRINT I% = I% + 1 LOOP PRINT '----------------------- 'Wait for the operator. '----------------------- PRINT "Press any key to rescan the data; press the [Esc] key to Quit"; C$ = INPUT$(1) CLS LOOP END '************************************************************* ' DRIVER HANDLER ' ' This following section of code will call the driver for you ' handling the argument passing convention, then check the ' status after it returns and provide a couple of options if ' there was an error. '************************************************************* handler: STAT% = 0 CALL A12GDRV(task%, VARPTR(PARAM%(1)), STAT%) IF STAT% THEN PRINT "TASK"; task%; "has error code"; STAT% DO PRINT "Try to continue with program or Exit (C/E)"; INPUT ans$ ans$ = UCASE$(ans$) IF ans$ = "C" THEN EXIT DO IF ans$ = "E" THEN END LOOP END IF 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