Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Make a stepper motor move

Status
Not open for further replies.

kidi3

Full Member level 1
Joined
Mar 31, 2013
Messages
98
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,350
Hi guys..

I am at the moment trying to make a stepper motor move, but can't seem to make it happen.

I am interfacing it through a control board, which takes the input Step, Dir, En, and 5V.

I am providing those inputs signal from an arduino, but can't get the damn thing to move. all it does it move a step forward and backwards, like it being stuck or and tries to wiggle out of something.. What could the reason be..

The code i am running om my arduino is this:

Code:
#include "stepper_motor.h"
int max_step = 200;
stepper_motor::stepper_motor()
{
  pinMode(BUILTIN_LED,OUTPUT);
  pinMode(step_pin,OUTPUT);
  pinMode(dir_pin,OUTPUT);
  pinMode(en_pin,OUTPUT);

  alive_bool = true;
  position_bool = false;
  step_count = 0;
}

void stepper_motor::step_pwm()
{

  if(position_bool==true)
  {
    //Dir pin low 
    digitalWrite(step_pin, LOW);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,LOW);

    delay(0.005);

    digitalWrite(step_pin, LOW);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,HIGH);

    delay(0.005);

    int step = 0;
    while(step < max_step)
    {
      digitalWrite(step_pin,HIGH);
      delay(1);
      digitalWrite(step_pin,LOW);
      delay(1);
    }

    //digitalWrite(en_pin,LOW);
    //position_bool = false;
  }
  else
  {
    //Dir pin high 
    delay(1000);
    digitalWrite(step_pin, LOW);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,LOW);

    delay(0.005);

    digitalWrite(step_pin, LOW);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,HIGH);

    delay(0.005);

    digitalWrite(step_pin, LOW);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,HIGH);

    int step = 0;
    while(step < max_step)
    {
      digitalWrite(step_pin,HIGH);
      delay(1);
      digitalWrite(step_pin,LOW);
      delay(1);
    }

    //digitalWrite(en_pin,LOW);
    //position_bool = true;
  }



}

And the things are connected as such:

circuit.png

I suspect the issue is caused by the battery and the arduino isn't sharing the ground pin, but on the other hand. Only one ground signal is provided which is from the negative terminal of the battery. Which make me question what might be wrong?


The control board i am using is a ST330-v3

And the motor i am using is a bipolar stepper motor.
 

Hi,

Difficult to say.

A assume wrong wiring. Power supply, signal lines, ...motor?
Test to interchange A+ with A-.

Klaus

- - - Updated - - -

Added:

Do you have a scope to make the signals visible?
 

I don't have a scope on me..

the power supply could not be the case.. I could measure the voltage but that it.

The motor lines might be incorrect.. the colouring of them seemed a bit of..

But what you are saying is that the Code should work, and it must be a hardware wiring problem...
 

Hi,

I didn't say anything about your code...

******

But now:
Did you read the datasheet? Especially the three signals? Timing and polarity?

First set EN, than you have to wait at least 5us, then set DIR, then wait at least 5us, then clear STEP wait 2.5us, then set STEP wait 2.5us.

You don't take care about signal order, nor timing.
(I really ask myself why reading datsheets is so much more difficult than reading posts)

EN may be active all the time. Active means HIGH. (In your code it rather looks lime low_active)
DIR is the motor rotating direction. CW or CCW. It only needs to be changed when you want to change direction.
STEP is idle HIGH. Then you need to apply H-->L ... wait .. L --> H ... wait. For each motor step. With the LH trasition the motor moves one step.

Klaus
 

Well.. yeah i read through the datasheet. Step signal should be H--> Wait --> L --> Wait --> H..

int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}

The datasheet states the the time should be atleast 2.5 µs and delay(1) = 1 ms.

so that should be ok..

The code enables EN first ,and keeps the other signal low. Then waits 5 µs then it sets the direction and wait 5µs and then comes the while loop which changes the state of step. step is always low before the while loop.

- - - Updated - - -

