DECLARE SUB mc4checkpar (ok$) 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$ 'Semi-permanent parameters CONST stepspercmP% = 10000 'number of steps per cm 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 '**************************************************************************** 'This subroutine initializes the MC4 Klinger stepping motor controller. ' 'Zachary Wolf '8/24/94 '**************************************************************************** '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 mc4move2rel (s1$, s2$, at!, v!, dx!) '**************************************************************************** 'This subroutine moves two stages simultaneously a given distance 'relative to their present position. 'It assumes the two stages are all the stages in the system!!! ' 'Input: ' s1$, stage 1 axis name ' s2$, stage 2 axis name ' at!, acceleration time in sec ' v!, velocity in cm per sec ' 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" 'Check s1$ IF s1$ = "" THEN PRINT "MC4: axis 1 not defined" EXIT SUB END IF 'Check s2$ IF s2$ = "" THEN PRINT "MC4: axis 2 not defined" EXIT SUB END IF 'Check at! IF at! < .1 THEN at! = .1 PRINT "MC4: Acceleration time out of range, set to 0.1 sec." END IF IF at! > 2! THEN at! = 2! PRINT "MC4: Acceleration time out of range, set to 2 sec." END IF 'Check v! IF INT(v! * stepspercmP%) < 32 THEN v! = 32! / stepspercmP% PRINT "MC4: Rate out of range, set to 32 steps/sec." END IF IF INT(v! * stepspercmP%) > 4000 THEN v! = 4000! / stepspercmP% PRINT "MC4: Rate out of range, set to 4000 steps/sec." END IF 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";ACA"; PRINT #gpiboutP%, USING "#.#"; at! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";RA"; LTRIM$(STR$(INT(v! * 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 s1 PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";N" + s1$ + LTRIM$(STR$(nstep&)) '# steps PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" + direction$ + s1$ 'direction 'Set up axis s2 PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";N" + s2$ + LTRIM$(STR$(nstep&)) '# steps PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" + direction$ + s2$ '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 mc4moveabs (s$, at!, v!, x!) '**************************************************************************** 'This subroutine moves all stages simultaneously to position x (cm). ' 'Input: ' s$, axis name of the stage ' at!, acceleration time in sec ' v!, stage velocity in cm/sec ' 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" 'Check s$ IF s$ = "" THEN PRINT "MC4: axis not defined" EXIT SUB END IF 'Check at! IF at! < .1 THEN at! = .1 PRINT "MC4: Acceleration time out of range, set to 0.1 sec." END IF IF at! > 2! THEN at! = 2! PRINT "MC4: Acceleration time out of range, set to 2 sec." END IF 'Check v! IF INT(v! * stepspercmP%) < 32 THEN v! = 32! / stepspercmP% PRINT "MC4: Rate out of range, set to 32 steps/sec." END IF IF INT(v! * stepspercmP%) > 4000 THEN v! = 4000! / stepspercmP% PRINT "MC4: Rate out of range, set to 4000 steps/sec." END IF 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";AC" + s$; PRINT #gpiboutP%, USING "#.#"; at! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";R" + s$ + LTRIM$(STR$(INT(v! * stepspercmP%))) 'Enable holding torque PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";K" + s$ + "E" '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 stage PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";P" + s$ + LTRIM$(STR$(xstep&)) + ".0" 'Wait until the move is finished moving$ = "y" WHILE moving$ <> "n" SLEEP 1 CALL mc4movestatus(moving$) WEND END SUB SUB mc4moveallabs (at!, v!, x!) '**************************************************************************** 'This subroutine moves all stages simultaneously to position x (cm). ' 'Input: ' at!, acceleration time in sec ' v!, stage velocity in cm/sec ' 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" 'Check at! IF at! < .1 THEN at! = .1 PRINT "MC4: Acceleration time out of range, set to 0.1 sec." END IF IF at! > 2! THEN at! = 2! PRINT "MC4: Acceleration time out of range, set to 2 sec." END IF 'Check v! IF INT(v! * stepspercmP%) < 32 THEN v! = 32! / stepspercmP% PRINT "MC4: Rate out of range, set to 32 steps/sec." END IF IF INT(v! * stepspercmP%) > 4000 THEN v! = 4000! / stepspercmP% PRINT "MC4: Rate out of range, set to 4000 steps/sec." END IF 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";ACA"; PRINT #gpiboutP%, USING "#.#"; at! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";RA"; LTRIM$(STR$(INT(v! * 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 all 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 (s$, at!, v!, dx!) '**************************************************************************** 'This subroutine moves a stage a given distance relative to its present 'position. ' 'Input: ' s$, stage axis name ' at!, acceleration time in sec ' v!, velocity in cm per sec ' dx!, the distance to move, in cm ' 'Zachary Wolf '12/12/95 '**************************************************************************** 'Set the GPIB terminators PRINT #gpiboutP%, "TERM IN CR LF" PRINT #gpiboutP%, "TERM OUT CR LF" 'Check s$ IF s$ = "" THEN PRINT "MC4: axis not defined" EXIT SUB END IF 'Check at! IF at! < .1 THEN at! = .1 PRINT "MC4: Acceleration time out of range, set to 0.1 sec." END IF IF at! > 2! THEN at! = 2! PRINT "MC4: Acceleration time out of range, set to 2 sec." END IF 'Check v! IF INT(v! * stepspercmP%) < 32 THEN v! = 32! / stepspercmP% PRINT "MC4: Rate out of range, set to 32 steps/sec." END IF IF INT(v! * stepspercmP%) > 4000 THEN v! = 4000! / stepspercmP% PRINT "MC4: Rate out of range, set to 4000 steps/sec." END IF 'Set the acceleration PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";AC" + s$; PRINT #gpiboutP%, USING "#.#"; at! 'Set the velocity PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";R" + s$ + LTRIM$(STR$(INT(v! * stepspercmP%))) 'Enable holding torque PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";K" + s$ + "E" '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 motion info PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";N" + s$ + LTRIM$(STR$(nstep&)) '# steps PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";" + direction$ + s$ 'direction 'Set up the MC4 to give the moving status PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";FS01" 'Move the stage PRINT #gpiboutP%, "OUTPUT " + mc4addrP$ + ";M" + s$ '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 (gpibinf%, gpiboutf%, mc4addr$) '**************************************************************************** 'This subroutine sets parameter values for the Klinger MC4 stepping 'motor controller. ' 'Input: ' gpibinf%, GPIB input file number ' gpiboutf%, GPIB output file number ' mc4addr$, the MC4 GPIB address in a string ' 'Zachary Wolf '9/21/95 '**************************************************************************** 'Make sure all GPIB parameters have reasonable values IF gpibinf% < 0 OR gpibinf% > 100 THEN PRINT "MC4: GPIB problem" EXIT SUB END IF IF gpiboutf% < 0 OR gpiboutf% > 100 THEN PRINT "MC4: GPIB problem" EXIT SUB END IF IF mc4addr$ = "" THEN PRINT "MC4: GPIB problem" EXIT SUB END IF 'Place the parameters in the local common block for future use gpibinP% = gpibinf% gpiboutP% = gpiboutf% mc4addrP$ = mc4addr$ 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