how to increase the pulses to a TB6600 driver for stepper motor&arduino mega?

Hi,
i am new with arduino & the forum. And i have been working on a project i want to control the pulses to a stepper motor driver TB6600 . the driver enables me with micro stepping . I set to 3200 step per revolution I used the acccelstepper library ,however it says that its reliability is limited to 1000 step per sec . i want a way to increase the number of steps per seconds or pulses to the driver in a kind of long code .
here is the code:

#include <AccelStepper.h>
int pinStep = 19;
int pindirection= 18;
int enable=17;
//# define pinStep 9;
//# define pindirection 8;
AccelStepper mystepper(1, pinStep, pindirection);


void setup() {
  // put your setup code here, to run once:
   
 digitalWrite(enable,HIGH);

  mystepper.setMaxSpeed(37300);
  mystepper.setSpeed(variable);/*i want this variable based on calculations in steps per second however the library is unreliable if steps per second >1000*/



}

void loop() {
  // put your main code here, to run repeatedly:
  mystepper.runSpeed();


}

THANKS i also attached the whole code if anyone wanted to check it.

semi_final_haam.ino (7.36 KB)

What stepper motor you got there?

Have a look at the second example in this Simple Stepper Code - it gives you complete control over the step interval.

Of course you would need to build your own acceleration code if you need that.

You can also use one the Arduino hardware Timers to produce timed interrupts that can be used to call a short step function.

Do you really need 3200 steps per revolution?

…R

nema 23 bipoller

no not necessary , unless i can get high revolution per seconds .see, i multiply the (rps) by (number of steps per revolution) (200 or 3200) and i get the steps per second i need. so i can deal with 200 steps per revolution. however if i want high steps per second (more than 1200) the motor doesn’t move (although i use 200 steps per revolution)

i have tried the simple stepper control, however i use along code so at large pulseWidthMicros it is good however when i use small(pulseWidthMicros ) it lags and doesn't work accurately . gives me unreliable speed.

If you can live with a bit noisier motor, you can switch the microstepping to "full step" which means 200steps/rev.

I work very successfully with the AccelStepper library and you can use the lib reliably up to 4000 steps/sec (look at their documentation).

4000 steps/sec would result in 20 rev/sec. If that is too much, then go with 1/2 or 1/4 microswitching which gets the noise a bit down and still delivering good torque.

It seems you started with 3200 steps and 1/16 microstepping, which results in 1 rev/sec. With that microstepping you can go only a little bit faster as you can't exceed the 4000 steps/sec limit.

So reduce the microstepping and you can go faster and have more torque.

Ziad_Ashraf:
i have tried the simple stepper control, however i use along code so at large pulseWidthMicros it is good however when i use small(pulseWidthMicros ) it lags and doesn't work accurately . gives me unreliable speed.

You need to post the code you are actually using.

Also post a link to the datasheet for your motor. Nema23 just defines the physical size of the front face.

What power supply are you using for the motor (volts and amps) ? Higher voltages facilitate higher speeds.

It is helpful to us if you quote a piece of the Reply you are responding to.

...R

thanks Robin2, rpt007 for your response:
i have attached the whole code up there however i will post it again.

Robin2:
You need to post the code you are actually using.

Also post a link to the datasheet for your motor. Nema23 just defines the physical size of the front face.

What power supply are you using for the motor (volts and amps) ? Higher voltages facilitate higher speeds.

It is helpful to us if you quote a piece of the Reply you are responding to.

…R

about the specs of the motor:

Technique specification:

  • Step Angle: 1.8°
  • Current /phase: 2 A
  • Resistance /phase: 1.6Ω
  • Inductance /phase: 2.5 mH
  • Holding Torque: 7Kg.cm (65 N.cm)
  • leads: 6 wires
  • Motor Wight: 0.45 Kg
  • Length: 51 mm

Technique parameters:

Step angle accuracy: +/-5%,(full step,no load)
Resistance accuracy: +/-10%
Inductance accuracy: +/-20%
Temperature rise: 80°C, rated current, 2 phase on
Ambient temperature: -10°C;-+50°C
Insulation resistance: 100MΩMin.,500VDC
Dielectric strength: 500VAC for one minute
Shaft radial play: 0.06Max(450g-load)
Shaft axial play: 0.08Max(450g-load)

