Stepper motor attempt

russbow

Senior Member
Reading this post by Boriz .....

http://www.picaxeforum.co.uk/showthread.php?21219-Stepper-stuff&highlight=stepper

............ prompted me to buy the unit and try to understand stepper motors. There is also a good tutorial by Westy in one of the forum sections.

The following code, based on Boriz's has produced a working stepper unit, albeit a little inaccurate.

Code:
 #Picaxe 18m2
'Stepper motor driver test
'Boris Burke May 2012

setfreq m8

dirsb=%00001111	'set port direction

main:

for w2=0 to 512	' do it 512 times for one complete rev


for b1=0 to 3

lookup b1,(%0011,%0110,%1100,%1001),pinsb	'step the driver outputs

pause 5

next b1


'pause 1

next w2

pause 5000
goto main
From the attached data sheet, I understand that 64 steps will give me one revolution of the motor and 64 motor revs are needed for one shaft rev.

I make that 4096 steps. but from the code above I only need 512 loops of variable w2 for a complete rev

I also cannot understand the switching sequence table. It shows 8 changes per step, where I am using 4. Is this to do with mixing "drive" types?

Should my pinsb sequence be %0001, %0011, %0010, %0110 and so on.

Finally, the ULN2003 circuit I am using shows the four coils commoned and taken to +ve. The stepper motor data sheet shows no such connection.
 

Attachments

bluejets

Senior Member
Looks to me like b loops around 4 times and w loops 512 times so 2048 steps..??
Seems code is "shifting left" for the sequence.

Connection to darlington driver seems about right but your stepper motor is only 4 wire. (Different type)
You will need a 5 or 6 wire type for the circuit you show.
Maybe a diagram of what you want to do.?

I think you need to do a bit more reading up on stepper motors also.
 
Last edited:

SAborn

Senior Member
Is your motor a Unipolar OR a Bipolar motor, as only a Unipolar motor can be used with a common connection or a 8 wire motor wired as a unipolar.
It all you have is 4 wires from the motor then its a Bipolar motor, which will need a H-bridge or motor driver chip to drive it correctly.
 

cactusface

Senior Member
Hi Russ,
Your motor looks like a unipolar to me, it just has both common leads connected together? So you have 5 leads, is that right? I have just started a new thread, as I have two new steppers too.Unipolar are usually 4 wire and require the polarity to be switched to activate the motor.

I have a PDF of motor wiring, if I fine it, it will be attached below. Lets hear how you get on.

Regards
Mel.
 

Attachments

russbow

Senior Member
Thank you all for your responses. Things are becoming a little clearer.

I think you need to do a bit more reading up on stepper motors also.
Oh yes, and this forum is great for helping understanding.

It all you have is 4 wires from the motor then its a Bipolar motor
4 coil wires and a +ve lead, so BiPolar ?

stepper001.jpg

@Mel, thanks connections sorted.

Now the questions. Would running through this part of the code ...
Code:
for b1=0 to 3

lookup b1,(%0011,%0110,%1100,%1001),pinsb	'step the driver outputs

pause 5

next b1
..... give me one step of the motor, or one revolution?

What is the effect of replacing the lookup line with this...
Code:
lookup b1,(%0001,%0011,%0010,%0110,%0100,%1100,%1000,%1001),pinsb
It seems to work just the same, but I think it follows the datasheet requirement.

And lastly ( for this post anyway ) how to I reverse the motor.

Thanks, R.
 

westaust55

Moderator
Your second version of the LOOKUP command has 8 steps so you in effect have steps half-way between those when using the 4 value methods.

To change the direction just decrement (-1) the pointer into the LOOKUP.
 

SAborn

Senior Member
4 coil wires and a +ve lead, so BiPolar ?
Actually you have a Unipolar motor, and for your motor, the Red wire goes to V+, and you switch the other 4 wires in sequence to ground, to step the motor.
 

cactusface

Senior Member
Hi Russ,
Perhaps not the bast way but in the past I've found this code works fine, to reverse the motor just feed it the data in reverse order (start at the bottom), If you take a look on the web! I'm sure you will find a lookup table for the data output, even to do half steps, which will in effect double the steps available. Just got a really nice pair of stepper motors on eBay, 200 steps per rev, hope to do good with them, with some better coding.

