BI Polar stepper motor programming

JimmyF89

Member
hi
i am a beginner with an Astrosyn y129-5 stepper motor and i need to program it in Picaxe 18. i was wondering if anyone was able to tell me how to code this in order for it to simply go forward and reverse. this is in order for me to complete my coursework.

any help would be grateful
 

hippy

Ex-Staff (retired)
Post that line of code and someone will probably be able to tell you what's wrong with it or what to do next. And don't forget to tell us what the error message you get is.
 

JimmyF89

Member
this is the code that i tried:

main: for b3 = 0 to 99 ‘ start a for...next loop
gosub lstep ‘ call left step sub-procedure
next b3 ‘ next loop
for b3 = 0 to 99 ‘ start a for...next loop
gosub rstep ‘ call left step sub-procedure
next b3 ‘ next loop
lstep: let b1 = b1 + 1 ‘ add 1 to variable b1
goto step ‘ goto the lookup tablethis is the line with the area all it says is error in this line
rstep: let b1 = b1 - 1 ‘ subtract 1 from variable b1
step: let b1 = b1 & 2 ‘ mask lower two bits of b1
lookup b1,(%1010,%1001,%0101,%0110),b2 ‘ lookup code into b2
let pins = b2 ‘ output b2 onto control lines
return

this is the code that is in the manual and i know there are problems with this however i am unsure what i need to do to correct this
 

Dippy

Moderator
I haven't checked the code but 'step' is a reserved keyword as it says in the manual.
Change it to soemthing else e.g. MyStep.
 

lbenson

Senior Member
"Step" has become a reserved word since this example was put in. Change the two instances to something like "step1" and the program will compile.

Beat out by 1 minute!
 

JimmyF89

Member
ok then i shall try that out

cheers

if there are any other hints they would be welcome
thanks
 
Last edited:

BCJKiwi

Senior Member
Just popped the Manual 3 code into the PE.

Have colours set on in the PE.

This shows immediately the problem in that the label step: shows up in blue not black.

Step is a reserved word (used in the for next construct) so cannot be used for a label.

If you change the two references to step to say mstep, then you should have more joy.

OK I'm way too slow with the reply!
 
Last edited:

jodicalhon

New Member
step: let b1 = b1 & 2 ‘ mask lower two bits of b1

To mask the lower two bits of b1 you must AND b1 and decimal 3, not 2. So...

step: let b1 = b1 & 3 'mask lower two bits of b1

