BI Polar stepper motor programming

JimmyF89

Member
this is the code that i am using:
start:
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

but instead of for b0 = 1 to 100 i am trying to increase the turns so i changed it to 300 and 400 to try it so it reads for b0 = 1 to 300 or for b0 = 1 to 400 howver it just seems to carry on in one direction
 

eclectic

Moderator
Got it!

I was initially confused when you said 200.

b0 is not allowed to go over 255.

Change ALL b0 to W0

and watch the difference in the simulator.

And then, look up

BYTE WORD in manuals 1 and 2

e.
 

eclectic

Moderator
And your other question.

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
This one is quite easy, IF you have printed out your new working code.

WHICH output pins can you use?
WHAT do want each LED to do?
WHEN do you want the LED to be ON or OFF. (1 or 0).

e.
 

JimmyF89

Member
ive tried looking up byte word in the 2 manuals that have been suggested however i can't seem to find anything about it in them.


ah right thanks i shall look at that as well now
 

Dippy

Moderator
If you mean a switch to simply reset the PICAXE, then it's shown in Manual 1 page 25 "PICAXE-18/18A/18X Pinout and Circuit". Look at the download circuit example.

If you want to sense a switch being pressed from code then do a similar res+switch configuration to an Input pin. Then you can sense a switch-press from within code and do whatever you want to do.
 

JimmyF89

Member
i looked at that page but all i could really understand was how it is used for the hard reset and reset switch on the board, because i looked on one of the other manuals i found on the internet and it said if i want an extrenal reset switch i just says to connect a switch in parallel between R and G so i was wondering about this, if anyone has any information they can give me on that if possible. thanks
 

manuka

Senior Member
JimmyF89: FWIW I'd a bunch of tertiary students in 2007 with intro steppers on their plate, & found the approach shown => www.picaxe.orconhosting.net.nz/stepdemo.jpg allowed near immediate "it works" satisfaction. They then moved on to self directed tweaking & produced and understood all manner of effects, with confidence & insights that fostered serious stepper work. Precious intro. stepper lab-work had been educationally excruciating in comparison!
 

Mycroft2152

Senior Member
JimmyF89: FWIW I'd a bunch of tertiary students in 2007 with intro steppers on their plate, & found the approach shown => www.picaxe.orconhosting.net.nz/stepdemo.jpg allowed near immediate "it works" satisfaction. They then moved on to self directed tweaking & produced and understood all manner of effects, with confidence & insights that fostered serious stepper work. Precious intro. stepper lab-work had been educationally excruciating in comparison!
Yup, Stan.

That's what the little flag wavers are for.
 

manuka

Senior Member
Agreed, BUT numerous stepper workouts proceed instead with "power hogs" rescued from old printers etc. I'd spent decades following this pathway myself until chasing up these Electronic Goldmine flag waving darlings => http://www.goldmine-elec-products.com/prodinfo.asp?number=G14197, specifically to cut thru' the learning fog such beasts normally require. Students LOVE THEM!

Even though I recall a minimum order,they're presently only a US$1 each, & I STRONGLY suggest others do the same- perhaps sharing out a bulk order locally to ease p&p. This way you'll master steppers fast track-& for peanuts!
 
Last edited:

eclectic

Moderator
OK.

Now a couple of things.

1. Your question in post #39. Did you see the reply in post #44?

2. Could you please explain a little further about "reset".

The RevEd board already HAS a reset switch.
Do you want another switch as well?
Or something else?
e.
 

JimmyF89

Member
1. yes i did see that thanks, i am currently looking at that along with my teacher and we are trying to work out the pins to use.

2. well the board is going to be enclosed and so when it is used i will not be able to use the reset switch on the board so i was looking into the use of an external switch to utilise this. and as i said before i found that all i could find was to connect a switch in parallel across R input and G
 

eclectic

Moderator
Jimmy.

