DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT "***************************************************************************" PRINT "* QSAMPLE2.BAS : DA1616 *" PRINT "* *" PRINT "* This sample will generate 3 different wave forms, sine, triangle and *" PRINT "* saw tooth. The user has the choice of base address, DAC number and the*" PRINT "* number of points per cycle. *" PRINT "* *" PRINT "* *" PRINT "* Board Configuration: *" PRINT "* *" PRINT "* -- Base address should be set to the address which will be entered *" PRINT "* during program execution. *" PRINT "* -- The board should be set to bipolar mode (required) *" PRINT "* -- All remaining jumper settings are irrelevant. *" PRINT "* *" PRINT "***************************************************************************" PRINT : PRINT : PRINT : PRINT INPUT "Press ENTER to continue"; Msg$ '*************************************************************************** '* FUNCTION: main - local routine * '* PURPOSE: Controls program execution. * '*************************************************************************** CONST PI = 3.1415927# DIM progstruct&(10000) ' buffer to hold points CLS FOR channelnum = 0 TO 16 ' set all 16 buffers to 0 OUT Address% + (2 * channelnum), &H8000 OUT Address% + (2 * channelnum + 1), &H8000 NEXT channelnum channelnum = INP(Address% + 10) ' remove from simultaneous ' mode and update all ' channels DO GOSUB menulist ' display menu IF menuchoice$ = "1" THEN GOSUB setparms ' fetch system params ELSEIF menuchoice$ = "2" THEN GOSUB sinecurve ' generate sine wave ELSEIF menuchoice$ = "3" THEN GOSUB trianglecurve ' generate triangle wave ELSEIF menuchoice$ = "4" THEN GOSUB sawcurve ' generate saw tooth wave END IF LOOP UNTIL menuchoice$ = "5" END '*************************************************************************** '* FUNCTION: menulist - local routine * '* PURPOSE: Display the menu choise on the screen. * '*************************************************************************** menulist: CLS PRINT PRINT PRINT PRINT "Your menu selections are: " PRINT "1. Input Board Data (do this first)" PRINT "2. Sine curve" PRINT "3. Triangle curve " PRINT "4. Saw curve" PRINT "5. End program, return to DOS" PRINT "Input Choice: " menuchoice$ = INPUT$(1) RETURN '*************************************************************************** '* FUNCTION: setparams - local routine * '* PURPOSE: Prompts the user for DAC number, base address and the number * '* of points per cycle. * '*************************************************************************** setparms: CLS Address% = AskForBaseAddress!(&H350) PRINT : PRINT : PRINT INPUT ; "Enter the DAC number you wish to output to (0 through 15 only): "; dacnum WHILE dacnum < 0 OR dacnum > 15 LOCATE 7, 65 PRINT " " LOCATE 7, 65 INPUT dacnum WEND PRINT : PRINT : PRINT PRINT "Enter the number of points you wish to calculate per cycle," INPUT ; "(10000 maximum, program will use modulus if needed): "; counts& counts& = counts& MOD 10001 RETURN '*************************************************************************** '* FUNCTION: sinecurve - local routine * '* PURPOSE: Calculate the points for creating a sine wave. * '***************************************************************************) sinecurve: IF counts& = 0 THEN RETURN ' no point -- no curve CLS PRINT "Calculating sine wave points....." rads# = 2! * PI / counts& ' rad per count FOR i& = 1 TO counts& sine# = (SIN(rads# * (i& - 1)) + 1!) * 32767 progstruct&(i&) = sine# NEXT i& CLS PRINT "Generating sine wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* FUNCTION: trianglecurve - local routine * '* PURPOSE: Calculate the points for creating a triangle wave. * '*************************************************************************** trianglecurve: IF counts& = 0 THEN RETURN ' no counts -- no curve CLS PRINT "Calculating triangle wave points....." slope# = 65535! / counts& * 2! ' wave form slope FOR i& = 1 TO counts& / 2 temp# = INT(slope# * i&) progstruct&(i&) = temp# progstruct&(i& + INT(counts& / 2)) = (65535 - temp#) NEXT i& CLS PRINT "Generating triangle wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* FUNCTION: sawcurve - local routine * '* PURPOSE: Calculate the points for creating a saw tooth wave. * '*************************************************************************** sawcurve: IF counts& = 0 THEN RETURN CLS PRINT "Calculating saw tooth wave points....." slope# = 65535 / counts& ' saw tooth slope FOR i& = 1 TO counts& progstruct&(i&) = INT(slope# * i&) NEXT i& CLS PRINT "Generating saw tooth wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* FUNCTION: sendtoport - local routine * '* PURPOSE: Writes the point buffer to the DAC until a key is pressed. * '*************************************************************************** sendtoport: ' each point is broken into the hi byte and low byte, and then written to ' the DAC into two seperate bytes. *) DO FOR i& = 1 TO counts& temp# = INT(progstruct&(i&) MOD 256) lowbyte% = temp# temp# = INT(progstruct&(i&) / 256) hibyte% = temp# OUT Address% + dacnum * 2, lowbyte% OUT Address% + (dacnum * 2 + 1), hibyte% NEXT i& LOOP UNTIL INKEY$ <> "" OUT Address% + dacnum * 2, 0 ' set DAC to 0 output OUT Address% + (dacnum * 2 + 1), 0 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