(I s'pose that should be 'mystep'...)
 
Last edited:

JimmyF89

Member
hi again,
i tried the code and it worked fine, however all i got from the motor was a vibration. i was wondering if anyone could tell me why this is.
i would also like to check the wiring because it is a circuit that i have borrowed and i am not sure whether it has been wired correctly. this is because i have a black and white wire going to v, yellow is to 4, brown to 3, orange to 2 and red to 1, if so is anyone able to tell me which goes where and the polarity that it should be going in

any help would be grateful
thanks
 
Last edited:

JimmyF89

Member
i had another look on past threads and found one example in answer to this which was
black V+12
White V+12
yellow output7
red output6
brown output5
orange output4
so i was wondering is this what i should use to wire the motor and also which do i put it in the '+' or '-' side?
 

Technical

Technical Support
Staff member
This is correct. There is no negative connection to the motor as this is handled by the darlington driver chip ... you are using a darlington driver aren't you, if not the PICAXE will go bang!

this motor will also work, with reduced torque, with 5V on the black and white wires.

' Stepper Y129-5
' If you use the wires in the 6 pin connector
' order the following program will cause rotation

' Black +12V
' White + 12V
' Yellow output7
' Red output6
' Brown output5
' Orange output4

main: let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
goto main
 
Last edited:

JimmyF89

Member
thanks.
erm... if im honest i have no idea if i am or not, i have just inherited it from someone else as it is and it appears it was originally wired incorrectly, which means i need to re wire it and also how will i know if i am using one? silly question i know but i would rather be safe than sorry
 

JimmyF89

Member
just one more question
with that bit of code, do i simply replace it with the code i am already using or place it in with that somewhere?

thanks
 

Logic Rules

New Member
HI,
There is a fix for the code in the maual in the forum but I don't remember where it is at the moment but you must change the line:
step1: let b1 = b1 & 2 ‘ mask lower two bits of b1
to read
step1: let b1 = b1 & 3 ‘ mask lower two bits of b1
The mask in the manual is wrong; in order to mask the count properly you must account for all bits.
Look in the Commands Manual at advanced reserved words so you don't use one of those for a variable.
 

JimmyF89

Member
i have managed to get the motor working by using the code posted by technical. however i would like to know how it would be possible to get the motor working in two directions if possible please.

thanks
 

eclectic

Moderator
Jimmy.
Look at the "main:" section of Tech's program.

There are four

let pins = statements.

Do a bit of copy and paste and REVERSE the sequence.

e.
 

Logic Rules

New Member
I posted a article a cuppla days ago involving speed, forward, and reverse. you might want to check that out. search for logicrules; that might help.
 

JimmyF89

Member
hi again
ive had a look at the program that was suggested but im still lost to what i need to do. simply i need to program the motor to turn a certain amount of times to go forward and then reverse the same amount of times but i am unsure how exactly to do this with the code that i have. any help would be great.

thanks
 

JimmyF89

Member
i have programmed the chip using the code logic rules suggested however i am unsure about the issue with the speed, and whether this is necessary, also another question is if i run this program i wanted to check that it will not cause any problems with the chip or motor, unless anyone can help me with the code above i would be grateful
 

JimmyF89

Member
this is the main code that i am using:
main: let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
goto main

i understand the idea of reversing the code in the way its written to get the motor to turn the opposite way but i am unsure how to set the number of turns that it should make and then stop to go the opposite way
 

eclectic

Moderator
Okay then.

Here is one way to make it turn say 100 steps clockwise.

start:
for b0 = 1 to 100
gosub clockwise
next

stop

clockwise:
let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
Return

Then try to ADD to the program to make it turn 100 steps the other way.

Mostly copy and paste

e.

PS and don't forget to print out ALL of the posts in this thread
to include in your folder.
 

JimmyF89

Member
this is what i have written and i just wanted to check that it will be ok:

start:
for b0 = 1 to 100
gosub clockwise
next

stop

clockwise:
let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
Return


nextstart:
for b0 = 1 to 100
gosub anticlockwise
next

stop


anticlockwise:
let pins = %10100000
pause 10
let pins = %00110000
pause 10
let pins = %01010000
pause 10
let pins = %11000000
pause 10
Return
 

eclectic

Moderator
You're very close, but...

Print out the program and use a pencil to follow it through.

It will only do a hundred turns clockwise then it will stop.

You need to do a bit of editing.

e.

Added. Use the Simulator to help.
 

JimmyF89

Member
hi again ive altered the code i wrote just before however i have been able to simulate it and i think it works but i would like someone to check it for me if possible, all i have done is removed the first stop in the code so it looks like this:
start:
for b0 = 1 to 100
gosub clockwise
next

clockwise:
let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
Return


nextstart:
for b0 = 1 to 100
gosub anticlockwise
next

stop

anticlockwise:
let pins = %10100000
pause 10
let pins = %00110000
pause 10
let pins = %01010000
pause 10
let pins = %11000000
pause 10
Return
 

eclectic

Moderator
Closer still!
But, it still won't simulate.

Move the

clockwise procedure

so that it's
AFTER the STOP.

And then watch the simulation.

e
 

JimmyF89

Member
when u say that i move the clockwise procedure to after the stop does that mean it is meant to be like this?

for b0 = 1 to 100
gosub clockwise
next

nextstart:
for b0 = 1 to 100
gosub anticlockwise
next

stop

clockwise:
let pins = %11000000
pause 10
let pins = %01010000
pause 10
let pins = %00110000
pause 10
let pins = %10100000
pause 10
Return

anticlockwise:
let pins = %10100000
pause 10
let pins = %00110000
pause 10
let pins = %01010000
pause 10
let pins = %11000000
pause 10
Return

or is that completely the wrong way?
 

JimmyF89

Member
hi, i managed to get the code working and i tried altering the number of steps for the motor to turn but once i try to do more than 200 it just seems to keep on going in one direction. and i was just wondering if anyone would be able to explain to me why this is happening.

also i am now adding two identical leds into the circuit that are to light up when the motor is running and i was wondering if anyone could tell me how/where to add the code for this because ive looked in the manual and i am unsure.
thanks
 

eclectic

Moderator
Jimmy.

Please post the code that WORKS .

And then, say which lines cause the "problem"
And EXACTLY what you typed that made the problem.

e.
 
Top