Shop OBEX P1 Docs P2 Docs Learn Events
question about stepper code ... please help! — Parallax Forums

question about stepper code ... please help!

daidalos62daidalos62 Posts: 21
edited 2007-03-16 21:34 in BASIC Stamp
hello all,

ok heres my question:

This code (below and attached) pushes a stepper perfectly but ONLY with pins 12 - 15 and 0 - 3. It will not work if the motor is connected to pins 4-7 or 8-11. This is a problem, because I'd like to run 3 motors from one stamp. BTW I'm running the Basic Stamp 2 IC module (the green one).

something is off within the code and I cant find it!


heres a quick reference and attached is the bs2 file.


x VAR WORD
stepper VAR NIB
steps VAR BYTE

DIRS.lowBYTE = %11111111
DIRS.highbyte = %11111111

'
o
main:

GOSUB clock
PAUSE 100
GOSUB counter
PAUSE 100
GOTO main

'
o
clock:

RANDOM steps
DEBUG DEC steps * 2, "to", CR
FOR x = 0 TO steps * 2
LOOKUP x//4, [noparse][[/noparse]%1000,%0100,%0010,%0001], stepper
OUTS.lowbyte.LOWNIB = stepper
PAUSE 2
NEXT
RETURN

'
o
counter:

RANDOM steps
DEBUG DEC steps * 2, "fro", CR
FOR x = 0 TO steps * 2
LOOKUP x//4, [noparse][[/noparse]%0001,%0010,%0100,%1000], stepper
OUTS.lowBYTE.LOWNIB = stepper
PAUSE 2
NEXT

RETURN



thanks guys!

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2007-03-14 12:10
    Your logic seems sound.

    In trying to work with pins 4-7 or 8-11, I assume you're adjusting the OUTS statement to reflect the actual pins you want to use.

    Have you tried using the nibble specifiers OUTA, OUTB, OUTC, OUTD with the same results?

    It is possible that its a bum chip, but the chances of those two nibbles being bad on one chip are pretty small.

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • daidalos62daidalos62 Posts: 21
    edited 2007-03-14 14:20
    thanks for the reply ...

    I havent tried those yet, In fact I've never used the OUTA etc so I'll look at the manual and see what I can figure out.

    And yes you were correct in your assumption - I would just enter highbyte in place of lowbyte in the case of the outs to switch from 0-3 to 12-15. I also tried HighNib but that didn't quite work. Must keep digging!!

    anyone else ever run multiple steppers, 3 or 4, from one stamp?
  • daidalos62daidalos62 Posts: 21
    edited 2007-03-15 14:31
    no one??
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-15 19:59
    I have seen 4 Stepper Motors run from one BASIC Stamp in a commercial application. They were connected via 2 ULN2803 chips and the BS2 received its commands from a host PC via the programming port. This was for a window display in a store. What is it you needed to know about it? I built the interface for that system.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • daidalos62daidalos62 Posts: 21
    edited 2007-03-16 03:46
    I will also be using a number of ULN2803's.

    My problem is with the code.... I cant figure out how to use pins 4-7 and 8-11. Theres more of a description above, and my current code is supplied via attachment. Basically, I was just changing the outs to read either the highbyte or lowbyte, but this only utilizes pins 0-3 and 12-15. The motor will not run if connected to any of the others.

    So I was really just asking if anyone knew of an easier way to write the code to utilize the pins in sets of 4 to run the steppers.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-16 14:48
    Regarding your code…You can adjust DIRS in one line instead of the way you have it. Actually the more syntactically correct way to do what you’re doing would be:

    DIRL = %11111111
    DIRH = %11111111

    Also, you’re using the same line for both Stepper Motor outputs:

    OUTS.LOWBYTE.LOWNIB

    What you need is a lin like:

    OUTA = stepper

    Or for controlling multiple Stepper Motors at the same time you would build your word variable from 4 binary nibble step patterns and simply do a:

    OUTS = stepper

    In the above case stepper is a WORD variable. For individual control using the same WORD variable you could use:

    OUTA = stepper.NIB0
    OUTB = stepper.NIB1
    OUTC = stepper.NIB2
    OUTD = stepper.NIB3

    Using only the above statements you wanted you could alter individual Stepper Motors without affecting others. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • daidalos62daidalos62 Posts: 21
    edited 2007-03-16 18:41
    This is great , thanks very much!
  • daidalos62daidalos62 Posts: 21
    edited 2007-03-16 21:21
    so as an update ...

    using outsA, outsB, outsC, and outsD I was able to get the desired results HOWEVER I think I may have a bum chip

    The motors run well getting data from outsA, C, and D but not B. I can feel the motor is getting something, as it makes some noise and vibrates a little but its almost as if one of the pins isnt working or something....

    grrrr
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-16 21:34
    Please verify your connections…This could be a result of mixed up phase wires…To verify swap the motor with the same wiring connections for one on another port. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.