'*************************************************************** '* * '* QuickBASIC SAMPLE 2:QSAMPLE2.BAS * '* * '* AD12-8G Timer Driven Data Acquisition * '*LAST MOD:2/4/98 * '*************************************************************** ' '--------------------------------------------------------------- ' This sample program requires the following setup on the AD12-8G ' card: ' ' interrupt selection = IRQ5 (interrupt request #5) ' ' The following external jumpers also need to be added: ' 1) CTR2 OUT, PIN 6 TO CTR1 CLK, PIN4 ' 2) CTR1 OUT, PIN 5 TO INT IN, PIN 24 '--------------------------------------------------------------- ' Dimension the paramter 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) '------------------------ 'Ask for the Base Address '------------------------ CLS PRINT " QSAMPLE2.BAS : AD12-8G TIMER DRIVEN DATA ACQUISITION " PRINT PRINT "This is a demonstration program to be used with the AD12-8G A/D board." PRINT "The program uses timer driven interrupts to read 17 channels of data." PRINT "This program is running in the manual gain mode for whichever mux board" PRINT "is attached." PRINT PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is at "; HEX$(Address%); " hex" PRINT " -- IRQ5 is used for interrupts (required)" PRINT " -- Needed external jumpers to be added: (required)" PRINT " 1) CTR2 OUT, PIN 6 TO CTR1 CLK, PIN4" PRINT " 2) CTR1 OUT, PIN 5 TO INT IN, PIN 24" PRINT " -- All remaining jumper settings are irrelevant" PRINT : PRINT : PRINT : PRINT PRINT "Press ENTER to scan the data" INPUT ""; Msg$ '----------------------- ' Initialize Driver '----------------------- TASK% = 0 PARAM%(1) = Address% '<-assign the base address. PARAM%(2) = 5 'interrupt number is 5 PARAM%(3) = 0 'non-programmable gains GOSUB HANDLER 'program the base address and int # 'reset the point assignment list TASK% = 11 PARAM%(1) = 2 GOSUB HANDLER 'assign the point range for 1 MUX card and 1 direct A/D channel TASK% = 5 PARAM%(1) = 0 PARAM%(2) = 16 GOSUB HANDLER 'program the counters that trigger the A/D TASK% = 14 PARAM%(1) = 2 PARAM%(2) = 3 PARAM%(3) = 1000 GOSUB HANDLER 'counter #2 setup on mode 3 PARAM%(1) = 1 PARAM%(2) = 3 PARAM%(3) = 5 GOSUB HANDLER 'counter #1 setup on mode 3 '----------------------------------------------------- ' Gather point data via timer controlled interrupts. '----------------------------------------------------- DO TASK% = 9 PARAM%(1) = 1 'start the scan PARAM%(2) = 17 PARAM%(3) = VARPTR(DATBUF%(1)) PARAM%(4) = VARPTR(PNTBUF%(1)) GOSUB HANDLER 'acquire data DO 'Wait for end of scan TASK% = 9 PARAM%(1) = 2 GOSUB HANDLER LOOP WHILE PARAM%(2) <> 0 CLS '-------------------------------------------------------------- ' Get and display the data '-------------------------------------------------------------- TASK% = 9 PARAM%(1) = 3 PARAM%(2) = VARPTR(DATBUF%(1)) PARAM%(3) = VARPTR(PNTBUF%(1)) PARAM%(4) = 17 GOSUB HANDLER 'fetch a block of data PRINT " CH DATA" PRINT " --- ------" FOR I = 1 TO PARAM%(4) CH = (PNTBUF%(I) AND &HFF00) / 256 DAT = DATBUF%(I) PRINT USING " ### #####"; CH; DAT NEXT I '----------------------- 'Wait for the operator. '----------------------- PRINT "Press any key to rescan the data; press the [Esc] key to Quit"; C$ = INPUT$(1) IF C$ = CHR$(27) THEN SYSTEM 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