I am trying to run two stepper motor at same time with different RPM. I decided to use two rotary encoder for change the RPM separately.
But, I am in problem with driving stepper at same time due to the delay time of the step pulse.
How can I generate separate(different duty cycle) step pulses for stepper motors? It's the main problem that I faced.
I have used some Arduino libraries and all of that library has same system for step pulse generation. But, I couldn't understand those well.
void AH_EasyDriver::setSpeedRPM(long RPM)
{
float DIV = RPM*this->MOTOR_RESOLUTION;
this->STEP_DELAY = 60000000.0L/DIV;
}
This function calculate the step time for given specific RPM
void AH_EasyDriver::move(int NUMBER_OF_STEPS)
{
while(STEPS > 0) {
if (micros() - this->LAST_STEP_TIME >= this->STEP_DELAY) {
this->LAST_STEP_TIME = micros();
STEPS--;
stepMotor();
}
}
}
This function rotate the motor the motor in STEP_DELAY using stepMotor() function.
void AH_EasyDriver::stepMotor()
{
digitalWrite(this->STEP_pin, HIGH);
delayMicroseconds(100);
digitalWrite(this->STEP_pin, LOW);
delayMicroseconds(100);
}
This function makes CONSTANT step pulses.
I removed some lines in the function. This is the link for original .cpp file. All of stepper controlling libraries has this functions. I couldn't understand how this functions can change the RPM. Can someone explain this?