Stepper motor

Hello,

I would like to drive my stepper motor by using impulsions with DIR and STEP. I would like to have a rotational speed of 1000 rpm. However, I can't achieve it. My motor doesn't from 815 to 1000 rpm.

Here you are my code :

int x=1;
int a=20;
int Tempspulse; //durée totale d'une pulse

// Référence Moteur
int dirPin=8;
int stepPin=9;

void setup()
{
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
Tempspulse=1000-a*x;
Serial.begin(9600);
}

void loop()
{
// phase Accélération
while(Tempspulse>300)
{Tempspulse=1000-a*x;
digitalWrite(stepPin, HIGH);
delayMicroseconds(Tempspulse/2);
Serial.println(Tempspulse);
digitalWrite(stepPin, LOW);
delayMicroseconds(Tempspulse/2);
x++;}

digitalWrite(stepPin, HIGH);
delayMicroseconds(300/2);
digitalWrite(stepPin, LOW);
delayMicroseconds(300/2);
}

Thank a lot in advance

What is the stepper actually connected to? Why are you not using the Stepper library?

My motor doesn't from 815 to 1000 rpm.

Your motor does do what from 815 to 1000? What does it do above 1000? What does it do below 815?

Excuse me : my motor stops turning from 815 to 1000 rpm.
Below 815 rpm, my motor turns accelerating.
My stepper motor is connected to a DRV8825 driver, which is connected to a Arduino Mega.
I don't use Stepper library, because I use a rotation sensor. And if I use "AccelStepper", Arduino isn't able to supply values of my sensor in same time my motor turns. It only supplies me the values at the end of the fonction...
Excuse me for my English

I dont know much about steppers, but from what I have read, is your motor accelerating from 0 to 815 rpm and stopping at 815 but you want it to go further?

Why is the acceleration stopping at Temspulse=300? Maybe thats when it hits 815rpm?

You are printing the Tempspulse values on the Serial monitor, so at what value is it hitting 815rpm?

Isabelle, a little more information would help a lot.
Do you mind answering the following questions:-

How many steps per revolution of your motor?
Can you please show us your schematic diagram?
Finally, out of interest only, how are you measuring RPM? Edit: OK, I see by your following answer that 815 is only the calculated RPM, not measured. By this time your motor is probably mis-stepping and may not even be truly reaching 815RPM

Edit: What other circuitry are you using to generate your step sequence? Noticeably, you only use one Arduino pin. Doh. Iwas looking at the DRV8828 datasheet instead of the DRV8825. Bad eyesight. :slight_smile:

Yes it is, Srijal97!!
Tempspulse=300µs (=> equals to 1 pulse is made during 300 µs, which corresponds to 1000 rpm).
The serial monitor continues to make the programme however the motor has already stopped .

Isabelle_VP:
Yes it is, Srijal97!!
Tempspulse=300µs (=> equals to 1 pulse is made during 300 µs, which corresponds to 1000 rpm).
The serial monitor continues to make the programme however the motor has already stopped .

And how many pulses does it take for it to complete 1 revolution?
~~Is it 20pulses? As 300µs=5/10,00,000mins => 10,00,000/5=20,000 pulses per min ~~
so, for 1000rev per min, 1 rev is equivalent to 20,000/1000=20 pulses.
If its not 20, this might be the problem. You can test it by sending 20 pulses and seeing if it completes a revolution

Edit: It should be 200 steps for 1 revolution as Isabelle mentions ahead
You could add a link to your stepper motor datasheet.

It would be better to change this

digitalWrite(stepPin, HIGH);
  delayMicroseconds(300/2);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(300/2);

to

digitalWrite(stepPin, HIGH);
  delayMicroseconds(10);  //   <---- you probably don't need this line at all due to the slowness of digitalWrite()
  digitalWrite(stepPin, LOW);
  delayMicroseconds(290);

as this puts all the timing delay in one place and makes it easier to manage. The stepper driver just needs a very short pulse - perhaps 10 µsecs or so to trigger a step