#include <Stepper.h>
#include <Keypad.h>
#include <SPI.h> 
#include <LiquidCrystal.h>
#include <AccelStepper.h>

LiquidCrystal lcd(8,9,4,5,6,7); 
///////////////////////////////
//accelstepper
int pinStep = 19;
int pindirection= 18;
int enable=17;
AccelStepper mystepper(1, pinStep, pindirection);
 float steps_per_sec;
 float rps;


 /////////////////////////////////
 
int keypad_pin = A0;
int keypad_value = 0;
int keypad_value_old = 0;
 
char btn_push;
 
byte mainMenuPage = 1;
byte mainMenuPageOld = 1;
byte mainMenuTotal = 2;

//////////////////////////////////////////////////
int Q=0; // volume flow_rate
int V=0; // total volume
float rpm=0; // rpm of stepper motor

char key;
long sum=0;
float ID=0;//tube internal diameter

//const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
//int stepCount = 0;  // number of steps the motor has taken
//Stepper myStepper(stepsPerRevolution, 11, 12, 13, 14);


// for your motor

//void keypad_set_up();
int get_sum();
void Main_Menu_Display();
void main_menu_setup();
void Main_Menu_Btn();
void main_menu_loop();
void Automatic();
void Manual();
char ReadKeypad();
void WaitBtnRelease();

    const byte rows=4;
    const byte cols=4;
    char keys[rows][cols] =
    {
        {'1','2','3','A'},
        {'4','5','6','B'},
        {'7','8','9','C'},
        {'*','0','#','D'}
    };
    byte rowpins[rows] = {32,34,36,38};
    byte colpins[cols] = {24,26,28,30};
Keypad keypad = Keypad(makeKeymap(keys), rowpins, colpins, rows, cols);
int stepper();


 

 void Automatic()
 { 
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter, Tube ID");

   sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for Menu A here
         lcd.setCursor(8,1);
          lcd.print("mm");
        ID=get_sum();  

          
        //***************** هااااااااااااااااااااااام
        //if(int(key)=='C');
        //return ????? ؟
    }
    WaitBtnRelease();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Total Volume");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatoc-->total volume here
         lcd.setCursor(8,1);
           lcd.print("ml");
        
        V=get_sum();

        //***************** 
        //if(int(key)=='C');
        //return ????? 
        
    }
WaitBtnRelease();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Flow_Rate");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatic--> flow_rate here
         lcd.setCursor(8,1);
          lcd.print("ml/min");

        Q=get_sum();
        //*****************
        //if(int(key)=='C');
        //return ?????
//    if (ReadKeypad()=='D')
//    {
//      Q=Q-5;
//    }
//    else if (ReadKeypad()=='U')
//    {
//      Q=Q+5;
//    }
      

      }
          WaitBtnRelease();

          stepper();

 }
 void Manual()
 {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter, Tube ID");

   sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for Manual here
         lcd.setCursor(8,1);
         lcd.print("mm");
        ID=get_sum();  

          
        //***************** هااااااااااااااااااااااام
        //if(int(key)=='C');
        //return ????? امسح الارقام وابدأ من تاني؟
        // ازاي انتقل للبعديها؟
    }
    WaitBtnRelease();
   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Flow_Rate");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatic--> flow_rate here
         lcd.setCursor(8,1);
         lcd.print("ml/min");

        Q=get_sum();
        //*****************
        //if(int(key)=='C');
        //return ?????
//    if (ReadKeypad()=='D')
//    {
//      Q=Q-5;
//    }
//    else if (ReadKeypad()=='U')
//    {
//      Q=Q+5;
//    }
      }
   WaitBtnRelease();

   stepper();
       
}




void Main_Menu_Display()
{
    lcd.clear();
    lcd.setCursor(0,0);
    switch (mainMenuPage)
    {
        case 1:
          lcd.print("1.Automatic");
          break;
        case 2:
          lcd.print("2. Manual");
          break;
   
    }
}
 
void Main_Menu_Btn()
{
    WaitBtnRelease();
    if(btn_push == 'D')
    {
        mainMenuPage++;
        if(mainMenuPage > mainMenuTotal)
          mainMenuPage = 1;
    }
    else if(btn_push == 'U')
    {
        mainMenuPage--;
        if(mainMenuPage == 0)
          mainMenuPage = mainMenuTotal;    
    }
   
    if(mainMenuPage != mainMenuPageOld) //only update display when page change
    {
        Main_Menu_Display();
        mainMenuPageOld = mainMenuPage;
    }
}
 
