DECLARE SUB dac488hrsetcv (c%, v!) DECLARE SUB dac488hrgetcv (c%, dacv!) DECLARE SUB gpibclr () DECLARE SUB dac488hrsetupcv (c%) DECLARE SUB dac488hrsetupv () '**************************************************************************** 'Module DAC488HR 'This module contains I/O subroutines for the DAC488HR. ' 'Zachary Wolf '5/8/95 '**************************************************************************** 'Common area for shared parameters COMMON SHARED /dac488hr/ gpibinP%, gpiboutP%, dac488hraddrP$ SUB dac488hrdo0 (d%) '**************************************************************************** 'This subroutine has the IOTech DAC488 output a low TTL level on digital line 'number d% (1 to 8). The other lines are not changed. ' 'Input: ' d%, line number 1 to 8 ' 'Zachary Wolf '6/24/94, 8/9/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Get the existing output digital port configuration PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";D? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ INPUT #gpibinP%, p$ 'Remove the leading D p$ = MID$(p$, 2) 'Extract the value p% = VAL(p$) 'Convert the line number to an integer with the appropriate bit pattern dp% = 2 ^ (d% - 1) 'Leave existing lines alone, except make line d% low dp% = NOT dp% p% = p% AND dp% 'Get the integer equivalent of the bit pattern and put it in a string p$ = LTRIM$(STR$(p%)) 'Send the new port configuration PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";D" + p$ + " X" END SUB SUB dac488hrdo1 (d%) '**************************************************************************** 'This subroutine has the IOTech DAC488 output a high TTL level on digital line 'number d% (1 to 8). The other lines are not changed. ' 'Input: ' d%, line number 1 to 8 ' 'Zachary Wolf '6/24/94, 8/9/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Get the existing output digital port configuration PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";D? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ INPUT #gpibinP%, p$ 'Remove the leading D p$ = MID$(p$, 2) 'Extract the value p% = VAL(p$) 'Convert the line number to an integer with the appropriate bit pattern dp% = 2 ^ (d% - 1) 'Leave existing lines alone, except make line d% high p% = p% OR dp% 'Get the integer equivalent of the bit pattern and put it in a string p$ = LTRIM$(STR$(p%)) 'Send the new port configuration PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";D" + p$ + " X" END SUB SUB dac488hrerr '**************************************************************************** 'This subroutine gets error messages from the IOTech DAC488HR/2. ' 'Zachary Wolf '9/21/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Perform the error query PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";E? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, a$ PRINT PRINT "DAC488HRERR error status: "; a$ END SUB SUB dac488hrgetcv (c%, dacv!) '**************************************************************************** 'This subroutine gets the output voltage from the IOTech DAC488HR/2 output. ' 'Input: ' c%, the DAC channel to give the voltage for ' 'Output: ' dacv!, the DAC voltage which is being output ' 'Zachary Wolf '4/19/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Test the channel number IF c% < 1 OR c% > 2 THEN PRINT "DAC488HRGETCV: Bad channel number." EXIT SUB END IF 'Set the output port to # c% c$ = LTRIM$(STR$(c%)) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P" + c$ + " X" 'Get the DAC voltage value PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";V? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ INPUT #gpibinP%, dacv$ dacv$ = MID$(dacv$, 2) dacv! = VAL(dacv$) END SUB SUB dac488hrid '**************************************************************************** 'This subroutine initializes the IOTech DAC488HR/2. ' 'Zachary Wolf '4/19/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Message PRINT PRINT "Verifying the DAC..." 'Get the DAC ID PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";U9 X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, a$ PRINT a$ END SUB SUB dac488hrinit '**************************************************************************** 'This subroutine initializes the IOTech DAC488HR/2. ' 'Zachary Wolf '4/19/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Message PRINT PRINT "Resetting the DAC..." 'Reset the DAC PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";*RX" 'Wait until the DAC is reset SLEEP 2 spoll! = 0 WHILE NOT spoll AND 4 PRINT #gpiboutP%, "SPOLL " + dac488hraddrP$ INPUT #gpibinP%, spoll! ' PRINT "spoll = "; spoll! SLEEP 1 WEND 'Get the DAC ID PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";U9 X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, a$ PRINT a$ 'Setup for voltage output FOR c% = 1 TO 2 CALL dac488hrsetupcv(c%) NEXT c% 'Clear the GPIB system after an spoll CALL gpibclr END SUB SUB dac488hrsetcv (c%, v!) '**************************************************************************** 'This subroutine has the IOTech DAC488HR/2 output a voltage v! on channel c%. ' 'Input: ' c%, the DAC channel to output the voltage on ' v!, the voltage to output ' 'Zachary Wolf '4/19/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Test the channel number IF c% < 1 OR c% > 2 THEN PRINT "DAC488HRGETCV: Bad channel number." EXIT SUB END IF 'Set the output port to # c% c$ = LTRIM$(STR$(c%)) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P" + c$ + " X" 'Make sure the voltage is within the proper range IF v! < 0! THEN v! = 0! IF v! > 5! THEN v! = 5! 'Output the voltage to the DAC PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";V"; PRINT #gpiboutP%, USING "###.#####"; v!; PRINT #gpiboutP%, " X" END SUB SUB dac488hrsetpar (gpibin%, gpibout%, dac488hraddr$) '**************************************************************************** 'This subroutine sets the parameters for the IOTech DAC488HR. ' 'Input: ' gpibin%, gpib input file number ' gpibout%, gpib output file number ' dac488hraddr$, gpib address in a string ' 'Zachary Wolf '6/24/94, 7/19/95 '**************************************************************************** 'Make sure the input parameters have reasonable values IF gpibin% < 0 OR gpibin% > 100 THEN PRINT "DAC488HR: GPIB problem" EXIT SUB END IF IF gpibout% < 0 OR gpibout% > 100 THEN PRINT "DAC488HR: GPIB problem" EXIT SUB END IF IF dac488hraddr$ = "" THEN PRINT "DAC488HR: GPIB problem" EXIT SUB END IF 'Save the GPIB information in a common block for future use gpibinP% = gpibin% gpiboutP% = gpibout% dac488hraddrP$ = dac488hraddr$ END SUB SUB dac488hrsetupcv (c%) '**************************************************************************** 'This subroutine sets up the IOTech DAC488HR/2 for static DC output. ' 'Input: ' c%, DAC channel to set up ' 'Zachary Wolf '4/19/94 '**************************************************************************** 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Test the channel number IF c% < 1 OR c% > 2 THEN PRINT "DAC488HRGETCV: Bad channel number." EXIT SUB END IF 'Set the output port to # c% c$ = LTRIM$(STR$(c%)) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P" + c$ + " X" 'Set the voltage range to 5 V unipolar 'PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";R7 X" PRINT "Voltage range: 0V -> 1V" PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";R5 X" 'Set the data format to signed volts PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";F0 X" 'Set the initial voltage value to 0 PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";V0 X" END SUB SUB dac488wavegen (c%, rr!, vini!, vfin!, iperv!) 'If there is no change in the current setting then no ramp is necessary IF (vfin! = vini!) THEN EXIT SUB 'No ramp necessary '************************************************************************ ' Have the DAC488HR output the last output voltage from the previous ramp. 'Get the present data buffer pointer location PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";L? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, l$ 'Set the data buffer pointer to the last output voltage dbl% = VAL(MID$(l$, 2)) - 1 'If there was no previous output voltage then dbl% < 0 IF dbl% < 0 THEN dbl% = 0 'Pointer location can not be < 0 'Set the dac488hr to the last data buffer and read the voltage l$ = LTRIM$(STR$(dbl%)) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";L" + l$ + " X" PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";B? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, b$ vini! = VAL(MID$(b$, 2)) 'This is the last voltage to be output on the previous ramp 'If pointer location is 0 then there was no previous ramp IF dbl% = 0 THEN vini! = 0 'No previous ramp or output voltage 'Output the initial vini! voltage (continuous output mode) CALL dac488hrsetcv(c%, vini!) CALL dac488hrgetcv(c%, vini!) 'PRINT "Voltages: "; vini!; vfin! 'Set the data buffer pointer back to 0 (ready to load new waveform) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";L0 X" '************************************************************************ ' Calculate the necessary parameters for the DAC488HR ramp waveform 'Calculate parameters for upramp or downramp waveform vrange! = 1! 'DAC488HR outout voltage range IF (vfin! > vini!) THEN sym$ = "0" 'Ramp upwards maxv% = 100 * vfin! / vrange! 'MaxV (%) of maximum output voltage minv% = 100 * (vini! - vrange!) / vrange! 'MinV (%) of minimum output voltage ELSE sym$ = "100" 'Ramp downwards maxv% = 100 * vini! / vrange! 'MaxV (%) of maximum output voltage minv% = 100 * (vfin! - vrange!) / vrange! 'MinV (%) of minimum output voltage END IF max$ = LTRIM$(STR$(maxv%)) min$ = LTRIM$(STR$(minv%)) 'Calculate the number of voltage samples the dac488hr is to generate samples% = ABS(((vfin! - vini!) * iperv! / rr!) / .01) IF (samples% < 33) OR (samples% > 8000) THEN PRINT "DAC488HR: Waveform Generation outside sample limit (33<->8000): "; samples% STOP END IF sam$ = LTRIM$(STR$(samples%)) '************************************************************************ ' Load the internal buffer of the DAC488HR with the output voltages ' ''Set the output port to # c% 'c$ = LTRIM$(STR$(c%)) 'PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P" + c$ + " X" ' ''Set the data buffer pointer back to 0 (ready to load new waveform) 'PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";L0 X" ' ''Find the size of each voltage step 'vstep! = (vfin! - vini!) / samples% 'PRINT : PRINT "V fin & ini: "; vfin!; vini! 'PRINT "Samples and Vstep: "; samples%; vstep! ' ''Compute the voltage at each step 'PRINT "Loading DAC488HR internal buffer..." 'FOR i% = 0 TO samples% ' vout! = vini! + vstep! * i% ' 'Output the voltage to the DAC ' PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";B"; ' PRINT #gpiboutP%, USING "###.#####"; vout!; ' PRINT #gpiboutP%, " X" 'NEXT i% 'PRINT "Voltages: "; vout!; vini!; vstep! 'PRINT "Load Complete" ' '************************************************************************ 'Send the DAC488HR the parameters to generate and output the waveform 'Load triangular ramp wave 'Settings (example): 500 samples, MaxV=100%, MinV=-100%, 0% Symetry(upramp) wavesetting$ = ";W1," + sam$ + "," + max$ + "," + min$ + "," + sym$ + " X" PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + wavesetting$ 'PRINT : PRINT "DAC488HR waveform: "; wavesetting$ 'Query present waveform load configuration PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";W? X" PRINT #gpiboutP%, "ENTER " + dac488hraddrP$ LINE INPUT #gpibinP%, a$ 'Wait while the dac488hr generates the waveform and fills the data buffer waittime! = samples% / 1700 'Generation rate: 1700 points/second strt! = TIMER WHILE TIMER - strt! < waittime! WEND 'Set the control block for output voltage control by the dac488hr PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P1 X" 'Select ouput port PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";O0 X" 'Set sequence pointer to 0 PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";Q0,0,0 X" 'Delete control block cntrlblk$ = ";Q0," + sam$ + ",1 X" PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + cntrlblk$ 'Define new control block PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";O0 X" 'Set sequence pointer back to 0 'PRINT "Control block written:"; cntrlblk$ 'Set the buffer count to 1 (the # of times the data buffer is repeated) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";K1 X" '************************************************************************ 'The DAC488HR is now programmed with a new ramp waveform. 'To have the DAC488HR output the ramp waveform call dac488wavestrt END SUB SUB dac488waveinit 'Initialize waveform for DAC488HR output port c% c% = 1 'Set the GPIB terminators for the DAC PRINT #gpiboutP%, "TERM OUT LF EOI" PRINT #gpiboutP%, "TERM IN LF EOI" 'Set the output port to c% c$ = LTRIM$(STR$(c%)) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";P" + c$ + " X" 'Set buffer mode to complex PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";A1 X" 'Set the voltage range: 0V to 5V unipolar 'PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";R7 X" PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";R5 X" 'Set update source mode to 200kHz synchronous (default) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";G3 X" 'Set update divider to 200 (output=> 200kHz/2000 = 100Hz or dt=0.01sec) PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";I2000 X" 'Set the data buffer pointer location to 0 PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";L0 X" END SUB SUB dac488wavestrt 'Set the GPIB terminators for the DAC 'PRINT #gpiboutP%, "TERM OUT LF EOI" 'PRINT #gpiboutP%, "TERM IN LF EOI" 'Start outputting the waveform; Immediate mode PRINT #gpiboutP%, "OUTPUT " + dac488hraddrP$ + ";C4X" END SUB