If you want to move at 1000RPM = 16.67 rps (call it 17) and if there are 200 steps per rvolution that means a delay between steps of 294 µsecs - pretty much the same as your 300.

For high speeds a stepper motor needs a high voltage power supply. What power supply are you using (volts and amps).

Also, post a link to the datasheet for your stepper motor.

Do you have a load on the motor shaft, or something that behaves like a flywheel. That can make it perform better by damping out resonances.

Have your tried microstepping?

It is OK to use delayMicroseconds() while testing but you probably don't want to use it in production code. Have a look at the second example in this Simple Stepper Code

...R
Stepper Motor Basics

Since I was looking at the wrong datasheet, I've done some editing of my earlier response.

I had written more here, but Robin2 just covered the points I planned to mention regarding voltage, so I don't need to.

The direction control is easy to implement. Connect your dirPin to Dir on the DRV8825, then take it either high or low to control your motor's direction.

Thank for your answers, Srijal97, PaulS and OldSteve.

OldSteve : I only have one driver for one stepper motor. Yes it is a bipolar stepper motor, excuse me !
My motor has 200 steps per revolution. (I programm it for full steps for the moment).
To measure RPM, I will use rotational sensor and speed sensors. I would like to turn my motor thanks to a potentiometer and I would like to create a correction if the motor is discordant with the sensors.
That's why I need to know the RPM during the variation of speed of my motor.
I make you the needed schema

Capture.JPG

Thank for the other messages !!! I read your answers and I quickly answer.

Isabelle_VP:
Thank for your answers, Srijal97, PaulS and OldSteve.

OldSteve : I only have one driver for one stepper motor. Yes it is a bipolar stepper motor, excuse me !
My motor has 200 steps per revolution. (I programm it for full steps for the moment).
To measure RPM, I will use rotational sensor and speed sensors. I would like to turn my motor thanks to a potentiometer and I would like to create a correction if the motor is discordant with the sensors.
That's why I need to know the RPM during the variation of speed of my motor.
I make you the needed schema

The schematic isn't really necessary now. I asked when I mistakenly thought you had a DRV8828 driver.

What is important now is the datasheet for your motor. As mentioned by Robin2, to increase the speed of your motor, you need to use a higher drive voltage, while limiting the current to the maximum allowed for your motor. (The DRV8825 can easily do this.)

The used motor is a 39SH38-0803A. I use a 24V voltage.
I know my motor can turn up to 1000 rpm, because it turns up to it thanks to the library AccelStepper.
I have limited the current as the videos shows it on Pololu website.
I tried to change, as you adviced me Robin2, from 300/2 to 10 µs ... However, it doesn't work...
I tried to use half steps instead of full steps, but it doesn't work better :frowning:

When the motor reaches 815rpm, whats the Tempspulse value it shows on the Serial monitor?

The Tempspulse value indicates 300 because it continues to decrease even if the motor doesn't achieve turning.

I tried to turn only my motor and I take note that I change the delayMicroseconds value, but the motor continues to turn at the same speed Maybe that's why my code doesn't work But I don't understand why my motor does that. I continue to search. Thank you all !

Srijal97:
When the motor reaches 815rpm, whats the Tempspulse value it shows on the Serial monitor?

The values in the serial monitor will continue to change with the code, despite the fact that the motor can't keep up.
(Isabelle just said the same while I was typing this.)

Isabelle, what's different in the AccelStepper library that allows it to drive your motor at 1000RPM, when it can't be done by your code? That's what puzzles me at this point. Does it maybe use longer pulses with shorter 'off' times.
Or is your Serial.print() statement possibly interfering with your pulse rate?

Maybe a close examination of the AccelStepper library would be a good idea. You might be able to copy and adapt it.

And what type of rotation sensor are you using? ie Why exactly can it not be used with the AccelStepper library? I didn't really understand your earlier explanation of this.

Edit: And I searched but could not find the datasheet for your motor. Not to worry.

oh, im sorry, i get it now :slight_smile:

Isabelle_VP:
I tried to change, as you adviced me Robin2, from 300/2 to 10 µs ... However, it doesn't work...

