'{$STAMP BS2} ' ============================================================================== ' File...... Ex26 - Stepper.BS2 ' Purpose... Stepper Motor Control ' E-mail.... stamptech@parallaxinc.com ' Started... ' Updated... 01 MAY 2002 ' {$STAMP BS2} ' ============================================================================== ' ------------------------------------------------------------------------------ ' Program Description ' ------------------------------------------------------------------------------ ' This program demonstrates unipolar stepper motor control. The pot allows the ' program to control speed and direction of the motor. ' ------------------------------------------------------------------------------ ' Revision History ' his version revised by Perry Hoberman 11/03 for CTIN534 class to ' use only one side (instead of both) of a 10K potentiometer for control ' '------------------------------------------------------------------------------- ' Revision History ' Revised March - Feb 2003 Bob Baer (rbaer@physics.siu.edu) ' for dual stepper motor logic control. ' Motor turns left or right in single steps based on pulse width of ' logic signal to p0 - motor 1 or p1 - motor 2. ' ' 5.17.2004 modify to use one input pulse to control the two motors ' ' ' ------------------------------------------------------------------------------ ' ------------------------------------------------------------------------------ ' I/O Definitions ' ------------------------------------------------------------------------------ PulseA CON 0 ' A motor input 'PulseB CON 1 ' B motor input ' PotCW CON 0 'clockwise pot input CoilsA VAR OutB ' output to motor A (pins 4, 5, 6, 7) CoilsB VAR OutC ' output to motor B (pins 8, 9, 10, 11) ' ------------------------------------------------------------------------------ ' Variables ' ------------------------------------------------------------------------------ speed VAR Word ' delay between steps x VAR Byte ' loop counter sAddrA VAR Byte ' EE address of step data for motor A sAddrB VAR Byte ' EE address of step data for motor B rcA VAR Word ' remote control reading motor A rcB VAR Word ' remote control reading motor B ' diff VAR Word ' difference between readings ' ' motor A stepping at 1/2 steps, motor B stepping at full steps. ' ' ------------------------------------------------------------------------------ ' EEPROM Data Steps for motor A and B ' ------------------------------------------------------------------------------ ' ABAB ' ----- Step1A DATA %1100 Step2A DATA %0110 Step3A DATA %0011 Step4A DATA %1001 Step1B DATA %1100 Step2B DATA %0110 Step3B DATA %0011 Step4B DATA %1001 ' ------------------------------------------------------------------------------ ' Initialization ' ------------------------------------------------------------------------------ Initialize: DirB = %1111 'make stepper pins 4, 5, 6, 7 outputs DirC = %1111 ' make stepper pins 8,9,10,11 outputs speed = 0 'set starting speed sAddrA = 0 saddrB = 0 ' ------------------------------------------------------------------------------ ' Program Code ' ------------------------------------------------------------------------------ Main: ' ' intialize motors by stepping x steps in both directions ' FOR x = 1 TO 200 ' 1 rev forward GOSUB Step_FwdA NEXT PAUSE 200 FOR x = 1 TO 200 ' 1 rev back GOSUB Step_RevA NEXT PAUSE 200 FOR x = 1 TO 200 ' 1 rev forward GOSUB Step_FwdB NEXT PAUSE 200 FOR x = 1 TO 200 ' 1 rev back GOSUB Step_RevB NEXT PAUSE 200 Step_Demo: Again: PULSIN PulseA, 1, rcA ' Debug "Pulse A", DEC ? rcA,cr ' Debug "Pules B", DEC ? rcB,cr If rcA = 0 THEN Again ' Wait for a pulse If rcA > 20 THEN Step_A GOTO Step_B Step_A: if rcA > 30 then Step_CCWA Step_CWA: GOSUB Step_FwdA ' do a step GOTO Step_Demo Step_CCWA: GOSUB Step_RevA GOTO Step_Demo Step_B: if rcA > 10 then Step_CCWB Step_CWB: GOSUB Step_FwdB ' do a step GOTO Step_Demo Step_CCWB: GOSUB Step_RevB GOTO Step_Demo ' ------------------------------------------------------------------------------ ' Subroutines ' ------------------------------------------------------------------------------ Step_FwdA: sAddrA = sAddrA + 1 // 4 ' point to next step READ (Step1A + sAddrA), CoilsA ' output step data ' PAUSE speed ' pause between steps RETURN Step_RevA: sAddrA = sAddrA + 3 // 4 ' point to previous step READ (Step1A + sAddrA), CoilsA ' PAUSE speed RETURN Step_FwdB: sAddrB = sAddrB + 1 // 4 ' point to next step READ (Step1B + sAddrB), CoilsB ' output step data ' PAUSE speed ' pause between steps RETURN Step_RevB: sAddrB = sAddrB + 3 // 4 ' point to previous step READ (Step1B + sAddrB), CoilsB ' PAUSE speed RETURN