char ReadKeypad()
{
  /* Keypad button analog Value
  no button pressed 1023
  select  638
  left    407
  down    253
  up      96
  right   0
  */
  keypad_value = analogRead(keypad_pin);
 
  if(keypad_value < 50)
    return 'R';
  else if(keypad_value < 110)
    return 'U';
  else if(keypad_value < 300)
    return 'D';
  else if(keypad_value < 500)
    return 'L';
  else if(keypad_value < 750)
    return 'S';
  else
    return 'N';
 
}
 
void WaitBtnRelease()
{
    while( analogRead(keypad_pin) < 800){}
}


///////////////////////////////////////
//void keypad_set_up()
//{
    // put your setup code here, to run once:
  //  lcd.setCursor(8,1);
   // lcd.print("ml");
//}
//********* check int loop

int get_sum()
{
    // put your main code here, to run repeatedly:
    
    lcd.setCursor(0,1);
  
//    while(keypad.getKey()==0)
    delay(10);
      key=keypad.getKey();
      if(key>47&&key<58)
     // if(key!='A'&&key!='B'&&key!='C'&&key!='D')   
      {
         Serial.println(key);
            sum=sum*10+(key-48);
            
            lcd.print(sum);
            Serial.println(sum);

        }
return sum;
}


int stepper()
{
    rpm=Q/(.009474140097*ID*ID);
    rps=rpm/60;
    steps_per_sec=3200*rps;
// 3200 is the steps per revolution (can be changed according to the microstepping)
          Serial.println(steps_per_sec);

 }
 void setup()
{
  //  pinMode(pinStep, OUTPUT);
   // pinMode(pindirection, OUTPUT);
   // pinMode(enable, OUTPUT);

  stepper;
   digitalWrite(enable,HIGH);
  mystepper.setMaxSpeed(37300);// depends on the max RPM i can have which is 700 RPM
  //mystepper.setSpeed(steps_per_sec);

    lcd.begin(16,2);  //Initialize a 2x16 type LCD
 
    Main_Menu_Display();
    //delay(1000);
    Serial.begin(9600);
      Serial.println("start,,,,,,");


}
void loop()
{
    btn_push = ReadKeypad();
   
    Main_Menu_Btn();

   
    if(btn_push == 'S')//enter selected menu
    {
        WaitBtnRelease();
        switch (mainMenuPage)
        {
            case 1:
              Automatic();
              break;
            case 2:
              Manual();
              break;
       
        }
 
          Main_Menu_Display();
          WaitBtnRelease();
    }
     mystepper.setSpeed(steps_per_sec);

       mystepper.runSpeed();

 
//delay(100);
 
}//--------------- End of loop() loop ---------------------

Ziad_Ashraf:
thanks Robin2, rpt007 for your response:
i have attached the whole code up there however i will post it again.

In Reply #5 you said you had problems when trying my code. That is the code I want you to post - the exact code that you tried.

...R

Robin2:
In Reply #5 you said you had problems when trying my code. That is the code I want you to post - the exact code that you tried.

…R

ok Robin2:
this code does not depend on accelstepper library ,rather depends on controlling the dealyMicroseconds() time between (the high & low)modes of the step pin:
transforming equations are at function [stepper()]
Thanks

#include <Stepper.h>
#include <Keypad.h>
#include <SPI.h> 
#include <LiquidCrystal.h>
#include <AccelStepper.h>

LiquidCrystal lcd(8,9,4,5,6,7); 
///////////////////////////////
//accelstepper
int dirpin = 18;
int steppin = 19;
int enable = 17;
AccelStepper mystepper(1, steppin, dirpin);
// int steps_per_sec;
float inverse_sps;
 float rps;
// float x=0;


 /////////////////////////////////
 
int keypad_pin = A0;
int keypad_value = 0;
int keypad_value_old = 0;
 
char btn_push;
 
byte mainMenuPage = 1;
byte mainMenuPageOld = 1;
byte mainMenuTotal = 2;

//////////////////////////////////////////////////
int Q=0; // volume flow_rate
int V=0; // total volume
float rpm=0; // rpm of stepper motor