Regards
Mel.


Code:
; *******************************
;    Filename: 	Stepper CH-1		
;    Date: 		03/05/2012		
;    File Version:V1	
;    Written by: 	MS	
;    Function:	To drive Srepper motors	
;    Last Revision:
;    Target PICAXE: Any.	
; ******************************* 

;This small Chinese motor has a built-in
;gearbox that needs 2048 pluses to give
;one complete rev.


Symbol delay = B0	'first gen-purpose register 
delay = 2		'XX milisecs delay 


start:

for w1 = 1 to 512

high b.0		'set bit 0 of port B high. Strange but this drives it CCW or anti clockwise!! 
pause delay 	'wait XX millisecs
low b.0		'set same bit low
high b.1		'set next bit high, etc
pause delay 
low b.1
high b.2
pause delay 
low b.2
high b.3
pause delay 
low b.3
next w1
 
Last edited:

cactusface

Senior Member
Russ,
Yes these are the same as mine!! did they come complete with a small PCB with the ULN2003 on? (I suppose not otherwise you would'ent have had the wiring problem) Here's some more code but note this time it makes the motor run in reverse, I got mine direct from China (via eBay) very cheap.

Glad you got the wiring sorted.
Regards
Mel.

Code:
; *******************************
;    Filename: 	Stepper CH-3		
;    Date: 		03/05/2012		
;    File Version:V1	
;    Written by: 	MS	
;    Function:	To drive Stepper motors	
;    Last Revision:
;    Target PICAXE: Any.	
; ******************************* 

;This small Chinese motor has a built-in
;gearbox that needs 2048 pluses to give
;one complete rev.

dirsC=%00001111

Symbol delay = B0	'first gen-purpose register 
delay = 2		'XX milisecs delay 


start:

for w1 = 1 to 512

pinsc=%00000101		'Strange but this drives it CCW or anti clockwise!! 
pause delay 		         'wait XX millisecs
pinsc=%00001001		 ' NOTE this energises two (oppisite) coils at a time, should give better stepping and static hold.
pause delay 
pinsc=%00001010
pause delay 
pinsc=%00000110
pause delay 
next w1
 

russbow

Senior Member
Thank you all. With a bit of googling and this addition to my grimoir

http://www.picaxeforum.co.uk/showthread.php?14205-Stepper-Motors-a-basic-tutorial&highlight=stepper

I now feel confident about the basics of stepper motors.

@Mel, thanks for the code, there are many ways to skin a cat it seems. These cheapo units are what you get!! Impossible to get a proper 360 degree run. Changing the W value in my code to 509 gave an overun of about 0.3% and a value of 308 an underrun of the same.

Seems they are manufactured to operate louvre fans, so I suppose Open and Shut are the parameters :)

Out of interest I came across this from another forum - accuracy was being disussed.

The formula I use is this, if there are any errors tell me, for maybe you're right.
Specification: Step Angle Torque: 5,625 ° / 64
Reduction ratio: 1/64
5VCC

calculations:
5.625 ° / 64 = 0.0878 ° step angle
360 ° / 0.0878 = 4100.22 Total steps -full turn of 360 ° (not a whole number) must counteract these error 0.22 ° and it is impossible.

proof:
360 ° / 4100.22 = 0.0878 step angle
4100/64 = 64 Reduction ratio
64 * 0.0878 = 5.62 °

These calculations are correct ...

THX.
Make what you will. Thanks to all. Now to hack a printer. ;)
 
Last edited:

russbow

Senior Member
I have just ripped apart on old Brother Fax machine.

The motor has a 16 tooth gear wheel and the shaft give 24 "nudges" per rev when turned by hand. Would this indicate a 15 deg step - ( 360/24 ) ?

It has 6 wires with the following resistive measurements.

Pin 1 - - 16 ohms -- pin 2 -- 16 ohms -- pin 3

Pin 4 - - 16 ohms -- pin 5 -- 16 ohms -- pin 6


No other continuity is shown.

Do I consider it as 4 coils with pins 2 and 5 taken to +ve, or is that a simplistic view.

What drive considerations must I be aware of.

Thanks. R.
 

cactusface

