'***************************************************************************** '* QSAMPLE3.BAS : TIMER DRIVEN DMA * '* LAST MODIFICATION: 2/3/98 * '*****************************************************************************/ ' Dimension the paramter passing variables. DIM task%, stat%, param%(5) 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 A16DRV (task%, BYVAL param%, stat%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT " QSAMPLE3.BAS: TIMER DRIVEN DMA" PRINT PRINT " This is a demonstration program to be used with the AD12-16 A/D" PRINT " board. The program will display sixteen channels using timer driven" PRINT " DMA The program demonstrates initializing the driver(task 0)," PRINT " setting the timers(task 17), setting the scan limits(task 1), performing" PRINT " timer driven DMA(task 6), checking for completion of a back" PRINT " ground task(task 8) and converting the readings returned by the board" PRINT " into channel and counts(task 9)." PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base address is "; HEX$(Address%); " hex" PRINT " -- IRQ5 is used for interrupts (required)" PRINT " -- Polarity set to bipolar (required)" PRINT " -- DMA channel 1 (required)" PRINT " -- On board clock set to 1 MHz (required)" PRINT " -- All remaining jumper settings are irrelevant" PRINT : PRINT : PRINT : PRINT PRINT "Press ENTER to continue" INPUT ""; Msg$ ' Initialize Driver task% = 0 param%(1) = Address% 'assign base address param%(2) = 5 'set IRQ5 param%(3) = 1 'set DMA channel 1 GOSUB HANDLER 'program the base address and int # ' Set timers to divide the board 1 MHz clock by 1000 task% = 17 param%(1) = 100 ' set second timer to divide by 100 param%(2) = 10 ' set second timer to divide by 10 GOSUB HANDLER DO 'set mux channel scan limits task% = 1 param%(1) = 0 'lower channel limit is 0 param%(2) = 15 'upper channel limit is 15 GOSUB HANDLER ' Gather point data via timer controlled DMA CLS task% = 6 param%(1) = 16 'start the scan param%(2) = &H7000 param%(3) = 1 param%(4) = 0 GOSUB HANDLER 'acquire data task% = 8 DO 'Wait for end of scan GOSUB HANDLER LOOP WHILE param%(2) = 0 ' we now can convert the values taken by task 5 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. ' ' calculate the offset to the buffers so the driver can return ' the data. datbuf will contain the data read from the channels and ' pnt buffer will contain the channel. task% = 9 param%(1) = 16 param%(2) = &H7000 param%(3) = 0 param%(4) = VARPTR(datbuf%(1)) param%(5) = VARPTR(pntbuf%(1)) GOSUB HANDLER 'fetch a block of data PRINT " CHANNEL DATA" PRINT " ------- -------" FOR I = 1 TO 16 PRINT USING " ## #####"; pntbuf%(I); datbuf%(I) 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 CLS SYSTEM END IF LOOP END '***************************************************************************** '* FUNCTION: HANDLER -- local routine * '* * '* PURPOSE: Performs the call to the driver package. * '* * '* INPUT: None. * '* * '* CALLS: ao16drv - entry point to driver package. * '* * '* OUTPUT: Returns the error code supplied by the driver routine. * '* * '*****************************************************************************/ HANDLER: stat% = 0 CALL A16DRV(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