char key;
long sum=0;
float ID=0;

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
int stepCount = 0;  // number of steps the motor has taken
//Stepper myStepper(stepsPerRevolution, 11, 12, 13, 14);


// for your motor

//void keypad_set_up();
int get_sum();
void Main_Menu_Display();
void main_menu_setup();
void Main_Menu_Btn();
void main_menu_loop();
void Automatic();
void Manual();
char ReadKeypad();
void WaitBtnRelease();

    const byte rows=4;
    const byte cols=4;
    char keys[rows][cols] =
    {
        {'1','2','3','A'},
        {'4','5','6','B'},
        {'7','8','9','C'},
        {'*','0','#','D'}
    };
    byte rowpins[rows] = {32,34,36,38};
    byte colpins[cols] = {24,26,28,30};
Keypad keypad = Keypad(makeKeymap(keys), rowpins, colpins, rows, cols);
int stepper();


 

 void Automatic()
 { 
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter, Tube ID");

   sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for Menu A here
         lcd.setCursor(8,1);
          lcd.print("mm");
        ID=get_sum();  

          
        //***************** هااااااااااااااااااااااام
        //if(int(key)=='C');
        //return ????? امسح الارقام وابدأ من تاني؟
        // ازاي انتقل للبعديها؟
    }
    WaitBtnRelease();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Total Volume");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatoc-->total volume here
         lcd.setCursor(8,1);
           lcd.print("ml");
        
        V=get_sum();

        //***************** 
        //if(int(key)=='C');
        //return ????? 
     
    }
WaitBtnRelease();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Flow_Rate");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatic--> flow_rate here
         lcd.setCursor(8,1);
          lcd.print("ml/min");

        Q=get_sum();
        //*****************
        //if(int(key)=='C');
        //return ????? 
//    if (ReadKeypad()=='D')
//    {
//      Q=Q-5;
//    }
//    else if (ReadKeypad()=='U')
//    {
//      Q=Q+5;
//    }
      

      }
          WaitBtnRelease();

          stepper();

 }
 void Manual()
 {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter, Tube ID");

   sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for Manual here
         lcd.setCursor(8,1);
         lcd.print("mm");
        ID=get_sum();  

          
        //***************** هااااااااااااااااااااااام
        //if(int(key)=='C');
        //return ????? امسح الارقام وابدأ من تاني؟
        // ازاي انتقل للبعديها؟
    }
    WaitBtnRelease();
   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter,Flow_Rate");
  sum=0;
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for automatic--> flow_rate here
         lcd.setCursor(8,1);
         lcd.print("ml/min");

        Q=get_sum();
        //*****************
        //if(int(key)=='C');
        //return ????? 
//    if (ReadKeypad()=='D')
//    {
//      Q=Q-5;
//    }
//    else if (ReadKeypad()=='U')
//    {
//      Q=Q+5;
//    }
      }
   WaitBtnRelease();

   stepper();
       
}




void Main_Menu_Display()
{
    lcd.clear();
    lcd.setCursor(0,0);
    switch (mainMenuPage)
    {
        case 1:
          lcd.print("1.Automatic");
          break;
        case 2:
          lcd.print("2. Manual");
          break;
   
    }
}
 
void Main_Menu_Btn()
{
    WaitBtnRelease();
    if(btn_push == 'D')
    {
        mainMenuPage++;
        if(mainMenuPage > mainMenuTotal)
          mainMenuPage = 1;
    }
    else if(btn_push == 'U')
    {
        mainMenuPage--;
        if(mainMenuPage == 0)
          mainMenuPage = mainMenuTotal;    
    }
   
    if(mainMenuPage != mainMenuPageOld) //only update display when page change
    {
        Main_Menu_Display();
        mainMenuPageOld = mainMenuPage;
    }
}
 
char ReadKeypad()
{
  /* Keypad button analog Value
  no button pressed 1023
  select  638
  left    407
  down    253
  up      96
  right   0
  */
  keypad_value = analogRead(keypad_pin);
 
  if(keypad_value < 50)
    return 'R';
  else if(keypad_value < 110)
    return 'U';
  else if(keypad_value < 300)
    return 'D';
  else if(keypad_value < 500)
    return 'L';
  else if(keypad_value < 750)
    return 'S';
  else
    return 'N';
 
}
 