Senior Member
Hi Russ,
I think eclectic, as found a very useful artical there! it seems to cover most of the main points. Yes I'd say that pins 2 & 5 are the common connections, and 360/24 is 15Deg. Just watch as V/R=I and V*I=W. My new motors are very nice and cheap considrering
http://www.ebay.co.uk/itm/110923913114?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2648

I too have a box of old printer type motors, but there a mix of voltages and steps and a real mix of wiring colours, nothing to any standard....
Regards
Mel.
 

russbow

Senior Member
Another nice link EC, thank you. Found the bit about "trial and error" sorting of the pulse wires useful.
 

russbow

Senior Member
Some further help please

Confirmation that the winding are :-

Pin 1 - - 16 ohms -- pin 2 -- 16 ohms -- pin 3

Pin 4 - - 16 ohms -- pin 5 -- 16 ohms -- pin 6

.............. so two centre tapped coils.

I can get the motor to run but a bit jerky. Seems like two steps forward, one back. If take the unit off the breadboard, connect pin 2 to +5v and alternate pins 1 and 3 to earth, the shaft turns clockwise.

If I take pin 5 to +ve and alternate pins 4 and 6, the shaft steps anti clockwise. This happens even if I reverse polarity.

Am I missing something significant, or is it maybe a motor for a special function. It is out of a Brother fax.
 

SAborn

Senior Member
What you are missing is that your code sequence is wrong to which coil is activated in sequence.

label your wires and write down the sequence of what wire steps the forward 1 step, then repeat the sequence in the code, if you have the sequence of what coil is energized following the previous coil wrong, then it will backstep and do all sorts of wierd actions.
 

cactusface

Senior Member
Hi Russ,
How are you driving the motors? the wave method that is activating each coil in turn, or 2 opposite coils at the same time this gives the motor more torque and power (Or even better holding/breaking). Strange that one set of coils work as expected and the other does'ent?? Would'ent think it was a special. Try tying pin 5 to V+ and then take pin 6 low then pin 4, does that move the opposite to pin 4 then pin 6??
You may have a bit more head scratching yet?

@SAborn seems like a plan? I tend to agree there's a wire crossed somewhere.

Regards
Mel.
 

russbow

Senior Member
I do not have a problem with the code.

My observation on this particular motor are:-

If take the unit off the breadboard, connect pin 2 to +5v and alternate pins 1 and 3 to earth, the shaft turns clockwise.

If I take pin 5 to +ve and alternate pins 4 and 6, the shaft steps anti clockwise. This happens even if I reverse polarity.
I cannot see how if winding two gives me reverse direction to winding one, no matter what the polarity, how windings one and two will give a continuous rotation.
 

SAborn

Senior Member
You do have pin 2 AND 5 of the motor BOTH connected to V+ dont you??? and then sequence pin 1,3,4,6 of the motor to ground in the correct order.

The reason its back stepping is because of the location of the N/S magnets inside, and as i keep saying you need to get the sequence right for it to rotate due to the N/S fields generated by the coils.
 

eclectic

Moderator
@Russ,
Just for background:

1. Is there a badgeplate or any code markings on the motor?

2. Can you provide the code and the circuit?

e
 

russbow

Senior Member
The circuit is as per post #2
The code is:-

Code:
#Picaxe 18m2
'Stepper motor driver test

setfreq m8

dirsb=%00001111	'set port direction


main:

for w2=0 to 509	' do it 512 times for one complete rev


for b1=0 to 8

pinsb	=b1'step the driver outputs

pause 50

next b1

next w2

pause 5000

goto main
The ULN inputs are connected to the 18m2 pins b0 to b3 via 1k resistors.

The code and circuit work with another motor.

With this particular motor, even with following this sequence
So, we have to do it by trial-and-error.
Connect the stepper motor in any arrangement to the project but make sure the common goes to the positive rail, as we have already identified this wire.
Turn on the project and see if the stepper motor rotates.
If not, do not touch the first wire. Simply swap the last two wires.
If this does not work, swap the 2nd and fourth wires.
Then the second and third wires.
The motor will not be damaged during this process as it does not take any more current when oscillating back and forth or when rotating.
keep swapping the last three wires until the motor rotates.
smooth rotation does not happen

