Shop OBEX P1 Docs P2 Docs Learn Events
How to increase motor speed? — Parallax Forums

How to increase motor speed?

grbeltrangrbeltran Posts: 6
edited 2006-11-09 05:45 in General Discussion
Using the····· Stepper.java and stepperTest.java, listed very commonly in the forum, how do I increase the speed
of the motor?

I have decreased the delay in between each step to 1 or EVEN O ..
Example

public class stepperTest {
· public static void main() {
··· boolean x1 = true;
··· Stepper motor = new Stepper(CPU.pin4, CPU.pin5, CPU.pin6, CPU.pin7);
··· while(x1 = true) {
····· motor.stepFFwd(48, 0);·················· // one rev clockwise
····· CPU.delay(5000);························· // wait 1/2 second
····· motor.stepFRev(48, 0);·················· // one rev counter clockwise
····· CPU.delay(5000);························· // wait 1/2 second
··· }
· }
}

and it increases the speed but I need to increase the frequency somehow... or be able to change the delay(in between steps) to us...?
can anybody please help?

Thanks,

Gabe

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 04:32
    Please post URL to thread where stepper.java is attached,
    or attach stepper.java. So we have not to search for it.

    regards peter
  • grbeltrangrbeltran Posts: 6
    edited 2006-11-09 04:44
    Okay, I am sorry.· The stepper files are in this attachment.· Any help is greatly appreciated!


    Thanks,
    Gabe
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 04:46
    I found the product the files relate to.
    http://www.parallax.com/detail.asp?product_id=27964

    public class stepperTest {
    · public static void main() {
    ··· boolean x1 = true;
    ··· Stepper motor = new Stepper(CPU.pin4, CPU.pin5, CPU.pin6, CPU.pin7);
    ··· while (x1) {
    ····· motor.stepFFwd(48, 15);·················· // one rev clockwise
    ····· CPU.delay(5000);························· // wait 1/2 second
    ····· motor.stepFRev(48, 15);·················· // one rev counter clockwise
    ····· CPU.delay(5000);························· // wait 1/2 second
    ··· }
    · }
    }

    You could try lowering the CPU.delay(5000)
    so the stepper motors get updated more
    frequently.

    regards peter
  • grbeltrangrbeltran Posts: 6
    edited 2006-11-09 04:57
    I believe the CPU.delay()· is the delay between stepping intervals,

    Ex
    step··step· step ·step ·step·<
    (CPU.delay)·
    > step· step ·step· step· step<
    (CPU.delay)
    > step etc.

    right?

    but what will·let me

    stepstepstepstepstepstepstep· faster..

    Thanks

    Gabe·······
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 05:10
    Here are the methods in Stepper.java

    · /**
    ·· * Sets up phase inputs for step index
    ·· */
    · private void setFullStep(int theStep) {

    ···· switch (theStep) {

    ······ case 0:
    ········ CPU.writePin(ph1Pin, true);
    ········ CPU.writePin(ph2Pin, true);
    ········ CPU.writePin(ph3Pin, false);
    ········ CPU.writePin(ph4Pin, false);
    ········ break;

    ······ case 1:
    ········ CPU.writePin(ph1Pin, false);
    ········ CPU.writePin(ph2Pin, true);
    ········ CPU.writePin(ph3Pin, true);
    ········ CPU.writePin(ph4Pin, false);
    ········ break;

    ······ case 2:
    ········ CPU.writePin(ph1Pin, false);
    ········ CPU.writePin(ph2Pin, false);
    ········ CPU.writePin(ph3Pin, true);
    ········ CPU.writePin(ph4Pin, true);
    ········ break;

    ······ case 3:
    ········ CPU.writePin(ph1Pin, true);
    ········ CPU.writePin(ph2Pin, false);
    ········ CPU.writePin(ph3Pin, false);
    ········ CPU.writePin(ph4Pin, true);
    ········ break;
    ···· }
    · }


    · /**
    ·· * Step forward clockwise
    ·· *
    ·· * @param steps Number of CW steps
    ·· * @param msDelay delay between steps in milliseconds
    ·· */
    · public void stepFFwd(int steps, int msDelay) {

    ··· while (steps-- > 0) {
    ····· stpIdx = (stpIdx + 1) % 4;
    ····· setFullStep(stpIdx);
    ····· CPU.delay(msDelay * 10);

    ··· }
    · }


    · /**
    ·· * Step forward counter-clockwise
    ·· *
    ·· * @param steps Number of CCW steps
    ·· * @param msDelay delay between steps in milliseconds
    ·· */
    · public void stepFRev(int steps, int msDelay) {

    ··· while (steps-- > 0) {
    ····· stpIdx = (stpIdx + 3) % 4;
    ····· setFullStep(stpIdx);
    ····· CPU.delay(msDelay * 10);
    ··· }
    · }
    }

    The minimal delay between steps is when using msDelay=0,
    the delay is then determined by the loop
    while (steps-->0)
    in which setFullStep() is called.
    setFullStep() itself contains 4 writePin() statements.

    To minimize that delay you need to rewrite it,
    instead of 4 CPU.writePin() you use 1 CPU.writePort()

    Another option to minimalize the delay, is by defining stpIdx global,
    so you don't need to pass it as a parameter each time.

    regards peter
  • grbeltrangrbeltran Posts: 6
    edited 2006-11-09 05:28
    I see... okay, well my situation is slightly different because I already have a driver and a different stepper motor...

    In other words all I need are two pins, step and direction.·· Simple i guess. but

    does that

    switch (theStep) {

    ······ case 0:
    ········ CPU.writePin(ph1Pin, true);
    ········ CPU.writePin(ph2Pin, true);
    ········ CPU.writePin(ph3Pin, false);
    ········ CPU.writePin(ph4Pin, false);
    ········ break;

    ······ case 1:
    ········ CPU.writePin(ph1Pin, false);
    ········ CPU.writePin(ph2Pin, true);
    ········ CPU.writePin(ph3Pin, true);
    ········ CPU.writePin(ph4Pin, false);
    ········ break;

    etc...

    even matter anymore, or what exactly is is for. Do I need it?



    Thanks,



    gabe
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 05:45
    Read this document,
    http://www.parallax.com/dl/docs/prod/motors/Stepper_Motor_27964.pdf

    You'll see the patterns are encoded in setFullStep.

    If you have a different stepper motor, check the
    datasheet on what patterns can be used.

    regards peter
Sign In or Register to comment.