May 18, 2024, 12:04:23 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Stepper Motors

Started by Scott, April 07, 2007, 10:15:52 AM

Previous topic - Next topic

Scott

Hi, I would like to use the prop 1 to control a stepper motor. Do you have some code and instructions regarding these devices?

JonnyMac

You can control unipolar steppers with a Prop-1; here's a program I wrote for one of our customers -- modify it to suit.  A Google search on "stepper motors" will turn up lots of circuits using the ULN2x03 which is the output driver we have on the Prop-1, Prop-2, and Prop-SX.

' =========================================================================
'
'   File...... Focus_Pull.BS1
'   Purpose... Stepper motor focus puller for film camera lens
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 12 AUG 2006
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is designed to control a focus-pulling stepper motor for
' a camera lens.  A switch connected to input P7 controls the motor dir-
' ection, a push-button on P6 starts the motor movement.  A momentary
' press of the trigger button will start the movement.  For moves from
' one extreme to the other, the button should be held down until the motor
' has moved past the "home" position.
'
' Note that when using the Prop-1 controller a unipolar stepper motor
' must be used, with the stepper common wire connected to V+.  The motor
' will not move unless the Prop-1 power switch is in position 2.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  MtrDir          = PIN7                  ' motor direction
SYMBOL  MoveNow         = PIN6                  ' trigger input
SYMBOL  LedCCW          = PIN5                  ' moving CCW
SYMBOL  LedMoving       = PIN4                  ' moving LED
SYMBOL  Stepper         = PINS                  ' uses P0..P3


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Pressed         = 1                     ' for active high button
SYMBOL  NotPressed      = 0

SYMBOL  CW              = 0                     ' motor direction input
SYMBOL  CCW             = 1

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  StpTiming       = 15                    ' inter-step timing (ms)

SYMBOL  PosLeft         = 0                     ' focus positions
SYMBOL  PosHome         = 1
SYMBOL  PosRight        = 2

SYMBOL  CwSteps         = 20                    ' from home to CW pos
SYMBOL  CcwSteps        = 25                    ' from home to CCW pos


' -----[ Variables ]-------------------------------------------------------

SYMBOL  pos             = B2                    ' current position
SYMBOL  nSteps          = W2                    ' steps to move
SYMBOL  stpIdx          = B6                    ' step pointer
SYMBOL  coils           = B7                    ' coil control bits


' -----[ Initialization ]--------------------------------------------------

Reset:
  READ 0, PINS                                  ' apply first set to coils
  DIRS = %00111111                              ' make P0..P5 outputs
  pos = PosHome


' -----[ Program Code ]----------------------------------------------------

Main:
  LedCCW = MtrDir                               ' indicate CW / CCW
  LedMoving = IsOff                             ' not moving now
  IF MoveNow = NotPressed THEN Main             ' wait for move button

Check_Direction_Switch:
  IF MtrDir = CCW THEN Spin_CCW                 ' check spin directin sw


Spin_CW:
  IF pos = PosRight THEN Main                   ' check stop
  pos = pos + 1                                 ' update position pointer
  LOOKUP pos, (0, CcwSteps, CwSteps), nSteps    ' get steps to new position

Move_Now_CW:                                    ' move the motor
  IF nSteps = 0 THEN Main                       ' if done, back to top
    LedMoving = IsOn                            ' light motor moving LED
    GOSUB Step_Fwd                              ' move one step
    nSteps = nSteps - 1                         ' update step counter
    GOTO Move_Now_CW


Spin_CCW:
  IF pos = PosLeft THEN Main
  pos = pos - 1
  LOOKUP pos, (CcwSteps, CwSteps, 0), nSteps

Move_Now_CCW:
  IF nSteps = 0 THEN Main
    LedMoving = IsOn
    GOSUB Step_Rev
    nSteps = nSteps - 1
    GOTO Move_Now_CCW


' -----[ Subroutines ]-----------------------------------------------------

' Turn stepper clockwise one full step

Step_Fwd:
  stpIdx = stpIdx + 1 // 4                      ' point to next step
  GOTO Do_Step

' -------------------------------------------------------------------------

' Turn stepper counter-clockwise one full step

Step_Rev:
  stpIdx = stpIdx + 3 // 4                      ' point to previous step
  GOTO Do_Step

' -------------------------------------------------------------------------

' Read new step data and output to pins while preserving
' the state of other I/Os

Do_Step:
  READ stpIdx, coils                            ' read new coil bits
  PINS = PINS & %11110000 | coils               ' update stepper pins
  PAUSE StpTiming                               ' pause between steps
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Full_Steps:
  EEPROM 0, (%0011, %0110, %1100, %1001)
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

I have been wondering if this was possible with the Prop-1 also.    I did the google on stepper motors and was overwelmed by the info.   I am not THAT much of geek to understand it all.

What voltage range would the stepper motor need to be in order to work with the Prop-1?   I have a couple of stepper motors out of a Epson Inkjet Printer that I was wondering if I could use. 

I was wondering if a stepper motor would be the way to drive the turning of a buckyskull since it has more torque than a servo and you can control how much it turns and which direction. You could even belt drive it?




JonnyMac

You can control 12- or 24-volt steppers from the Prop-1, so long as they're UNIPOLAR (bipolar motors use a different driver chip).  The nice thing about steppers is that while the do use up more I/O (four lines to control one motor), they don't have to be refreshed except when they're running, in fact, the motor will not "coast" until all the outputs have been set to the same level.

Honestly, it's best to start with a known motor until you learn how these things work.  Taking motors ripped out of an old printer will likely lead to more frustration than anything.  You can get cheap steppers from All Electronics or even one from Parallax.
Jon McPhalen
EFX-TEK Hollywood Office