DECLARE SUB mc4checkpar (ok$) DECLARE SUB mc4parcheck (ok$) DECLARE SUB mc4movestatussetup () DECLARE SUB mc4movestatus (moving$) '**************************************************************************** 'Module MC4 'This module contains I/O subroutines for the MC4 Klinger stepping motor 'controller. ' 'Zachary Wolf '9/20/95 '**************************************************************************** 'Common area for shared parameters COMMON SHARED /mc4/ gpibinP%, gpiboutP%, mc4addrP$, velcmsP!, acctimeP!, x1P$, x2P$ 'Semi-permanent parameters CONST stepspercmP% = 10000 'number of steps per cm SUB mc4checkpar (ok$) '**************************************************************************** 'This subroutine checks that all required parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '9/18/95 '**************************************************************************** 'Default value ok$ = "n" 'stepspercmP% IF stepspercmP% <> 10000 THEN PRINT "MC4: stepspercm problem" EXIT SUB END IF 'velcmsP! IF INT(velcmsP! * stepspercmP%) < 32 THEN velcmsP! = 32! / stepspercmP% PRINT "MC4: Rate out of range, set to 32 steps/sec." END IF IF INT(velcmsP! * stepspercmP%) > 4000 THEN velcmsP! = 4000! / stepspercmP% PRINT "MC4: Rate out of range, set to 4000 steps/sec." END IF 'acctimeP! IF acctimeP! < .1 THEN acctimeP! = .1 PRINT "MC4: Acceleration time out of range, set to 0.1 sec." END IF IF acctimeP! > 2! THEN acctimeP! = 2! PRINT "MC4: Acceleration time out of range, set to 2 sec." END IF 'x1P$ IF x1P$ = "" THEN PRINT "MC4: Stage 1 identifier not defined" EXIT SUB END IF 'x2P$ IF x2P$ = "" THEN PRINT "MC4: Stage 2 identifier not defined" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB mc4err '**************************************************************************** 'This subroutine reports errors from the MC4 Klinger stepping motor 'controller. ' 'Zachary Wolf '1/22/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Display the error message PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";?" PRINT #gpiboutP%, "ENTER " + mc4addrP$ LINE INPUT #gpibinP%, e$ PRINT e$ END SUB SUB mc4init (gpibin%, gpibout%, mc4addr$) '**************************************************************************** 'This subroutine initializes the MC4 Klinger stepping motor controller. ' 'Input: ' gpibin%, GPIB input file number ' gpibout%, GPIB output file number ' mc4addr$, the MC4 GPIB address in a string ' 'Zachary Wolf '8/24/94 '**************************************************************************** 'Make sure all input parameters have reasonable values IF gpibin% < 0 OR gpibin% > 100 THEN PRINT "MC4: GPIB problem" EXIT SUB END IF IF gpibout% < 0 OR gpibout% > 100 THEN PRINT "MC4: GPIB problem" EXIT SUB END IF IF mc4addr$ = "" THEN PRINT "MC4: GPIB problem" EXIT SUB END IF 'Save the GPIB information in a common block for future use gpibinP% = gpibin% gpiboutP% = gpibout% mc4addrP$ = mc4addr$ 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Message PRINT PRINT "Resetting the MC4 stepping motor controller..." 'Display the MC4 status PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";FS0F" PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";?" PRINT #gpiboutP%, "ENTER " + mc4addrP$ LINE INPUT #gpibinP%, s$ PRINT s$ 'Display the MC4 front panel display PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";DA" PRINT #gpiboutP%, "ENTER " + mc4addrP$ LINE INPUT #gpibinP%, d$ PRINT d$ END SUB SUB mc4moveabs (x!) '**************************************************************************** 'This subroutine moves the stages to position x (cm). ' 'Input: ' x!, the position to move the stages to, in cm ' 'Zachary Wolf '1/22/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Make sure all parameters have been defined with acceptable values CALL mc4checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";ACA"; PRINT #gpiboutP%, USING "#.#"; acctimeP! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";RA"; LTRIM$(STR$(INT(velcmsP! * stepspercmP%))) 'Enable holding torque PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";KAE" 'Convert from cm to number of steps xstep& = x! * stepspercmP% 'Set up the MC4 to give the moving status PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";FS01" 'Move the stages PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";PA" + LTRIM$(STR$(xstep&)) + ".0" 'Wait until the move is finished moving$ = "y" WHILE moving$ <> "n" SLEEP 1 CALL mc4movestatus(moving$) WEND END SUB SUB mc4moverel (dx!) '**************************************************************************** 'This subroutine moves the stages a distance relative to their present position. ' 'Input: ' dx!, the distance to move, in cm ' 'Zachary Wolf '1/15/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Make sure all parameters have been defined with acceptable values CALL mc4checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";ACA"; PRINT #gpiboutP%, USING "#.#"; acctimeP! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";RA"; LTRIM$(STR$(INT(velcmsP! * stepspercmP%))) 'Enable holding torque PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";KAE" 'Get the direction IF dx! >= 0! THEN absdx! = dx! direction$ = "+" ELSE absdx! = -dx! direction$ = "-" END IF 'Convert from cm to number of steps nstep& = absdx! * stepspercmP% 'Set up axis x1 PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";N" + x1P$ + LTRIM$(STR$(nstep&)) '# steps PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" + direction$ + x1P$ 'direction 'Set up axis x2 PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";N" + x2P$ + LTRIM$(STR$(nstep&)) '# steps PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" + direction$ + x2P$ 'direction 'Set up the MC4 to give the moving status PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";FS01" 'Move the stages PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" 'Wait until the move is finished moving$ = "y" WHILE moving$ <> "n" SLEEP 1 CALL mc4movestatus(moving$) WEND END SUB SUB mc4movestatus (moving$) '**************************************************************************** 'This subroutine tells whether the stages are moving (moving$ = "y") 'or not (moving$ = "n"). ' 'Output: ' moving$, "y" or "n" telling if the stages are moving or not ' 'Zachary Wolf '1/22/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Get the moving status 'The MC4 needs to have already received the following command: 'PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";FS01" PRINT #gpiboutP%, "ENTER " + mc4addrP$ LINE INPUT #gpibinP%, status$ 'PRINT status$ 'Determine if a stage is moving moving$ = "n" 'default IF MID$(status$, 1, 1) = "0" THEN 'check for moving status header IF MID$(status$, 2, 1) <> "@" THEN moving$ = "y" 'bit pattern 40H END IF 'PRINT moving$ END SUB SUB mc4setpar (velcms!, acctime!, x1$, x2$) '**************************************************************************** 'This subroutine sets parameter values for the Klinger MC4 stepping 'motor controller. ' 'Input: ' velcms!, the velocity of the stage motion ' acctime!, the acceleration time in sec ' x1$, the channel number of stage 1 ' x2$, the channel number of stage 2 ' 'Zachary Wolf '9/21/95 '**************************************************************************** 'Place the parameters in the local common block for future use velcmsP! = velcms! acctimeP! = acctime! x1P$ = x1$ x2P$ = x2$ END SUB SUB mc4zero '**************************************************************************** 'This subroutine zeros the MC4 Klinger stepping motor controller. ' 'Zachary Wolf '1/15/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Zero all axes PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";AA" END SUB