'*************************************************************** '* * '* QuickBASIC SAMPLE 2:QSAMPLE2.BAS * '* * '* AD12-8 Timer Driven Data Acquisition * '* * '*************************************************************** ' '--------------------------------------------------------------- ' This sample program requires the following setup on the AD12-8 ' card: ' ' voltage jumper = 5V (5 volt range) ' trigger jumper = TMR (timer triggers the A/D) ' interrupt source = EOC (End-of-Conversion causes IRQ) ' interrupt selection = IRQ5 (interrupt request #5) '--------------------------------------------------------------- ' Dimension the paramter passing variables. DIM TASK%, STAT%, PARAM%(5) ' Dimension some buffers. You need data and point buffers. DIM DATBUF%(200), PNTBUF%(200) ' Place all arrays in same segment for use with driver in QB environment COMMON SHARED PARAM%(), DATBUF%(), PNTBUF%() ' This is the driver entry point declaration DECLARE SUB A12DRV (TASK%, BYVAL PARAM%, STAT%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '----------------------- ' Initialize Driver '----------------------- CLS PRINT "SAMPLE 2 AD12-8" PRINT PRINT "This sample will display the analog inputs from an AIM-16." PRINT "NOTE: This program is an interrupt/timer-driven sample." PRINT : PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- BASE ADDRESS: "; HEX$(Address%); " hex" PRINT " -- RANGE: 5 volt range (required)" PRINT " -- POLARITY: Bipolar (required)" PRINT " -- IRQ: 5 (required)" PRINT " -- The TMR must be in the TMR position. (required)" PRINT " -- The EXT EOC jumper must be in the EOC position. (required)" PRINT " -- The AUTO jumper must NOT be installed. (required)" PRINT " -- All remaining jumper positions are irrelevant." PRINT : PRINT PRINT "Please press return to continue."; INPUT "", xx$ TASK% = 0 PARAM%(1) = 1 'manual initialization PARAM%(2) = Address% '<- assigning the Base Address to param[0] 'wish to use a different BASE address. PARAM%(3) = 5 'interrupt number is 5 PARAM%(4) = 5 PARAM%(5) = 1 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 AIM-16 card TASK% = 5 PARAM%(1) = 0 PARAM%(2) = 15 GOSUB handler 'program the counters that trigger the A/D TASK% = 14 PARAM%(1) = 1 PARAM%(2) = 3 PARAM%(3) = 2 'period = 4.47 uSecs GOSUB handler 'counter #1 setup for divide-by-2 on mode 3 PARAM%(1) = 2 PARAM%(2) = 2 PARAM%(3) = 2237 'period = 9.999 mSecs GOSUB handler 'counter #2 setup for 100 samples/sec mode 3 '-------------------------------------------------- 'Assign output range to points 0 thru 5 that will 'convert counts to millivolts at a gain of 1. '(Based on 0-4095 count A/D = 0 to 10 volts.) '-------------------------------------------------- TASK% = 10 PARAM%(1) = 3 'sub-task code PARAM%(2) = 0 'assign to this point PARAM%(3) = -5000 '1st output term (-5 volts) PARAM%(4) = 5000 '2nd output term (+5 volts) GOSUB handler 'replicate point 0 in points 1 thru 15 TASK% = 10 PARAM%(1) = 4 'sub task code PARAM%(2) = 0 'from this point PARAM%(3) = 1 ' to this point PARAM%(4) = 15 'thru this point GOSUB handler '----------------------------------------------------- ' Gather point data via timer controlled interrupts. '----------------------------------------------------- DO TASK% = 9 PARAM%(1) = 1 'start the scan PARAM%(2) = 16 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) = 16 GOSUB handler 'fetch a block of data PRINT " CH DATA GAIN" PRINT " -- ---- ----" PRINT FOR I = 1 TO 16 CH = (PNTBUF%(I) AND &HFF00) / 256 DAT = DATBUF%(I) * .001 GAIN = PNTBUF%(I) AND 255 PRINT USING " ## ##.### ##"; CH; DAT; GAIN NEXT I '----------------------- 'Wait for the operator. '----------------------- PRINT 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 A12DRV(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