how to write code to run bipolar stepper motor

sreutens

New Member
hi, I'm teaching myself picaxe programming and i am trying to figure out how to write a simple program to run a bipolar stepper motor.( using a Picaxe 14m2) Here is my test code :

output c.1,c.0,b.4,b.5

for b1 = 1 to 20
for b0 = 1 to 4
lookup b0, (0,$01,$02,$04,$10), b3
pins=b3
pause 100
next b0
next b1

I am having a problem with the line "pins=b3" as in the picaxe editor it tells me it has a syntax error and i can't figure out the problem. With the Picaxe 14m2 can i use the "pins" command? If not, what do i use?
Basically I want to output the lookup table to my outputs to drive the LD293D IC but I do not understand how to do that.
How do i tell the variable "b3" to go to the "output pins"?
 

BESQUEUT

Senior Member
How do i tell the variable "b3" to go to the "output pins"?
Maybe specifying wich port you are adressing ... :p
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]
[color=Blue]output c.1[/color][color=Black],[/color][color=Blue]c.0[/color][color=Black],[/color][color=Blue]b.4[/color][color=Black],[/color][color=Blue]b.5

for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]20
      [/color][color=Blue]for [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]4
            [/color][color=Blue]lookup [/color][color=Purple]b0[/color][color=Black], [/color][color=Blue]([/color][color=Navy]0[/color][color=Black],[/color][color=Navy]$01[/color][color=Black],[/color][color=Navy]$02[/color][color=Black],[/color][color=Navy]$04[/color][color=Black],[/color][color=Navy]$10[/color][color=Blue])[/color][color=Black], [/color][color=Purple]b3
            pinsb[/color][color=DarkCyan]=[/color][color=Purple]b3
            [/color][color=Blue]pause [/color][color=Navy]100
      [/color][color=Blue]next [/color][color=Purple]b0[/color]
[color=Blue]next [/color][color=Purple]b1[/color]
Bye the way, you can also specify that you are using out pins :
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]
[color=Blue]output c.1[/color][color=Black],[/color][color=Blue]c.0[/color][color=Black],[/color][color=Blue]b.4[/color][color=Black],[/color][color=Blue]b.5

for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]20
      [/color][color=Blue]for [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]4
            [/color][color=Blue]lookup [/color][color=Purple]b0[/color][color=Black], [/color][color=Blue]([/color][color=Navy]0[/color][color=Black],[/color][color=Navy]$01[/color][color=Black],[/color][color=Navy]$02[/color][color=Black],[/color][color=Navy]$04[/color][color=Black],[/color][color=Navy]$10[/color][color=Blue])[/color][color=Black], [/color][color=Purple]b3
            outpinsb[/color][color=DarkCyan]=[/color][color=Purple]b3
            [/color][color=Blue]pause [/color][color=Navy]100
      [/color][color=Blue]next [/color][color=Purple]b0[/color]
[color=Blue]next [/color][color=Purple]b1[/color]
Arghl... pins are not within the same port !
Can you arrange for having all pins within the same port ?

output c.1,c.0,b.4,b.5
only say that theses pins dirs are outputs.

There is no "virtual" output port to be mapped to any outpin, from differents ports...

Maybe something like :
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]
[color=Blue]output c.1[/color][color=Black],[/color][color=Blue]c.0[/color][color=Black],[/color][color=Blue]b.4[/color][color=Black],[/color][color=Blue]b.5

for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]20
      [/color][color=Blue]for [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]3
            [/color][color=Blue]on [/color][color=Purple]b0 [/color][color=Blue]gosub [/color][color=Black]step0, Step1, Step2, Step3
            [/color][color=Blue]pause [/color][color=Navy]100
      [/color][color=Blue]next [/color][color=Purple]b0[/color]
[color=Blue]next [/color][color=Purple]b1[/color]

[color=Black]Step0: [/color][color=Blue]low b.5[/color][color=Black]: [/color][color=Blue]high c.1 [/color][color=Black]: [/color][color=Blue]return[/color]
[color=Black]Step1: [/color][color=Blue]low c.1[/color][color=Black]: [/color][color=Blue]high c.0 [/color][color=Black]: [/color][color=Blue]return[/color]
[color=Black]Step2: [/color][color=Blue]low c.0[/color][color=Black]: [/color][color=Blue]high b.4 [/color][color=Black]: [/color][color=Blue]return[/color]
[color=Black]Step3: [/color][color=Blue]low b.4[/color][color=Black]: [/color][color=Blue]high b.5 [/color][color=Black]: [/color][color=Blue]return[/color]
 
Last edited:

sreutens

New Member
yes i could use 4 "B" ports. But ( for my own understanding) I am wondering what is the difficulty using 2 different ports? Essentially I need 4 ports to run 4 inputs of the stepper motor driver.
 

BESQUEUT

Senior Member
yes i could use 4 "B" ports. But ( for my own understanding) I am wondering what is the difficulty using 2 different ports? Essentially I need 4 ports to run 4 inputs of the stepper motor driver.
Well...
PICs and Picaxes are 8 bits processeurs. So it's easier to deal with bits on the same port as you can do that with only one command.
All pins will switch at the same time. (IE : be carefull with "unused" pins...)

If on differents ports, you have to deal successively with each pin=each bit
 

hippy

Technical Support
Staff member
With a rearrangement of variables this will possibly do what is intended. Untested and the outpin allocations may be wrong -

Code:
#Picaxe 14M2
output c.1, c.0, b.4, b.5

for b1 = 1 to 20
      for [b]b2[/b] = 1 to 4
            lookup [b]b2[/b], (0,$01,$02,$04,[b]$08[/b]),[b]b0[/b]
            outpinC.1 = bit0
            outpinC.0 = bit1
            outpinB.4 = bit2
            outpinB.5 = bit3
            pause 100
      next [b]b2[/b]
next b1
 

sreutens

New Member
yes i am beginning to understand now. Will try the modified code with my stepper motor now to see how it works and practice more in debugging.
 
Top