Home Chapter 16 Stepper control code

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
Stepper control code


 

X VAR WORD ‘NAME A WORD “X”
EN CON 0 ‘PIN 0, “EN” ENABLES THE MOTOR WHEN LOW
DIR CON 1 ‘PIN 1, “DIR” CONTROLS THE MOTOR DIRECTION
STEPIN CON 2 ‘PIN 2, “STEPIN” SENDS PULSES TO DRIVE MOTOR
HALF CON 3 ‘PIN 3, “HALF” CONTROLS HALF OR FULL STEPS
PHASE CON 4 ‘PIN 4, “PHASE” CONTROLS PHASE INFORMATION

STEPPER: ‘LABLE FOR THE MAIN ROUTINE NAMED “STEPPER”
GOSUB CWONE ‘EXECUTE SUBROUTINE “CWONE”
GOSUB CCWONE ‘EXECUTE SUBROUTINE “CCWONE”
GOSUB CWTWO ‘EXECUTE SUBROUTINE “CWTWO”
GOSUB CCWTWO ‘EXECUTE SUBROUTINE “CCWTWO”
GOSUB CWHALF ‘EXECUTE SUBROUTINE “CWHALF”
GOSUB CCWHALF ‘EXECUTE SUBROUTINE “CCWHALF”
GOTO STEPPER ‘RETURN TO STEPPER

 

CWONE: ‘SUBROUTINE FOR CLOCKWISE ONE PHASE MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
LOW DIR ‘SET MOTOR DIRECTION CLOCKWISE
LOW HALF ‘HAVE MOTOR USE FULL STEPS
HIGH PHASE ‘HAVE MOTOR USE ONE PHASE
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

CCWONE: ‘SUBROUTINE FOR CCW ONE PHASE MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
HIGH DIR ‘SET MOTOR DIRECTION COUNTER CLOCKWISE
LOW HALF ‘HAVE MOTOR USE FULL STEPS
HIGH PHASE ‘HAVE MOTOR USE ONE PHASE
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

CWTWO: ‘SUBROUTINE FOR CLOCKWISE TWO PHASE MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
LOW DIR ‘SET MOTOR DIRECTION CLOCKWISE
LOW HALF ‘HAVE MOTOR USE FULL STEPS
LOW PHASE ‘HAVE MOTOR USE TWO PHASES
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

CCWTWO: ‘SUBROUTINE FOR CCW TWO PHASE MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
HIGH DIR ‘SET MOTOR DIRECTION COUNTER CLOCKWISE
LOW HALF ‘HAVE MOTOR USE FULL STEPS
LOW PHASE ‘HAVE MOTOR USE TWO PHASES
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

CWHALF: ‘SUBROUTINE FOR CLOCKWISE HALF STEP MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
LOW DIR ‘SET MOTOR DIRECTION CLOCKWISE
HIGH HALF ‘HAVE MOTOR USE HALF STEPS
LOW PHASE ‘HAVE MOTOR USE TWO PHASES
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

CCWHALF: ‘SUBROUTINE FOR CCW HALF STEP MOTION
LOW EN ‘ENABLE THE 5804 TO CONRTOL THE MOTOR
HIGH DIR ‘SET MOTOR DIRECTION COUNTER CLOCKWISE
HIGH HALF ‘HAVE MOTOR USE HALF STEPS
LOW PHASE ‘HAVE MOTOR USE TWO PHASES
FOR X = 1 TO 100 ‘SET X=1 AND EXECUTE WHILE 1 < X > 100
LOW STEPIN ‘PREPARE PULSOUT TO GO LOW-HIGH-LOW
PULSOUT STEPIN, 100 ‘CREATE HIGH PULSE ON STEPIN (PIN 2)
PAUSE 200 ‘PAUSE FOR 200 TIME UNITS
NEXT ‘ADD 1 TO X AND GO TO FOR X
HIGH EN ‘DISABLE 5804 CONTROL OF MOTOR
RETURN ‘RETURN TO MAIN ROUTINE STEPPER

coding by Ross Baldwin