void WaitBtnRelease()
{
    while( analogRead(keypad_pin) < 800){}
}


///////////////////////////////////////
//void keypad_set_up()
//{
    // put your setup code here, to run once:
  //  lcd.setCursor(8,1);
   // lcd.print("ml");
//}
//********* check int loop

int get_sum()
{
    // put your main code here, to run repeatedly:
    
    lcd.setCursor(0,1);
  
//    while(keypad.getKey()==0)
    delay(10);
      key=keypad.getKey();
      if(key>47&&key<58)
     // if(key!='A'&&key!='B'&&key!='C'&&key!='D')   
      {
         Serial.println(key);
            sum=sum*10+(key-48);
            
            lcd.print(sum);
            Serial.println(sum);

        }
return sum;
}


int stepper()
{
    rpm=Q/(.009474140097*ID*ID);
    rps=rpm/60;
     inverse_sps=1/((3200*rps)/1000000);  //inverse of steps per second-->steps per sec = 3200*rps
  //   x=inverse_sps;
    // Serial.println(steps_per_sec);


  
 }
 void setup()
{
   pinMode(dirpin, OUTPUT);
  pinMode(steppin, OUTPUT);
  digitalWrite(enable, HIGH);
  digitalWrite(dirpin, HIGH); // Set the direction.
  stepper;
   digitalWrite(enable,HIGH);
 // mystepper.setMaxSpeed(37300);
  //mystepper.setSpeed(steps_per_sec);

    lcd.begin(16,2);  //Initialize a 2x16 type LCD
 
    Main_Menu_Display();
    //delay(1000);
    Serial.begin(9600);
      Serial.println("start,,,,,,");
      

}
void loop()
{
   btn_push = ReadKeypad();
   
    Main_Menu_Btn();

   
    if(btn_push == 'S')//enter selected menu
    {
        WaitBtnRelease();
        switch (mainMenuPage)
        {
            case 1:
              Automatic();
              break;
            case 2:
              Manual();
              break;
       
        }
 
          Main_Menu_Display();
          WaitBtnRelease();
    }

   
    digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates t
     delayMicroseconds(27);
     //delayMicroseconds(inverse_sps/2);
    digitalWrite(steppin, HIGH);
    // delayMicroseconds(inverse_sps/2);
    delayMicroseconds(27); // This delay time is close to top speed for thi
 // particular motor. Any faster the motor stalls.
    

 
//delay(100);
 
}//--------------- End of loop() loop ---------------------

Ziad_Ashraf:
I used the acccelstepper library ,however it says that its reliability is limited to 1000 step per sec .

The version I have says 4000 steps/sec on 16MHz Uno. AccelStepper uses floats so its going to
be fairly limited.

Personally I favour the DDS route to pulse generation as its integer-only and can be very fast,
but its quite complex to get right (avoid over- or under-shoot on moves due to quantization
errors) - you also need to set up a timer to give regular interrupts (upto 50kHz is doable) for
fast stepping.

Basic pseudocode:

long freq = 0 ;
long phase = 0 ;
long steps = 0 ;

ISR TIMER2_OVF_vect ()  // or whatever
{
  long old_phase = phase ;
  phase += freq ;    // update phase accumulator
  if ((phase ^ old_phase) < 0)  // phase changed sign
  {
    digitalWrite (DIRpin, (freq < 0)) ;
    delayMicroseconds (1) ;
    digitalWrite (STEPpin, HIGH) ;
    delayMicroseconds (5) ;
    if (freq < 0)
      steps -- ;
    else
      steps ++ ;
    digitalWrite (STEPpin, LOW) ;
  }
}

void set_freq (long f)
{
  noInterrupts () ;
  freq = f ;
  interrupts () ;
}

long get_steps ()
{
  noInterrupts () ;
  long s = steps ;
  interrupts () ;
  return s ;
}

You call set_freq() to control the step rate and monitor progress by get_steps().
You can add an acceleration variable and add the line

 freq += accel ;

to get acceleration/ramping.
DDS (direct digital synthesis) is more usually used to index a wave-table for generating waveforms
of arbitrary frequency, but a step pulse is just a special case of a waveform.

1 Like

