How to calculate stepper motor RPM?

Hi, i want to calculate the rpm of my stepper motor as a beginner. delay in microseconds is 3500. using nema 23 stepper motor with 200 steps per revolution (1.8 degree). plz guide me & suggest me the formula to calculate the exact rpm. more how to calculate pulse rate or peulse frequency
thanks in advance

void Nema(void *pvParameters){  
   //Nema pins
    pinMode (pulPin, OUTPUT); // set Pin9 as PUL
    pinMode (dirPin, OUTPUT); // set Pin8 as DIR
    digitalWrite (dirPin, LOW); // set high level direction
  while(1){  
 
 //nema speed control
 int delayValue = 3500; // in microseconds

  digitalWrite (pulPin, HIGH);
  delayMicroseconds (delayValue);
  digitalWrite (pulPin, LOW);
  delayMicroseconds (delayValue);

  }  

.....maybe 1 rev every 22 minutes...?
Could be way out...oh...microseconds....:confounded:

How hard can it be?

For your program, 30 million divided by delayValue divided by 200.

RPM = 30000000UL / delayValue / 200:
Serial.println(RPM);

To calculate the stepper speed, divide the step angle by 360, multiply by the pulse frequency, then multiply by 60?

Thanks @timothylove . i have already used that formula and it gives me 42.8 RPM theoritically. but manually , RPM is 2.1

there is a large difference between RPM when calculating theoretically and manually.

Thanks @JCA34F . kindly elaborate it

1 step takes 2*3.5msec = 7msec.
200 steps takes 1.4 sec
RPM is 60 sec/1,4sec = 42.8

where is the rest of your code? what hardware are yoiu using?

like this?
https://www.amazon.co.uk/nema-23-stepper-motor/s?k=nema+23+stepper+motor

I would imagine youre microstepping at 1/8th steps. If youre seeing that difference between expected and actual RPM values... Can you elaborate more on your code and circuit/driver setup?
Have you confirmed the current has been regulated appropriately for your motor/system?

Ah, now, what driver are you using? Is it a microstepping driver and if so how have you set the microstep pins?

Or even more... Also, your sketch abruptly starts so the stepper may be having acceleration problems, what sort of noise is it making?

Your step period is 7000 micros (3500 HIGH + 3500 LOW), a minute is 60 million micros, 60000000 / 7000 = 8571.42857143 steps per minute, / 200 steps per revolution = 42.8571428571 revolutions per minute (RPM). It's just elementary school arithmetic.

Because your program is taking a LOT more time than the snippet you have shown.

Thanks for your kind response @JBornstein90 @johnerrington @jhaine .
https://www.omc-stepperonline.com/support/can-you-send-me-a-schematic-that-how-to-wire-the-stepper-driver-to-an-arduino
I am following the above connection diagram. using DM542T stepper driver. steps per revolution are set to 200 (default) and the set current is 1.9A max. step delay is 5 milliseconds as shown in the code.


// Vacuum Motor 
#define RPWM 5
#define LPWM 6
int Vacuumspeed = 150;

// Nema 23 
#define pulPin 9
#define dirPin 8
//int delayValue = 3500; // in microseconds
unsigned long previous_NemaTime = 0;
long NemaDelay = 5; // in milliseconds

void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600);

  // Vacuum 
    pinMode(RPWM, OUTPUT);
    pinMode(LPWM, OUTPUT);
    analogWrite(LPWM, 0);

  //Nema 
    pinMode (pulPin, OUTPUT); // set Pin9 as PUL
    pinMode (dirPin, OUTPUT); // set Pin8 as DIR
    digitalWrite (dirPin, LOW); // set high level direction
    


}

void loop() {
  // put your main code here, to run repeatedly:
   //vacuum speed  
  analogWrite(RPWM, Vacuumspeed);

 //nema speed 
  digitalWrite (pulPin, LOW);
  unsigned long current_NemaTime = millis();
  if(current_NemaTime - previous_NemaTime >= NemaDelay) {
   digitalWrite (pulPin, HIGH);
   previous_NemaTime = current_NemaTime;
  }
  

  //delay(500); 


}                                   

I have analyzed the pulse signal (pin no 9 of Arduino Uno) in a proteus which showed the time period is 5ms. but the motor is not rotating with 60 RPM as calculated theoretically. There is also negligible load on Nema 23. I have also tested the motor providing 4.5A max current but still the same problem. Motor moves at about 8 RPM calculated manually.

A couple of points. First, the DM542 has opto isolated inputs which is good but I can't recall what the drive current is (i.e. what the series resistor to the LED is) - hopefully the Arduino digital outputs will have enough grunt. I don't think you said what Arduino you are using - it does have 5v logic levels I suppose?

Second, in your loop() you write a high after 5ms to pulPin but then it almost immediately gets set low next time round the loop - the resulting pulse length may be too short to reliably trigger the driver. You want something like 2.5ms high then 2.5ms low so pulses repeat at 500Hz.

Why make it so complicated?

Use

 digitalWrite (pulPin, LOW);
 delay(NemaDelay);
   digitalWrite (pulPin, HIGH);
   delay(NemaDelay);
  }

and perhaps try a longer delay?

@johnerrington Thanks. Actually i am trying to do multitasking with arduino uno. i wrote this not to disturb motor step delay while execution.

I suggest you get it working before you make it more complicated

Can i ask you to try a different approach on the motor logic, and let me know the results?

digitalWrite(pulpin, HIGH);
delaymicros(20); // this is the step pulse, the value 20 worked well for my needs 
digitalWrite(pulpin, LOW);
delaymicros(500); // change this value only for RPM adjustment

Does this help improve your step speed?