determine stepper motor frequency

Hi guys,
I know that i can make my motor faster by Minimize my delay between steps like:

            digitalWrite(steppin,LOW);
            digitalWrite(steppin,HIGH);
            delay(50);

but how can I determine the frequency??? :confused:

but how can I determine the frequency???

Count the number of steps in some period of time.

You posted a useless snippet of code. I posted a useful snippet of an answer.

gaggs:
but how can I determine the frequency??? :confused:

If the delay() is measured in millisecs then the frequency in Hz is 1000 / the-delay-value

...R

ok my code is:

const int dirPin = 5;  // Direction
const int stepPin = 2; // Step
int r=0;
int m=0;
// Motor steps per rotation
const int STEPS_PER_REV = 200;
 
void setup() {
  Serial.begin(9600);
  // Setup the pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}
void loop() {
   if(r==1){
  digitalWrite(dirPin,HIGH); 
  
  // Spin motor one rotation slowly
  for(int x = 0; x < STEPS_PER_REV*2; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(1000); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(1000); 
     m=m+1; 
  Serial.println(m);
  }
 
 }
  // Set motor direction clockwise
 if(r==0){
    digitalWrite(dirPin,HIGH); 
  
  // Spin motor one rotation slowly
  for(int x = 0; x < STEPS_PER_REV; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(1000); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(1000); 
  m=m+1;
  Serial.println(m);
  }
  r=1;
 }

 
 // Set motor direction clockwise
  digitalWrite(dirPin,LOW); 
  
  // Spin motor one rotation slowly
  for(int x = 0; x < STEPS_PER_REV*2; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(1000); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(1000);
     m=m-1;
    Serial.println(m); 
  } 

}

The names r and m might mean something to you. They don't mean anything to me.

gaggs:
ok my code is:

And using the suggestion in Reply #2 what do you calculate the frequency to be?

...R

thanks robine2 :slight_smile: and r ,m 2 variables of Security