The green LED of the control board is lid when i run the code posted above.
it is shortly lid and then stops by changing the code.

This code should follow the timing diagram. But does the same thing, being wiggle back and forth.
HTML:
  if(position_bool==true)
  {
    //Dir pin low 
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,LOW);

    delay(0.005);

    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,HIGH);
    
    delay(0.005);

    int step = 0;
    while(step < max_step)
    {
      digitalWrite(step_pin,LOW);
      delay(0.0025);
      digitalWrite(step_pin,HIGH);
      delay(0.0025);
    }

- - - Updated - - -

I checked the wires for the motor. They are correct. Also according to the datasheet.

Motor PK244-01 6 wires.View attachment pk2_hm-601-15.pdf datasheet added
 
Last edited:

Hi,

Well.. yeah i read through the datasheet. Step signal should be H--> Wait --> L --> Wait --> H..

then this is wrong:
Code:
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}

*******
this is wrong, too.
Code:
    //Dir pin low 
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,LOW);

    delay(0.005);

    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,HIGH);
* Because it is the wrong order.
* because you don´t need EN to be inactive when you change DIR. (In the datasheet you see that DIR is changed when EN is high)
* and you shouldn´t touch STEP at all.

Now you might say: "I don´t change STEP"
--> if STEP is high before, then the line is useless anyway.
--> if STEP is low before, then the line is useless because you violate the order and timing.


Klaus
 

So... I accidently pulled the enable wire out, and the damn thing began moving.. ?

But only seems that i able to move it one direction..

I will check the enable pin and return with info.

- - - Updated - - -

I changed the code to this.

Code:
void stepper_motor::step_pwm()
{
    //Start -  En Low , DIR HIGH, STEP high
    //init configuration!
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,HIGH); // Previous LOW
    
    delay(0.005);
    
    //T1-  En HIGH , DIR HIGH, STEP HIGH
    //Enable high
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,LOW);
    
    delay(0.005);
    
    //T2-  En HIGH , DIR low, STEP HIGH
    //Direction choosen
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,LOW);
    digitalWrite(en_pin,LOW);

    delay(0.005);
    //T2-  En HIGH , DIR low, STEP HIGH
    //STEP  step between low and high with 2.5µs between
       
    while(1)
    {
      digitalWrite(step_pin,LOW);
      delay(2.5);
      digitalWrite(step_pin,HIGH);
      delay(2.5);
    }
  
}

I later noticed what you mentioned above.

- - - Updated - - -

Something is very wrong with the enable pin..
I can move the system without the information from the enable pin. But i cannot change the direction of the system.
 

Hi,

still wrong order, still no delays..

If you don´t follow the rules it is likely to fail. (Maybe it works today - by accident, but don´t expect it to run in either case)

Klaus

- - - Updated - - -

****
Something is very wrong with the enable pin..
I can move the system without the information from the enable pin.

Nothing is wrong with the enable pin. It works as described in the datasheet.

Klaus
 

I am not sure I understand what you mean with wrong order and still no delays.

Is it because i am setting all three pins at the same time and the add the delay?

between each change i only change one pin. The rest is set to same state as it was before?..
I know its redundant, i just do it so i am sure they are set to something in each timeframe.

- - - Updated - - -

I changed the code. Now there is one delay pr. signal change.


Code:
void stepper_motor::step_pwm()
{
    //Start -  En Low , DIR HIGH, STEP high
    //init configuration!
    digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,LOW); // Previous LOW
    
    delay(0.005);
    
    //T1-  En HIGH , DIR HIGH, STEP HIGH
    //Enable high
    //digitalWrite(step_pin, HIGH);
    //digitalWrite(dir_pin,HIGH);
    digitalWrite(en_pin,HIGH);
    
    delay(0.005);
    
    //T2-  En HIGH , DIR low, STEP HIGH
    //Direction choosen
    //digitalWrite(step_pin, HIGH);
    digitalWrite(dir_pin,LOW);
    //digitalWrite(en_pin,HIGH);

    delay(0.005);
    //T2-  En HIGH , DIR low, STEP HIGH
    //STEP  step between low and high with 2.5µs between
       
    while(1)
    {
      digitalWrite(step_pin,LOW);
      delay(2.5);
      digitalWrite(step_pin,HIGH);
      delay(2.5);
    }
  
}

