Shop OBEX P1 Docs P2 Docs Learn Events
Here's the program. — Parallax Forums

Here's the program.

NWUpgradesNWUpgrades Posts: 292
edited 2011-09-06 07:56 in BASIC Stamp
' {$STAMP BS2}
' {$PBASIC 2.5}
 
StepperDir      PIN     0                       ' direction control
StepperMove     PIN     1                       ' movement
 
CW              CON     0
CCW             CON     1

idx             VAR     Byte
 
Reset:
  OUTPUT StepperDir
  HIGH StepperMove                              ' move on high-to-low transition

Main:
  StepperDir = CW
  FOR idx = 1 TO 100
    PULSOUT StepperMove, 500
    PAUSE 5
  NEXT
 
  StepperDir = CCW
  FOR idx = 1 TO 100
    PULSOUT StepperMove, 500
    PAUSE 5
  NEXT
 
  GOTO Main

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-13 20:41
    Hello,

    ·· This post looks like it should be in the other thread you posted asking for Stepper Motor code.· And by the way, this code requires a Stepper Motor controller.· This code is not for direct control of a Stepper Motor as the example I posted in your other thread.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • NWUpgradesNWUpgrades Posts: 292
    edited 2006-02-14 01:33
    So, Can anyone elaborate a bit to explain how to make this code run the motor 360 degrees CW and then 360 CCW? I have the stamp2 connected to a Sterpper Controller Board. This program works for simple testing, and I a sure there is a way to make the motors turn 360, I just do not know how. Thanks for your help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 01:57
    Well for starters you would need to know how many degrees per step the stepper motor moves, otherwise there's no way to know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • NWUpgradesNWUpgrades Posts: 292
    edited 2006-02-14 03:16
    That, I do not know. Howe ever, I do know that before I lost everything last year I had modified this code and had it working. I just for the life of me can not get it to work again the way it did before. I think I may be missing somthing and am sure I will get it figured out soon. Thanks for the help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 05:18
    Well you will need to find out the degrees per step then.· As I said, without it you will be able to do nothing more than keep trying until you get it right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • NWUpgradesNWUpgrades Posts: 292
    edited 2006-02-14 07:04
    It looks like 1.8 degree per step on one of the motors I have.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-14 09:09
    NWUpgrades -

    Since 360 / 1.8 = 200, there are 200 steps in an entire circle (360 degrees) using this particlar stepper motor. Forward step (CW) the motor 200 steps and you will complete the circle in one direction. Reverse (CCW) step the motor 200 steps and you return to the original position.

    So, presently, as your program is written, it will turn 180 degrees (+ 100 steps) in a CW direction, and then turn 180 degrees (- 100 steps) in a CCW direction.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 2/14/2006 9:16:05 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 22:56
    And there you have it...· =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-01 12:43
    Is there a version for BS1?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-01 13:11
    This thread is from back in 2006 and the original poster split his thread causing this one to be without the details you would normally require to port the code to the BS1. At a glance it looks like this code doesn't drive a Stepper Motor directly, but rather controls a Stepper Motor Controller Board of some kind. One pin setting direction and the other pin pulsing the pin the advance the stepper one position. The code should work minus directives and a few syntactical changes. The following code hasn't been tested, but should be close in functionality. Let me know if it does not work.

    P0 is direction control and P1 is the step pulse.
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL          StepperDir = PIN0                       ' direction control
    SYMBOL          StepperMove = PIN1                       ' movement
    SYMBOL          CW = 0
    SYMBOL          CCW = 1
    SYMBOL          idx = B0
    Reset:
      OUTPUT StepperDir
      HIGH StepperMove                              ' move on high-to-low transition
    Main:
      StepperDir = CW
      FOR idx = 1 TO 100
        PULSOUT StepperMove, 500
        PAUSE 5
      NEXT
      StepperDir = CCW
      FOR idx = 1 TO 100
        PULSOUT StepperMove, 500
        PAUSE 5
      NEXT
      GOTO Main
    
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-01 14:24
    Thanks Chris,
    That's eaxctly what I need.
    I have a stepper driver with PLS & Dir input, so will use stamp to send the pulse.

    thanks
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-01 14:55
    I changed the value of PULSOUT StepperMove, 500 to 1000, but the speed seems to be the same, how do I increase speed?

    thanks
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-01 15:40
    In the PULSOUT command the second value represents the pulse width units. On the BS1 this value is in 10uS units, so a value of 500 equals equates to 5mS and 1000 equates to 10mS. As you can see higher values take longer and therefore slow down the loop. You actually need smaller values for PULSOUT. The original values were for the BS2 which uses 2uS units. The BS1 is 5 times the difference, so the 500 on the BS2 code should have been a 100 on the BS1, but smaller values will make it go faster.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-01 15:42
    As a note, there is also a PAUSE 5 in each loop, meaning between each pulse the loop waits 5mS. You can also lower this value or remove it entirely to make things go faster.
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-01 22:59
    I changed the value pulsout and pause to 1 it did go faster, but 1 is the lowest value it can go and the speed is still not fast enough, how do I go beyond the speed of pulsout 1?

    thanks
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-02 09:10
    You can't and still trigger the pulse. You can remove the PAUSE statement entirely, but I am afraid it seems like you're at the speed limitations of the BS1.
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-04 11:29
    You can't and still trigger the pulse. You can remove the PAUSE statement entirely, but I am afraid it seems like you're at the speed limitations of the BS1.

    Ok, thanks
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-04 13:08
    I forgot to ask:

    how do I reverse direction for the BS1 code,

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL StepperDir = PIN0 ' direction control
    SYMBOL StepperMove = PIN1 ' movement
    SYMBOL CW = 0
    SYMBOL CCW = 1
    SYMBOL idx = B0
    Reset:
    OUTPUT StepperDir
    HIGH StepperMove ' move on high-to-low transition
    Main:
    StepperDir = CW
    FOR idx = 1 TO 100
    PULSOUT StepperMove, 500
    PAUSE 5
    NEXT
    StepperDir = CCW
    FOR idx = 1 TO 100
    PULSOUT StepperMove, 500
    PAUSE 5
    NEXT
    GOTO Main
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2011-09-05 08:52
    You can't and still trigger the pulse. You can remove the PAUSE statement entirely, but I am afraid it seems like you're at the speed limitations of the BS1.

    I tried PWM command, is faster:
    http://www.youtube.com/watch?v=n4G9u6sqr24
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-06 07:56
    You may be getting a visual indication that the motor is moving faster, and it certainly will be stepping faster from the PWM signal, however, unlike the previous code where the step pulses were fixed and consistent, the PWM command on the BS1 was designed to generate an analog voltage via a filter circuit by varying the proportion of 0's to 1's it is sending out. Also, as you have noticed in order to keeo it going it has to stay in that loop, however the PWM pulses are not consistent and there is a gap in the pulses each time the code loops. It is just happening fast enough that you don't notice.

    As for direction, if your direction line was connected to P0 in the original cod you should have observed the stepper motor stepping one way for 100 pulses and then turning the other way. The line StepperDir = CW or CCW is what set direction.
Sign In or Register to comment.