'Dimension the parameter passing variables DIM task%, status%, params%(10) COMMON SHARED params%() 'Declare the driver entry point DECLARE SUB ctr5drv (task%, BYVAL params%, status%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT " QSAMPLE2.BAS : FREQUENCY MEASUREMENT " PRINT " " PRINT " This is a demonstration program to be used with the CTR-5 Counter " PRINT " timer board. The program will measure frequency from about 1Hz up to " PRINT " 32KHz. By changing the number of 1ms periods, the frequency range can " PRINT " be changed, but resolution is still only 16 bits. A modification of this" PRINT " program cascading two counters could yield 32 bit accuracy. " PRINT " " PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT " Board Configuration: " PRINT PRINT " -- Base address is "; HEX$(Address%); " hex " PRINT " -- On board clock should be set to 1 MHz (required) " PRINT " -- Input is applied to pin 13, counter 5 input. (required) " PRINT " -- All remaining jumper settings should not be altered." PRINT : PRINT : PRINT INPUT "Press ENTER to continue"; Msg$ '* LAST MODIFICATION: 2/5/98 '***************************************************************************** '* PROCEDURE: main -- local routine * '* * '* PURPOSE: Controls program flow, detects when user is ready to exit. * '* * '* INPUT: None. * '* * '* CALLS: setup - set up program and drivers. * '* getreadings - read the frequency. * * '***************************************************************************** GOSUB setup 'set up program and the driver IF status% <> 0 THEN SYSTEM 'if status > 0 then board error DO UNTIL CH$ <> "" GOSUB getreadings CH$ = INKEY$ LOOP QUIT: CLS SYSTEM ' end main program '***************************************************************************** '* PROCEDURE: setup -- local routine * '* * '* PURPOSE: Sets up the driver and counter board. * '* * '* INPUT: None. * '* * '* CALLS: calldriver - entry point to driver package. * '* * '***************************************************************************** setup: CLS LOCATE 10, 20 PRINT "FREQUENCY: Hz" ' display frequency label on screen LOCATE 14, 17 PRINT "Press any key to exit the program." ' initialize the board params%(1) = Address% ' starting board address params%(2) = 1 ' FOUT divider ratio = 1 params%(3) = 14 ' FOUT source = F4 params%(4) = 0 ' counter 2 compare disabled params%(5) = 0 ' counter 1 compare disabled params%(6) = 0 ' disable time of day task% = 0 GOSUB calldriver RETURN 'END setup '***************************************************************************** '* PROCEDURE: getreadings -- local routine * '* * '* PURPOSE: Uses the driver to measure the freqency of an input. * '* * '* INPUT: None. * '* * '* CALLS: calldriver - entry point to driver package. * '* * '***************************************************************************** getreadings: params%(1) = 1000 ' 1000 1ms intervals = 1 second params%(2) = 5 ' counter 5 input is source params%(3) = 0 ' this param returns counts task% = 10 GOSUB calldriver LOCATE 10, 31 PRINT USING "########"; params%(3) ' display the value RETURN '***************************************************************************** '* PROCEDURE: call_driver -- local routine * '* * '* PURPOSE: Performs the call to the driver package. * '* * '* INPUT: None. * '* * '* CALLS: ctr5drv - entry point to driver package. * '* * '***************************************************************************** calldriver: CALL ctr5drv(task%, VARPTR(params%(1)), status%) IF status% > 0 THEN ' an error has occured PRINT "A status error code of"; status%; " was detected." 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