Ziad_Ashraf:
ok Robin2:
this code does not depend on accelstepper library ,rather depends on controlling the dealyMicroseconds() time between (the high & low)modes of the step pin:

I don’t understand why you have #include <Stepper.h> and #include<Accelstepper.h> if you are using neither?

More importantly you have not told us what that code actually does and what you want it to do.

In this piece of code

   digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates t
     delayMicroseconds(27);
     //delayMicroseconds(inverse_sps/2);
    digitalWrite(steppin, HIGH);
    // delayMicroseconds(inverse_sps/2);
    delayMicroseconds(27); // This delay time is close to top speed for thi

you have delayMicroseconds(27) twice for a total of 54.

It seems to me it would be much easier to manage the code with a single delayMicroseconds(54) - like this

   digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates t
    digitalWrite(steppin, HIGH);
    delayMicroseconds(54);

If you really do need very short intervals between steps then it may make more sense to use one of the Timers to produce interrupts at the appropriate intervals and put the step code (without any delay()) in the ISR. Even then there may not be many CPU cycles available for the Arduino to do anything else.

…R

Robin2:
I don’t understand why you have #include <Stepper.h> and #include<Accelstepper.h> if you are using neither?

More importantly you have not told us what that code actually does and what you want it to do.

…R

the code should drive a stepper motor to drive a perstaltic pump.The user should determine the flowrate which i can determine the necessary rpm to give this specific flowrate through some equations.
so i need to control the rpms of the pump. the (delayMicroseconds)is determined through another equation so it is (variable) according to the rpm needed to pump the specific flow-rate.

You did not yet tell us about the microstepping, which you are using.

I set to 3200 step per revolution

That's telling me, you are operating at 1/16th microstepping.
If that is not needed and a noisier stepper is no issue, why don't you follow my advice in reply #6 and go with smaller microstepping?

  • With 3200 steps/rev at 1/16th, you will increase your speed by 16(!) if you go with full steps.
  • With 4000 steps / full step mode and AccelStepper you will get to a maximum speed of:
    4000/3200 x 16 = 20 rev/sec = 1200 RPM.

If that is still too slow, AccelStepper won't help anymore, but up to this point (provided for having implemented a reasonable high voltage power supply) you are fine.

thanks rpt007. last question? if many processes are going in the loop will not this affect the response (ie:the number of steps sent to the motor )will not this cause (delays) and so causes inaccuracy at high rpms which needs large number of steps per second? (ie: high frequency)

Ziad_Ashraf:
the code should drive a stepper motor to drive a perstaltic pump.The user should determine the flowrate which i can determine the necessary rpm to give this specific flowrate through some equations.
so i need to control the rpms of the pump. the (delayMicroseconds)is determined through another equation so it is (variable) according to the rpm needed to pump the specific flow-rate.

This is useful information but it does not answer my question which you quoted
what that code actually does and what you want it to do

Without that info why shouldn't I assume that the code works properly?

...R

thanks rpt007. last question? if many processes are going in the loop will not this affect the response (ie:the number of steps sent to the motor )will not this cause (delays) and so causes inaccuracy at high rpms which needs large number of steps per second? (ie: high frequency)

As long as you don't use any delay() or serial.print() commands in your main loop, you will be fine.
But as you are asking into that direction: what else will have to happen in the main loop?

Pls reply @Robin2's question and then we can analyze if you will be in trouble or not.

Robin2:
This is useful information but it does not answer my question which you quoted
what that code actually does and what you want it to do

Without that info why shouldn’t I assume that the code works properly?

…R

rpt007:
As long as you don’t use any delay() or serial.print() commands in your main loop, you will be fine.
But as you are asking into that direction: what else will have to happen in the main loop?

Pls reply @Robin2’s question and then we can analyze if you will be in trouble or not.

thanks rpt007 & robin 2 :
in the code i made a menu system displayed on the lcd keypad shield which i can move through the lcd keypad buttons[ up/down/left/right/select].I have two options
1 -automatic 2-manual
for the (automatic) the user insert the 3 variables through the (keypad matrix 4*4) of which i can calculate the rpm then the steps per second and send it to the driver & the motor .
So in the loop i call the lcd keypad function ,the menu system function & the keypad function(impeded in another function) then the run.speed() function.
The manual is the same ,however it will be connected to on/off button.