Stepper Ramping

Hello, I am writing stepper motor control with magnetic sensor.

When sensor is 0 and motor pulse between 0-600 motor is running properly if I turned the sensor on and off unlimited motor working properly . But when I raise motor pulse value over 600 motor doesnt work.
If I turned on sensor while motor working motor is stopping. Actually motor is strain.

Thanks in advance

#include <AccelStepper.h>

 String inputString="";

AccelStepper stepper(1, 8, 9);


int entpin=13;
int entoutpin=12;
int sensordeger=0;
 int side=-1;
 long stepCnt=0;
 int index=0;
 int speed=900;
 bool stepCompleted=false;
 bool isRunning=false;
 int finalStep=-1;
int sensorLowCount=0;
 void setup()
{  
  Serial.begin(9600);
 
  stepper.setMaxSpeed(900);//1100 
  stepper.setAcceleration(3800);
  inputString.reserve(200);
}
int sensorReading = 0;
void loop()
{
  sensorReading = analogRead(A0);
  if (sensorReading > 1000) 
  {
    isRunning=true;
  } 
  else
  {
   isRunning=false;
   delay(100);
  }
 
   if(isRunning){
   while (Serial.available()) {
    stepCompleted=false;
    char inChar = (char)Serial.read();
    inputString += inChar;
       if (inChar == ' ') {
        if(index==0)
        { stepCnt= inputString.toInt(); inputString=""; index=1;} 
        else if(index==1)
        { side= inputString.toInt(); inputString=""; index=2;} 
        else if(index==2)
        { speed= inputString.toInt(); inputString=""; index=0;
          stepper.setMaxSpeed(speed);//1100
        } 
      }

   }
      
    if(side==0){ 
      Serial.print("currentPosition=");
      Serial.println(stepper.currentPosition());
      Serial.print("stepcount=");
      Serial.println(stepCnt);
      Serial.print("result=");
      Serial.println(stepper.currentPosition() + stepCnt);
      Serial.println("");
      stepper.moveTo(stepper.currentPosition() + stepCnt);
      finalStep=stepper.currentPosition() + stepCnt;
      side=-1;       
    }
    else if(side==1)
    { Serial.print("currentPosition=");
      Serial.println(stepper.currentPosition());
      Serial.print("stepcount=");
      Serial.println(stepCnt);
      Serial.print(stepper.currentPosition());
      Serial.print("result=");
      Serial.println(stepper.currentPosition() - stepCnt);
      Serial.println("");      
      stepper.moveTo(stepper.currentPosition() - stepCnt);
      finalStep=stepper.currentPosition() + stepCnt;
    side=-1;     
    }

    if(stepper.currentPosition()==finalStep && stepCompleted==false)
    {
      Serial.write("ok"); 
      Serial.println("ok");
      stepCompleted=true;
    }
     stepper.run();    
    }  
}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

From a quick look I could not see 600 anywhere in your code. However if I could review it in my text editor I could be more certain.

...R

Vecihi:

    if (yon == 0) // şişeden çek

{
      Serial.println(stepCnt);
      Serial.print("Sonuç=");

stepper.moveTo(stepper.currentPosition() + stepCnt);
      finalStep = stepper.currentPosition() + stepCnt;    ????????? Same sign
      yon = -1;
    }
    else if (yon == 1) // şişeye ekle
    {
      Serial.println(stepCnt);
      Serial.print(stepper.currentPosition());  ????????????  Why?
      Serial.print("Sonuç=");

stepper.moveTo(stepper.currentPosition() - stepCnt);
      finalStep = stepper.currentPosition() + stepCnt;  ???????? Different sign
      yon = -1;
    }

I modified my post sorry

Vecihi:
I modified my post sorry

Thanks. But you did not explain where the 600 is, or should be?

...R

I get this c# // speed= inputString.toInt(); inputString=""; index=0;
stepper.setMaxSpeed(speed);//1100 //

Vecihi:
I get this c#

That (and your image) don't convey anything to me.

...R

I select in the progress bar value c# (0-1100) its speed value and this value write to arduino (speed=inputstring)with serial port. Arduino reading this value.

What you are describing in your Reply #7 is how you send values to the Arduino.

But the problem you described in your Original Post seems to arise after the Arduino has received the value correctly.

Now, when the Arduino receives a value of 600, how does it use it?

When you have a problem like this it is usually easier to put the problem value (600 in this case) directly into the Arduino program so that the problem is not confused by the business of receiving data.

...R

The real issue is step motor working every speed without magnetic sensor. But when ı take over the magnetic sensor motor doesnt work if speed over 600. 600= motor pulse value*step(motor driver step number each degree). If motor acceleration is reduced the problem nothing has changed.

Try commenting out all the print statements and see if that helps. Serial.print() is very slow and it may prevent AccelStepper from being called sufficiently frequently.

...R

I tried it.But nothing has changed.

Maybe it's not the issue, but you Serial print a lot. Change Serial.begin(9600) which is very slow, to Serial.begin(115200).

Vecihi:
I tried it.But nothing has changed.

Post the revised program so we can see exactly what you tried.

...R

I commented all print statements as you say and I changed bound rate value 115200. But nothing has changed. :frowning:

//Serial.print("currentPosition=");
     //Serial.println(stepper.currentPosition());
      //Serial.print("stepcount=");
     // Serial.println(stepCnt);
      //Serial.print(stepper.currentPosition());
      //Serial.print("result=");

Vecihi:
I commented all print statements as you say and I changed bound rate value 115200. But nothing has changed. :frowning:

I asked you to post the program, not a little piece of it. Usually the problem is in the other piece.

...R

is it arduino or c# ? İf its arduino I published all code as you know

ınfact ı cant understand you

Vecihi:
is it arduino or c# ? İf its arduino I published all code as you know

ınfact ı cant understand you

In Reply #10 I suggested that you comment out the print statements
In Reply #11 you said you did and nothing changed
In Reply #13 I asked you to post the program
In Reply #14 you posted a little piece of the program
In Reply #15 I asked you to post the complete program

What is hard to understand?

Help us to help you.

...R

Respect! I may not have understood to you.

ın reply 11 I said : Clean all print statements and ı said nothing changed . is it freak?

ın reply 12-13-14 : Already I published complete program in first reply. I published just al little print statements because other program in my first published code.

and my last comment ı asked all codes means:arduino or c#.

What is the hard to understand.

İf you can help or cant.

Thanks

If you don't want help that's fine with me.

if you do want help then in your next reply post the complete program from which the part in Reply #14 was taken.

...R