Closed loop stepper speed?

Hello,

I'm getting my feet wet in cnc stuff so I'm testing with an arduino mega to control a nema 34 stepper with driver from stepperonline. I am succesfully controlling the driver/motor with the x axe of a little joistick with arduino. So the code works, but... as soon as I want to print in serial the motor chops so it seems the arduino isn't strong enough to do both. This is no problem since I don't need to print in seriel monitor. But the top speed I can achieve is pretty slow to me it seems.
I have added the code I wrote and driver specs aswell as motor specs as attachements if you need this to help me out here.

Here is a short vid of the actuall movement speeds;

any suggestions how to increase the speed? I am using full step in the dipswitches on driver.

https://forum.arduino.cc/index.php?action=dlattach;topic=560607.0;attach=268013

Thanks

CL86T.pdf (447 KB)

34HS59-5004D-E1000.pdf (158 KB)

S-350-60.pdf (124 KB)

YoGroove:
any suggestions how to increase the speed? I am using full step in the dipswitches on driver.

Yes. Please post the program you are having trouble with.

And please make your images visible in your Post. See this Simple Image Guide

...R
Stepper Motor Basics
Simple Stepper Code

Post the code! No idea what its doing otherwise...

Thanks guys,

The code is in the picture I took but I'll write it here if you prefere...

int XaxePin =A6;
int XValue=0;
int YaxePin =A5;
int YValue=0;
double Speed=0;
void setup() {

                   
  //Serial.begin(9600);
  pinMode(8,OUTPUT); // DIR
  pinMode(10,OUTPUT); // STEP
  digitalWrite(8,LOW);
  digitalWrite(10,LOW);
}

void loop() {
 XValue= analogRead(XaxePin);
 XValue = map(XValue,0,1022,3600,1);
 YValue= analogRead(YaxePin);
  if(XValue<1600 )
    { 
     int DirState=digitalRead(8);
      if(DirState==HIGH){digitalWrite(8,LOW);}
     // digitalWrite(9,LOW);//delay(50);
   //   digitalWrite(8,LOW);
      int useValue=analogRead(XaxePin);
      Speed = map(useValue,0,1022,1800,1);
      digitalWrite(10,HIGH);delayMicroseconds(2);digitalWrite(10,LOW);delayMicroseconds(Speed);
          }
   else if(XValue>2000 )
    {      int DirState=digitalRead(8);
      if(DirState==LOW){digitalWrite(8,HIGH);}
      int useValue=analogRead(XaxePin);
      Speed = map(useValue,0,1022,1,1800);
      digitalWrite(10,HIGH);delayMicroseconds(2);digitalWrite(10,LOW);delayMicroseconds(Speed);
          }  
}

This is the latest I've tried so far and result is the same. The difference here is the pulse is set at 2 microseconds fixed and the pauze is variable according to the joystick value.

Could it be that arduino isn't working at those speeds? Anyway I can check the output of the step pin? To see if it is really doing what I coded?
thanks again.

Youri

YoGroove:
The code is in the picture I took

A picture of code (or any other text) is useless.

Don't put several statements on one line like the following - it makes the program very hard to read

digitalWrite(10,HIGH);delayMicroseconds(2);digitalWrite(10,LOW);delayMicroseconds(Speed);

You said in your Original Post that the problem is caused by printing but I don't see any Serial.print() statements in your program.

You seem to have analogRead(XaxePin) in several places. Don't do that. Just read the X and Y values at the start of loop() and use those values everywhere.

...R

Ok thanks for the info, I'll change few things and test again.

As for the Serial.print issue; that was causing another problem for driving the motor and can't be used at all so I don't bother with that and left it out after testing. I only used it to see the values returned by the joystick. Doing that makes the motor even slower.

The problem I have is that my motor turns pretty slow even if I set fixed pause times of 2 microseconds.
If you check the little clip I've posted earlier you can see the motor running with these settings.

Maybe it has to do with analogRead issue, causing the arduino to lose some microseconds due to reading those values coup^le of times. I will test this tomorrow and let you know.

Grts

If you want to generate high rates of pulses from the Arduino and have it do anything else, you
may need to drive the step pulses from an interrupt handler. analogRead() takes 110us to complete,
it alone will limit your step rate significantly.

You might want to investigate the techniques used in GRBL for getting step pulse performance from an Arduino.

MarkT:
If you want to generate high rates of pulses from the Arduino and have it do anything else, you
may need to drive the step pulses from an interrupt handler. analogRead() takes 110us to complete,
it alone will limit your step rate significantly.

You might want to investigate the techniques used in GRBL for getting step pulse performance from an Arduino.

Exactly the kind of thing I thought was the problem. As this is my first project in arduino I have still a lot to learn and think next thing to learn is what you suggest. If it really takes 110us to complete then this is the problem for shure. That would become 112us+2us for the pulse top speed.
Thanks for pointing me in the right direction.

My goal is to put together a 3Dprinter/laser/spindle cnc. I have a couple of ramps1.4 to test thes things. So I might be in here some more in the future :wink:

grts

YoGroove:
The problem I have is that my motor turns pretty slow even if I set fixed pause times of 2 microseconds.

That implies a step rate of about 250,000 steps per sec - what step rate do you really need?

In any case the digitalWrite() function is slower than that so your actual step rate will be much lower - maybe one step every 16 µsecs or about 60,000 per sec.

Either use the digitalWriteFast library or, better still, direct port manipulation if you really need high step rates.

And have you checked what is the minimum pulse width that is accepted by your stepper driver?

...R

YoGroove:
Exactly the kind of thing I thought was the problem. As this is my first project in arduino I have still a lot to learn and think next thing to learn is what you suggest. If it really takes 110us to complete then this is the problem for shure. That would become 112us+2us for the pulse top speed.
Thanks for pointing me in the right direction.

My goal is to put together a 3Dprinter/laser/spindle cnc. I have a couple of ramps1.4 to test thes things. So I might be in here some more in the future :wink:

grts

Definitely time to study the GRBL codebase then...