The change I suggested should have made no difference. I just substituted 10 and 290 for 2 times 150. I presume you did change the other 300/2 to 290 ?

You need to post your latest code so that we can keep up with what you are trying.

The words "it doesn't work" tell us nothing that provides a basis for giving more advice.

Also, you need to post a link to the datasheet for your motor - not just the manufacturers number. At this stage we don't know whether the motor and the DRV8825 are compatible with each other.

Using meaningful names for variables and constants (as in my Simple Stepper Code) makes it easier to understand code and to spot problems.

...R

Hello OldSteve,

Fisrtly, I join the datasheet of my motor. Then, maybe I don't understand very well AccelStepper, I begin. I wrote the following code with AccelStepper, the motor achieved to rotate up to 1000 rpm without issue but the Arduino only sent me back one value at the end at the rotation of my motor. However, I would like to obtain the values "in live". The used rotational sensor works like this : it varies from 0 to 5V, according to the number of rotations (from 0 to 50).
Nevertheless,I don't know how introduce some code in AccelStepper...

int x=1; //incrementation
int a=20; //coefficient de multiplication
int Tempspulse; //durée totale d'une pulse

// Référence Moteur
byte dirPin=8; // broche de direction
byte stepPin=9; // broche des pas
byte Mode0=7; //fullstep or halfstep

void setup()
{
pinMode(dirPin, OUTPUT); //sortie
pinMode(stepPin, OUTPUT); //sortie
pinMode(Mode0, OUTPUT); //sortie
digitalWrite(Mode0, HIGH); //fullsteps activated
Tempspulse=1800-a*x; //initialisation de l'équation de décrémentation
Serial.begin(9600); //renvoi des infos en baud
}

void loop()
{
// phase Accélération = tant que le moteur n'a pas atteint la vitesse, il accélère
while(Tempspulse>300)
{Tempspulse=1800-a*x;
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
delayMicroseconds(Tempspulse-10);
Serial.println(Tempspulse);
x++;}

// il a atteint la vitesse et la maintient
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
delayMicroseconds(Tempspulse-10);
Serial.println(Tempspulse);
}

HelloRobin2,
I sent the following code, and I have changed 300µs by 500µs but the motor doesn't see the difference, it only rotates at the same speed, and if the serial monitor displays me the good information (980,960,940...=>300), the motor rotates at the same speed, it doesn't accelerate. Is it possible that the microprocessor keeps in mind old values and refuses to have new codes?
Your Simple Stepper Code is wonderful ! Thank !

// --- Programme Arduino ---
// Le 26/10/2015
/* Test moteur pas à pas bipolaire via DRV8825 en pulse dir avec accélération*/

int x=1; //incrementation
int a=20; //coefficient de multiplication
int Tempspulse; //durée totale d'une pulse
int Beginvalue = 1000; //valeur de départ (le moteur monte sans problème à cette valeur)

// Référence Moteur
byte dirPin=8; // broche de direction
byte stepPin=9; // broche des pas
byte Mode0=7; //fullstep or halfstep

void setup()
{
pinMode(dirPin, OUTPUT); //sortie
pinMode(stepPin, OUTPUT); //sortie
pinMode(Mode0, OUTPUT); //sortie
digitalWrite(Mode0, LOW); //fullsteps activated
Tempspulse=Beginvalue-a*x; //initialisation de l'équation de décrémentation
Serial.begin(9600); //renvoi des infos en baud
}

void loop()
{
// phase Accélération = tant que le moteur n'a pas atteint la vitesse, il accélère
while(Tempspulse>300)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
delayMicroseconds(Tempspulse-10);
Serial.println(Tempspulse);
x++;
Tempspulse=Beginvalue-a*x;}

// il a atteint la vitesse et la maintient
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
delayMicroseconds(Tempspulse-10);
Serial.println(Tempspulse);
}

Thank a lot both for your quick and complete answers! Thanks !!!

Here you are the datasheet of my motor
http://www.delta-line.com/data/media/39SH38_16.pdf