Look at the Datasheet for the CHI030.
(It's in the Datasheets section near the top of this page).

Pages 4,5 and 7.

Very carefully, check which two connections you need.
(Ask your teacher for help.)

Then it's easy to wire a switch.

e
 

JimmyF89

Member
ok i will do, one thing neither of us can understand is that it says on the datasheet to wire in parallel and we were both wondering what exactly this means?

also another thing is will i have to code the chip to recognise the external reset switch or not?
 

JimmyF89

Member
one other question going back to the leds, i have used the output pins on both the 'V's, 7,6,5,4 for the stepper motor, so all i have left are 3,2,1,0,G and both me and my teacher are unsure about which pins the leds should be placed in, i know i have asked this before but i was wondering if anyone could give me an example?
 

eclectic

Moderator
Your first question.

Print out the CHI030 circuit diagram on page 7 of the Datasheet.
Left hand side, you'll see two connection points

R and the one beside it. Have a look at my terrible diagram.

The switches are in parallel.

Second question. Let's say you've got

a red LED and 500 ohm resistor connected between out 0 and V+.
a green LED and 500 ohm resistor connected between out 1 and V+.

(Yes V plus and don't forget which way the LED's must point.)
Change your code like this.

Code:
clockwise:
let pins = %11000001
pause 10
let pins = %01010001
pause 10
let pins = %00110001
pause 10
let pins = %10100001
pause 10
Return
This will make LED 0 light while the motor is turning clockwise.
Then see if you can work out LED 1.

e.
 

Attachments

JimmyF89

Member
just one quick question before i do it about the v plus, is that the power in v+? just wanted to make sure before i wire this up
 

eclectic

Moderator
Yes.

The sequence is V+ >>>> LED/resistor >>> UNL2803 chip.

Look up Darlington in the search.

And, run your NEW program through the simulator first.
If the prog is correct, you will see the result very easily.

And thank you for asking a very sensible question.
e.
 

SD2100

New Member
When the program finishes outputs 6 & 7 will be left ON also possibly the anticlockwise LED, it might pay to put something before the STOP command to turn the outputs OFF.
 

JimmyF89

Member
i have managed to now wire up the circuit and have the LEDs working however the problem is that the motor is no longer turning and is just vibrating and i was wondering if anyone could tell me what is wrong?
 

JimmyF89

Member
well we have solved that problem now but there is a new one.
basically i have got to add two switches into the circuit, one to turn the motor clockwise and the other to turn anticlockwise.
we have created a code but it doesnt seem to turn as it should and just almost the motor just vibrates back and forth without doing the full movement before and we are unsure.
this is the code that i am using:

main:
label0: if Input6 is On then label1
goto label0
label1: gosub clockwise_time
label2: if Input7 is On then label3
goto label2
label3: gosub anticlockwise_time
let pins = %00000000
goto label0

clockwise_time:
for w0 = 1 to 400
gosub clockwise
Return

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

anticlockwise_time:
let pins = %10100000
pause 10
let pins = %00110000
pause 10
let pins = %01010000
pause 10
let pins = %11000000
pause 10
return
 

eclectic

Moderator
Jimmy.

Just so that I'm clear.
Do you want....

Press input 6 to make it turn 400 steps CLOCKWISE.

Press input 7 to make it turn 400 steps ANTI -CLOCKWISE.


AND, the LED to light as well?

e.
 

JimmyF89

Member
well any input that i can use really, but yes ideally

well the LED my teacher decided would be done differently now so i dont need to worry about the program for lighting that now
 

eclectic

Moderator
Jimmy.
I've made some changes, which I've indicated with *****.

This is not "good" programming, but it works in the simulator.

Code:
main: 
if Input6 is On then gosub clockwise_time '******

if Input7 is On then gosub anticlockwise_time '*****
goto main '********

clockwise_time:
for w0 = 1 to 400
gosub clockwise
next '********
Return

anticlockwise_time: '*****
for w0 = 1 to 400
gosub anticlockwise
next '********
Return


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
Please try it, in the simulator then for real.

Then, PRINT IT.

And then, what will happen if BOTH switches are pressed?

e.
 

JimmyF89

Member
i have just tried running the code you suggested to use but i try running it and on the first line:

if Input6 is On then gosub clockwise_time

it says that there is a compile error
 

eclectic

Moderator
Hmmm? It works here.

Ask your teacher WHICH version of editor you're using.

Or, in the editor, go to

Help then About.

It Should say 5.2.0

Can you check ASAP?
 

eclectic

Moderator
Oh!

Well, for the time being, change

just the first three blocks of code to this.

Code:
main: 
if Input6 is On then clockwise_time '******

if Input7 is On then  anticlockwise_time '*****
goto main '********

clockwise_time:
for w0 = 1 to 400
gosub clockwise
next 
goto main '*******

anticlockwise_time: 
for w0 = 1 to 400
gosub anticlockwise
next 
goto main '******
DO NOT change the rest.

Then you'll need to see your teacher to get the NEW
Editor 5.2.0 downloaded on to your school system.

e

Added. Hmmm. Looks like Nesbit's in for some competition here!
 

Squidteeth

New Member
I think there is another mistake in that code section.
the mask needs to read

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

Otherwise the lookup only gets the #2 bit and not the #1 & #2 bits, does it not?
 
Top