View Full Version : Controlling a Stepper Motor with a BS2

04-28-2006, 08:30 PM
Dear Guru's,
I am trying to control a Shinano·2 phase bipolar 2 phase exciting stepper motor (this is the description of the motor from the spec sheet) part no. SST36C0030.· See the attached spec sheet for this motor.
I finally gave up on trying to adapt an example piece of code from the Parallax website·to my application and wrote my own piece of code.· I pretty much understood the code from the Parallax website and I am not sure why·I couldn't·get it to·work.· I finally got the motor to turn with my own code, as "basic" is it may be!

I now have a few problems for which·somebody may have some suggestions:
1.··· The motor speed is extremely slow, approximately 50 to 60 rpm.· With a rating of 2250 pulses per second·MAX, I should be able to achieve 337.5rpm MAX.· I have varied the delay from 0 to 500 milliseconds and it only really works with delays around the 2 to 4 milliseconds.
2.··· The motor rpm’s are VERY inconsistent as it speeds up and slows down, very jumpy.
3.··· The torque is EXTREMELY low.· I have no way to measure the torque, however a very light pinch with my fingers is enough to stop the motor from turning (motor is rated for 35.2mN m for holding torque and 3.92 mN m detent torque. ·I am not sure which one of these numbers is supposed to represent the active driving torque of the motor.
4.··· I have tried driving this motor through a Darlington Transistor Array (ULN2803A).· I have only successfully been able to drive the motor from the outputs of the Basic Stamp 2 (BS2) microcontroller, but not from the outputs of ULN2803A.
5.··· I am not sure exactly how much voltage and current I get from an ACTIVE HIGH state of one of the pins on the BS2.· I may need an amplifier.
Thanks in advance,
Neal, 954-649-9399

My source code looks something like this:

' {$STAMP BS2}
' {$PBASIC 2.5}
' Connections:
' -----------------------------------------------
' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Brown)
' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Red)
' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Orange)
' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
' -----[ I/O Definitions ]-------------------------------------------------
senseMotion·· PIN 0
closure······ PIN 1
manualAdvance PIN 2
cutoff······· PIN 3
brown········ PIN 4
red·········· PIN 5
orange······· PIN 6
yellow······· PIN 7
INPUT senseMotion
INPUT closure
INPUT manualAdvance
INPUT cutoff
OUTPUT brown
OUTPUT orange
OUTPUT yellow

' -----[ Constants ]-------------------------------------------------------
' -----[ Variables ]-------------------------------------------------------
idx·········· VAR···· Byte··················· ' loop counter
stpDelay····· VAR···· Byte··················· ' delay for speed control
_steps······· VAR···· Word··················· ' number of steps required

' -----[ Initialization ]--------------------------------------------------
· stpDelay = 2···························· ' set step delay in milliseconds
' -----[ Program Code ]----------------------------------------------------
· IF (senseMotion = 1 AND closure = 1) THEN·· ' dispense 14 inch piece of·string
··· _steps=150········································ ···' when motion is detected and
··· GOSUB DriveMotor································· ' cover is closed
··· senseMotion = 0
··· closure = 0
· ELSEIF (manualAdvance=1) THEN········ ' manually advance·string with pushbutton sw
··· DO WHILE (manualAdvance=1)
····· _steps=16
····· GOSUB DriveMotor
··· LOOP
··· manualAdvance = 0
· ELSEIF (cutoff=1) THEN··············· ' advance 1 inch after·string is cut
··· _steps=104
··· GOSUB DriveMotor
··· cutoff = 0
'··· NAP 3
'··· END
' -----[ Subroutines ]-----------------------------------------------------
· FOR idx = 1 TO _steps/4····· ' cycle through different phases
··· HIGH brown
··· HIGH red
··· LOW orange
··· LOW yellow
··· PAUSE stpDelay

··· LOW brown
··· HIGH red
··· HIGH orange
··· LOW yellow
··· PAUSE stpDelay

··· LOW brown
··· LOW red
··· HIGH orange
··· HIGH yellow
··· PAUSE stpDelay

··· HIGH brown
··· LOW red
··· LOW orange
··· HIGH yellow
··· PAUSE stpDelay

04-28-2006, 08:53 PM
A few things I see and then I better get to work so off the top of my head check these things.

I dont see _Steps default value

Do you have a load on the motor while testing it if not it will cavitate

Are you running at least 2x the voltage rating, if not you cant get the rated speed

BS2 can only execute 2000 lines of code per second so your max step rate is 2000 per second / 5 lines of code per step

Usually the amount of current is the problem for faster speeds, that is why you push it with higher voltage as the winding takes time to get up to full power.
Using a big capacitor on the power supply can help as well.

Think outside the BOX!

04-29-2006, 01:59 AM
I always say this in these kinds of posts, and just as metron9 pointed out, the basic stamps can only execute ~2000 lines of code per second. So if it’s a critical project just get a stepper motor controller/driver that you can command by serial. it simplifys your code and makes life so nice. so·even when the stepper is off doing its thing, the basic stamp can go on to handle other things like environmental monitoring and damage control. and the controller gives you a braud range of setting like voltage, torque, acceleration/deceleration profiles, step counting, holding current, current limiting (so you cant break stuff if it hits something), multipule stepper motors using 1 set of I/O and so much more!

www.simplestep.com <- is a great place for cheap effective motor drivers

related post:

Chris Savage
04-29-2006, 02:14 AM
The BASIC Stamp can directly control the Stepper Motor without problem.· You first need to appropriate driver chip for the type of Stepper Motor you are using.· In speaking with the poster it seems that is the hang-up right now so we'll wait to see if he gets that taken care of.

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Ryan Clarke
04-29-2006, 02:58 AM
I have also driven two steppers with a DC-16 and a BS2 at the same time, no problem.


Ryan Clarke
Parallax Tech Support

RClarke@Parallax.com (mailto:RClarke@Parallax.com)