'***************************************************************************** '* LAST MODIFICATION: 2/3/98 * '*****************************************************************************/ ' Dimension the paramter passing variables. DIM task%, stat%, param%(7) COMMON SHARED param%() ' Dimension some buffers. You need data and point buffers. DIM datbuf%(200) COMMON SHARED datbuf%() DIM pntbuf%(200) COMMON SHARED pntbuf%() ' This is the driver entry point declaration DECLARE SUB AA16DRV (task%, BYVAL param%, stat%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT " SAMPLE3.BAS : TIMER DRIVEN DMA" PRINT PRINT "The program will display sixteen channels using timer driven DMA." PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configurations:" PRINT PRINT " -- Base address is "; HEX$(Address%); " hex" PRINT " -- Polarity set to bipolar -- S2 TO BIP (required)" PRINT " -- 16 channel single ended mode -- S3 TO 16CH (required)" PRINT " -- Clock set to 1 MHZ -- CLOCK JUMPER TO 1MHZ (required)" PRINT " -- DMA channel 1 -- S1 TO 1 (required)" PRINT " -- All other jumper settings are irrelevant" PRINT PRINT PRINT PRINT "Press ENTER to continue" INPUT ""; Msg$ ' Initialize Driver task% = 0 param%(1) = Address% 'assign base address param%(2) = 5 'voltage range is 5 GOSUB HANDLER ' Set the sample and hold settle count, this is only required for faster ' machines, such as 386's task% = 11 param%(1) = 5 'sub task 5, set settle count param%(2) = 50 '50 settle counts GOSUB HANDLER ' Set up counters 1 and 2 to divide the clock by 1000 to get 100HZ task% = 14 param%(1) = 1 'set up counter 1 param%(2) = 3 'use mode 3 param%(3) = 100 'divisor is 100 GOSUB HANDLER task% = 14 param%(1) = 2 'set up counter 2 param%(2) = 3 'use mode 3 param%(3) = 10 'divisor is 10 GOSUB HANDLER ' Assign all 16 channels of the A/D board to the A/D scan register. task% = 12 param%(1) = 0 'lower point address in range param%(2) = 15 'upper point address in range GOSUB HANDLER ' Set the AIM-16P to channel 0, note that since DMA is a hardware function, ' the driver cannot switch its channels task% = 1 param%(1) = 0 'output 0 to digital bits GOSUB HANDLER ' execute this loop until user enters and ESC at the prompt DO ' Gather point data via DMA task% = 17 param%(1) = 16 'take 16 conversions param%(2) = &H7000 'segment to put conversions param%(3) = 1 'use counters for start conversion param%(4) = 0 'do 1 cycle only param%(5) = 1 'use DMA channel 1 param%(6) = 5 'use IRQ 5 GOSUB HANDLER ' Wait for the end of the DMA scan task% = 9 param%(1) = 2 'sub task 2, check int status DO ' Other code could be executed here GOSUB HANDLER LOOP WHILE param%(2) <> 0 ' we now can convert the values taken by task 17 into channel and ' counts and store in seperate arrays. This needs to be done because ' the board returns a conversion with the count in the upper 12 bits ' of a 16 bit integer and the channel number in the lower 4 bits. task% = 18 param%(1) = 16 'take 16 conversions param%(2) = &H7000 'segment to fetch conversions from param%(3) = 0 ' param%(4) = VARPTR(datbuf%(1)) 'offset of data buffer param%(5) = VARPTR(pntbuf%(1)) 'offset of point buffer GOSUB HANDLER ' Write the results to the screen CLS PRINT " CHANNEL DATA" PRINT " ------- -----" FOR I = 1 TO 16 PRINT USING " ## #####"; pntbuf%(I); datbuf%(I) NEXT I ' Wait for the user. PRINT PRINT "Press any key to rescan the data; press the [Esc] key to Quit"; C$ = INPUT$(1) IF C$ = CHR$(27) THEN CLS SYSTEM END IF LOOP END '***************************************************************************** '* FUNCTION: HANDLER -- local routine * '* * '* PURPOSE: Performs the call to the driver package. * '* * '* INPUT: None. * '* * '* CALLS: aa16drv - entry point to driver package. * '* * '* OUTPUT: Returns the error code supplied by the driver routine. * '* * '*****************************************************************************/ HANDLER: stat% = 0 CALL AA16DRV(task%, VARPTR(param%(1)), stat%) IF stat% THEN 'error has occurred PRINT "TASK"; task%; "has error code"; stat% PRINT "PROGRAM TERMINATED.." SYSTEM 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