stepper motor
just me
Posts: 7
hi I'm trYing to run 3 stepper motor with a basic stamp home work board and darlintons I'm only able to run one please any body help me with the code and conection
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
File...... Stepper_27964.BS2
' Purpose... Simple Stepper Motor Demo
' Author.... Parallax, Inc. (Copyright (c) 2004, All Rights Reserved)
' E-mail.... support@parallax.com
' Started...
' Updated... 18 MAR 2004
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' Simple stepper motor (Parallax #27964) demonstration rotates motor one
' full revolution clockwise, pauses, then rotates one full revolution
' counter-clockwise. After another short pause, the process repeats.
'
' Connections:
'
' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Black)
' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Orange)
' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Brown)
' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
'
' Note: Do NOT connect stepper motor wires directly to the BASIC Stamp.
' See Parallax documentation for complete connection schematic.
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] I/O Definitions ]
Phase VAR OUTB ' phase control outputs
'
[noparse][[/noparse] Constants ]
'
[noparse][[/noparse] Variables ]
idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control
'
[noparse][[/noparse] EEPROM Data ]
Steps DATA %0011, %0110, %1100, %1001
'
[noparse][[/noparse] Initialization ]
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 15 ' set step delay
'
[noparse][[/noparse] Program Code ]
Main:
FOR idx = 1 TO 48 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 500 ' wait 1/2 second
FOR idx = 1 TO 48 ' one revolution
GOSUB Step_Rev ' rotate counter-clockwise
NEXT
PAUSE 500 ' wait 1/2 second
GOTO Main
END
'
[noparse][[/noparse] Subroutines ]
' Turn stepper clockwise one full step (7.5 degrees)
Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step
' Turn stepper counter-clockwise one full step (7.5 degrees)
Step_Rev:
stpIdx = stpIdx + 3 // 4 ' point to previous step
GOTO Do_Step
' Read new step data and output to pins
Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN
The steppers are connected to ports A, B and C.
And the Phase value ( original code ) is just copied to these ports.
It does not do anything fancy. It runs all steppers in same fashion - forward and backwards.
Of course you could run them independently·with some more changes to your code.
You·could use array of Phase instead of individual port assigments.
Have fun "coding".
PS I use BS2E and have not changed the processor selection back to·yours.
·
Whoops, I forgot to change the output direction!
Unless there is a conflict just do DIRS = $FFFF
Post Edited (vaclav_sal) : 5/17/2009 12:43:57 AM GMT
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle