SAMPLE #2 (PROGRAM SAMPLE2.BAS ON THE CLCI2000 DISK)
This sample shows two different homing routines that can be used to home the motors. The first routine callled Home Type 0, uses two switches - the first switch causes the motor to ramp down to base speed, and the second switch causes the motor to stop. The second routine, Home Type 1, uses only 1 switch - when the switch is activated the motor will ramp down to base speed, the mechanics need to be made in such a way that the switch will be deactivated when it reaches base speed. When base speed is reached, the motor will reverse direction and will stop once the switch is activated once again.
'PROGRAM FOR QUICKBASIC OR 'VISUALBASIC USING CLCISUB1.BAS
DECLARE ()... | 'this representation is for all the declare statements |
ADDR = &H300 | 'sets up the variable for the board address |
AXIS = 1 | 'sets up the variable for axis 1 |
INITIALIZE ADDR, AXIS | 'initializes axis 1 |
MOTION ADDR, AXIS, 500, 10000, 23000 'sets up the base speed, max speed, and acceleration
HOME.TYPE.1:
'home type 1 requires the switch to be activated and then deactivated (passed) 'while decelerating. The motor will then stop and reverse direction. When the 'switch is then activated, the motor will stop.
LIMIT.CONTROL ADDR, AXIS, 0, 0, 0 | 'soft is not active, mark is not active, home is not active | |
SET.OUTPUT1 ADDR, 0, 0, 0, 0, 0, 1, 0 'sets the HOME.DIR.1 to CW and all outputs off | ||
IF HOME.INPUT(ADDR, AXIS) = 1 THEN END 'if we are already on the limit switch | ||
HOME.CW ADDR, AXIS | 'this will home the motor in the CW direction | |
WHILE HOME.INPUT(ADDR, AXIS) = 0 |
| |
WEND |
|
|
RAMP.TO.STOP.CW ADDR, AXIS |
|
|
WAIT.FOR.STOP ADDR, AXIS |
|
|
LIMIT.CONTROL ADDR, AXIS, 0, 0, 1 | 'soft is not active, mark is not active, home is active | |
SLEW.AT.BASE.CCW ADDR, AXIS |
|
|
WHILE BUSY(ADDR, AXIS) = 1 |
|
|
WEND |
|
|
LIMIT.CONTROL ADDR, AXIS, 0, 0, 0 | 'soft is not active, mark is not active, home is not active |
RETURN
HOME.TYPE.0:
'home type 0 requires two switches - a soft limit switch, and a home limit 'switch. When the soft limit switch is activated, the software will ramp 'the motor down to base speed. The motor will continue traveling until the 'home limit switch is activated.
LIMIT.CONTROL ADDR, AXIS, 0, 0, 1 'soft is not active, mark is not active, home is active SET.OUTPUT1 ADDR, 0, 0, 0, 0, 0, 1, 0 'sets the HOME.DIR.1 to CW and all outputs off
HOME.CW ADDR, AXIS'this will home the motor in the CW direction WHILE SOFT.INPUT.CW(ADDR, AXIS) = 0
WEND
RAMP.TO.BASE.CW ADDR, AXIS END
16