' Program STEP.BAS ' The Stamp accepts simply formatted commands and drives a four-coil ' stepper. Commands are formatted as follows: +500 20 means ' rotate forward 500 steps with 20 milliseconds between steps. To ' run the stepper backward, substitute - for +. Symbol Directn = b0 Symbol Steps = w1 Symbol i = w2 Symbol Delay = b6 Symbol Dir_cmd = b7 dirs = %01000011 : pins = %00000001 ' Initialize output. b1 = %00000001 : Directn = "+" goto Prompt ' Display prompt. ' Accept a command string consisting of direction (+/-), a 16-bit number ' of steps, and an 8-bit delay (milliseconds) between steps. If longer ' step delays are required, just command 1 step at a time with long ' delays between commands. Cmd: serin 7,N2400,Dir_cmd,#Steps,#Delay ' Get orders from terminal. if Dir_cmd = Directn then Stepit ' Same direction? Begin. b1 = b1^%00000011 ' Else reverse. Stepit: for i = 1 to Steps ' Number of steps. pins = pins^b1 ' XOR output with b1, then invert b1 to b1 = b1^%00000011 ' calculate the stepping sequence. pause Delay ' Wait commanded delay between steps. next Directn = Dir_cmd ' Direction = new direction. Prompt: serout 6,N2400,(10,13,"step> ") ' Show prompt, send return goto Cmd ' and linefeed to terminal. -------------------------------------------------------------------------- ' *** STEPPER MOTOR DEMO USING "BASIC STAMP". JIM GILLESPIE 4/1/93 ' *** CAUSES 240 HALF-STEPS CLOCKWISE THEN COUNTER CLOCKWISE ' *** USES BS170 TMOS TRANSISTORS DRIVEN FROM PORT PINS 0 - 3 OUTPUT 0 ' STEPPER MOTOR OUTPUTS TO BS170 DRIVERS OUTPUT 1 OUTPUT 2 OUTPUT 3 ' EEPROM (1,3,2,6,4,12,8,9) ' HALF STEP DATA TABLE TO EEPROM ' PINS = 0 ' OUTPUTS ALL ZERO FOR NOW ' LOOP1:FOR B3= 0 TO 30 ' 30 TIMES IN ONE DIRECTION THIS LOOP FOR B4 = 0 TO 7 ' 8 STEPS IN THIS LOOP (8*30=240 STEPS) READ B4,B5 ' (LOC. B4 (EEPROM)) GOES TO B5 PINS = B5 ' OUTPUT STEPPER PATTERN 'DEBUG PINS PAUSE 10 ' WAIT AWHILE (DETERMINES SPEED) NEXT B4 ' YOU GET THE IDEA NEXT B3 ' DONE 30 LOOPS? ' 240 STEPS CLOCKWISE. NOW CHANGE DIRECTION FOR B3=0 TO 30 ' SAME IDEA AS ABOVE ONLY GET VALUES FOR B4 = 7 TO 0 STEP -1 ' FROM TABLE BAS ACKWARDS READ B4,B5 PINS = B5 PAUSE 10 NEXT B4 NEXT B3 GOTO LOOP1 ' DO IT ALL OVER AGAIN --------------------------------------------------------------------------- ' *** STEPPER MOTOR DEMO USING "BASIC STAMP". JIM GILLESPIE 4/1/93 ' *** CAUSES 240 HALF-STEPS CLOCKWISE THEN COUNTER CLOCKWISE ' *** USES BS170 TMOS TRANSISTORS DRIVEN FROM PORT PINS 0 - 3 OUTPUT 0 ' STEPPER MOTOR OUTPUTS TO BS170 DRIVERS OUTPUT 1 OUTPUT 2 OUTPUT 3 ' EEPROM (1,3,2,6,4,12,8,9) ' HALF STEP DATA TABLE TO EEPROM ' PINS = 0 ' OUTPUTS ALL ZERO FOR NOW ' LOOP1:FOR B3= 0 TO 30 ' 30 TIMES IN ONE DIRECTION THIS LOOP FOR B4 = 0 TO 7 ' 8 STEPS IN THIS LOOP (8*30=240 STEPS) READ B4,B5 ' (LOC. B4 (EEPROM)) GOES TO B5 PINS = B5 ' OUTPUT STEPPER PATTERN 'DEBUG PINS PAUSE 10 ' WAIT AWHILE (DETERMINES SPEED) NEXT B4 ' YOU GET THE IDEA NEXT B3 ' DONE 30 LOOPS? ' 240 STEPS CLOCKWISE. NOW CHANGE DIRECTION FOR B3=0 TO 30 ' SAME IDEA AS ABOVE ONLY GET VALUES FOR B4 = 7 TO 0 STEP -1 ' FROM TABLE BAS ACKWARDS READ B4,B5 PINS = B5 PAUSE 10 NEXT B4 NEXT B3 GOTO LOOP1 ' DO IT ALL OVER AGAIN