Shop OBEX P1 Docs P2 Docs Learn Events
steppermotor control — Parallax Forums

steppermotor control

chrillzchrillz Posts: 3
edited 2009-01-06 23:41 in BASIC Stamp
I have a bipolar stepper motor controller which I try to control with my bs2. (The schematic can be found at http://farm4.static.flickr.com/3195/2910951388_0e05a5c7cc_b.jpg)

It needs to get a high or low signal on the "Direction"-pin (depending on if it is to be driven clockwise or counter clockwise), and also needs to be pulsed at the "Step-pin" with the desired frequency.

Now my problem is that when I try to control the motor with my basic stamp it seems to overstep the motor and it gets really week. I have successfully controlled the stepper-controller via the parallelport on my laptop with a software called Turbo CNC. At a frequency of ca 200 Hz the motor is really strong and runs great!

The basic stamp code that I´ve tried is:

HIGH 1 ' Dir-pin, making the motor run clockwise
freqout 2, 10000, 200 ' Step-pin, should give the motor a pulse with the frequency of 200Hz for 10 seconds right?

This code makes the motor whissle and turn weekly.. Does anybody know what´s wrong?

Post Edited (chrillz) : 1/5/2009 11:30:14 PM GMT

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-06 01:13
    chrillz

    I think Your board is looking for the STEP pattern. something like this
    %1100
    %0110
    %0011
    %1001

    The rate at which You feed this pattern will control its speed.
    I could be wrong. I'm not familiar with Your stepper board.
    Take a look at DATA,READ,and SHIFTOUT
    Experiment #27 is a good place to start. "StampWorks Manuel"Pg. 150

    ________________$WMc%_____

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there·········································· E=$WMc%2
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-01-06 01:13
    FREQOUT doesn't send out a hard digital pulse-form.

    In PBASIC Help we read, "FREQOUT generates one or two sine waves using a PWM algorithm."· Not what you're looking for.

    So, I think you want to look at using PULSOUT (or PULSOUT nested in a FOR...NEXT or DO...LOOP...UNTIL.)
  • chrillzchrillz Posts: 3
    edited 2009-01-06 11:11
    The same steppercontroller can be driven by an Arduino with this code:

    found on dev.www.reprap.org/bin/view/Main/Stepper_Motor_Driver_1_2
    #define stepPin 4
    #define dirPin 5
    
    void setup()
    {
      Serial.begin(9600);
      Serial.println("Starting stepper exerciser.");
    
      pinMode(stepPin, OUTPUT);
      pinMode(dirPin, OUTPUT);
    
      digitalWrite(dirPin, HIGH);
      digitalWrite(stepPin, LOW);
    }
    
    void loop()
    {
        int i, j;
        
        for (i=1650; i>=600; i-=150)
        {
          Serial.print("Speed: ");
          Serial.println(i);
          
          for (j=0; j<2000; j++)
          {
            digitalWrite(stepPin, HIGH);
            delayMicroseconds(2);
            digitalWrite(stepPin, LOW);
            delayMicroseconds(i);
          }
    
          delay(500);
          Serial.println("Switching directions.");
          digitalWrite(dirPin, !digitalRead(dirPin));
    
          for (j=0; j<2000; j++)
          {
            digitalWrite(stepPin, HIGH);
            delayMicroseconds(2);
            digitalWrite(stepPin, LOW);
            delayMicroseconds(i);
          }
    
          delay(1000);
          Serial.println("Switching directions."); 
          digitalWrite(dirPin, !digitalRead(dirPin));
      }
    }
    
    



    "The basic way the motor exerciser works is this:
    The stepper will take 2000 steps in one direction
    The stepper will take 2000 steps in the opposite direction
    The speed will increase or decrease."

    It seems like the corresponding way to do it in Pbasic, for just running the motor 2000 steps should be like:


    counter VAR word
    HIGH Dir_Pin
    FOR counter = 1 to 2000
    HIGH Step_Pin
    PAUSE 20
    LOW Step_Pin
    PAUSE 20
    NEXT
    
    




    Am I in the right direction?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-01-06 12:16
    Looks right, too.· A series of PULSOUTs, a series of HIGH/LOWs, same difference.· Give it a whirl.

    Post Edit -- Just wanted to add for the others that your L297·generates the Gray Code with each Clock input, as appropriate given the state of the Dir input.

    Post Edited (PJ Allen) : 1/6/2009 12:21:54 PM GMT
  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-06 23:41
    chrillz

    I see why You want to use the BS2, The other Stamp needs way to much code just to spin a stepper!

    __________________$WMc%________________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there·········································· E=$WMc%2
Sign In or Register to comment.