Direction and enable pin seem to be bit weird.

When i execute the program, set direction to either high or low moves the stepper motor in the same direction.
But if manually pull out the direction input while its running changes the state of the stepper motor.
 

Hi,

I´m asking myself how I can help.

You refuse to follow the rules in the datasheet and
you refuse to follow my recommendations.

The datasheet tells you all.
All my recommendations come from the datasheet. (I have read this datasheet today for the first time.)

So reading the datasheet tells you all. Usually you don´t need any more assistance.

But I gave you the recommendations in post#4 (and all other posts)

Re-read the last three lines of post#6.

Klaus
 

I am sorry for being so hard headed and not understand what you are saying..

But I seriously do not understand where I am clearly making a mistake..

I agree as you say in post #6 that enable and direction pin is set in wrong order, and that enable should be high before direction can be changed.

The pins aren't set to anything prior to the execution of this function, which is why i start by setting step and dir high and en low. Should i just leave them untouched and let pin be until then floating?

The reason why I would say i don't change the state of step at the begining but only in the while loop, is that the state is the same, until i change it in the while loop, which should cause a move of the stepper motor, which it does when i remove the enable pin.

I don't understand why the while loop doesn't follow the specification given in the code.. Please look at the recently posted code.
 

Hi,

I don´t write software. I can read it.

*****

The datasheet begins with: EN = 0, DIR = 1, STEP = 1.
Where is this in your code?
(Maybe this is given with your microcontroller or with your compiler. Then you have to tell us, because I don´t see/know this. Otherwise you need to write the code for this.)
Maybe somewhere in the datasheet there is an information that you don´t need this. But I didn´t find such an information.

*****
from post#4:
First set EN, than you have to wait at least 5us, then set DIR, then wait at least 5us, then clear STEP wait 2.5us, then set STEP wait 2.5us.

Where do you have this in your code?
* The order EN --> DIR --> STEP
* and the delays between each of them?

******
EN needs to be active all the time.

******

Those are just some issues that MIGHT be the problem. I´m not sure of.
You need to take care about order and timing. Once at the initialization and then every time in the loop.

******

You really need careful going through the given timing diagram step by step. And follow all the timings and transitions.

******

Please confirm that the delay routine works with floating point paramater instead of integers.


Klaus

- - - Updated - - -

Added:

I don't understand why the while loop doesn't follow the specification given in the code..
Where did I say this?
--> As far as I can see the while loop of post#9 is correct.

Klaus

- - - Updated - - -

My mistake:
The datasheet begins with: EN = 0, DIR = 1, STEP = 1.
Where is this in your code?
Yes it´s in your code...(I greyed it out now)

Sorry for this.

***
Again my mistake:
Now I see that all the commands are remarked with "//", so that your code of #9 should work.
Again: Sorry.

Klaus
 

So.. The code i posted above, does the same thing as mentioned before.. The enable pin doesn't affect the motor.
And the direction can only be changed by pulling out the direction signal. The direction doesn't change, when i change its state in the code.

The step signal seem to be correct, it moves as expected by the signal.
 

Hi,

The enable pin doesn't affect the motor.
The datasheet says: pulling the EN to LOW (GND) will stop the motor current.

And the direction can only be changed by pulling out the direction signal. The direction doesn't change, when i change its state in the code.
Then most probably the controller dirves the pin LOW. (A voltmeter should show the voltage)
What pin is it?
Is the pin configured for an alternate pin function?

Klaus
 

So the arduino i am using is in reality an ESP8266

I am using the D1, D2, D3 pins.

I guess the problem could be that the ESP8266 outputs are rated for 12mA, and the ST330 inputs need about 20mA, so my microcontroller won't be able to handle it. What if I used an arduino uno?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top