Significantly, if I disconnect one coil completely, perfect rotation is CW. reconnect and dis other coil, perfect rotation CCW.

The motor is badged "Brother BP484223 LM 4290513". The BP number gets some hits on Google
 

cactusface

Senior Member
Take a good look at the motor?

Hi Russ,
Just been playing around with one of my old steppers, proberly from an old printer. I had the same problem as you? in that I could get one phase to work both way but not the other, also the usual wire color did'ent work either. The 2 phases are usually staggered and one on top of the other, and this can show in the way the wires enter the motor! So in the end I just when with that and Ha-presto it worked, it might be worth a try.

The motor in the following pictures is a 5 wire motor, I took it that white was comm to V+ but red-yellow & blue(no orange)-brown did'ent work the motor just jittered!! but looking at the wires going in to the motor, suggested red+brown & yellow+blue and it was right. I have some motors all wied in pastal colours and it hard to tell the pinks from the oranges, etc.

Hope this might help you. or others.
Regards
Mel.
 

Attachments

cactusface

Senior Member
Supper Buggy?

Hi,
Talking of stepper motors, here's a pic of the very nice ones I got from ebay, too good for a buggy really, but in this simple mockup they carried their own weight plus a small box of drill bits and an hammer.. and PCB's etc.
Regards
Mel.
 

Attachments

SAborn

Senior Member
Russ, I am starting to wonder if you have the coil wiring correct, working from your wire sequence system can you confirm the resistance.
It has 6 wires with the following resistive measurements.

Pin 1 - - 16 ohms -- pin 2 -- 16 ohms -- pin 3

Pin 4 - - 16 ohms -- pin 5 -- 16 ohms -- pin 6

No other continuity is shown.

Do I consider it as 4 coils with pins 2 and 5 taken to +ve, or is that a simplistic view.
Pin 1 and pin 3 should read double the resistance (32 ohm) as pin 1 and pin 2 (16 ohm) or pin2 and pin 3.(16 ohm)
The same applies for pin 4 and pin 6 should read double the resistance (32 ohm) as pin 4 and pin 5 (16 ohm) or pin 5 and pin 6 (16 ohm)

Can you confirm this.

Then your drive sequence should be something like ... pin 1, pin 4, pin 2, pin 6, .....note the coils normally alternate from one to the other and not pin 1 then pin 2........ the actual pin sequence might be pin 1 then pin 6, pin 2 , pin 4, ....only some trial and error will establish the correct sequence.
 
Last edited:

SAborn

Senior Member
Actually my comment above is not 100% correct, i draw a little schematic to show each coil set has a North and South winding to show how the sequence will work, then realized each coil can not alternate fully.

Please look at the drawing, each sequence needs to go N,S,N,S or S,N,S,N depending on the direction of rotation.
I may have the N and S for each coil backwards, but this wont matter as its just to show how each coil has a N and S winding.

In the example the sequence would be Pin 1, pin 4, pin 6, pin 3 (N,S,N,S) and to reverse it would be 3,6,4,1 (S,N,S,N)


Stepper coils.JPG
 

TAMeyer

Member
This link will prove helpful in identifying the leads if you have a scope.
http://www.piclist.com/techref/io/stepper/wiresscope.htm

Using Womai's DPScope, I was able to identify the pairing on 5 different steppers.
Full disclosure: My findings have not been tested in circuit.

The attached refers to a"PM55L-048-HP69", from an HP inkjet.
These two images show the signaling slightly out of phase.


Stepper_Scope_A2_B1.jpgStepper_Scope_A1_B1.jpg


See next post for 3rd image.
 

russbow

Senior Member
Success

:D Thank you all very much.

@SAborn - your little diagram and explanation was the key to final understanding

@Mel - In this case your "connect in the order" idea worked

@ everyone else - All your help is appreciated.

Major learning point - If you don't know much about it, assume you know nothing. Applying misconceptions really muddies the water.

Now what to do with the motor ? :D
 

cactusface

Senior Member
Russ,
I've always had this idea! one motor turns a turntable, the other moves a pen that draws on the paper on the turntable, a sort of PicAxe spirograph!! Ha, Ha...
Regards to all.
Mel.
 
Top