Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create function to control motor speed by RPMs? #64

Open
conn250 opened this issue Jan 1, 2019 · 1 comment
Open

How to create function to control motor speed by RPMs? #64

conn250 opened this issue Jan 1, 2019 · 1 comment

Comments

@conn250
Copy link

conn250 commented Jan 1, 2019

I'm pretty new to stepper motors in general so I probably just don't know the basic principles behind this yet. So currently I just know about the way of controlling the motor via the basic commands to set the STEP_PIN HIGH or LOW with some amount of delay between them. It's not a very easy way to precisely set the speed of the motor. How can I translate those commands into something easier to use like simply inputting an RPM?

digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(10);

I think it would be similar to the step() function in the Arduino Stepper.h library, but that library writes commands to the individual stepper coils. Ideas?

@teemuatlut
Copy link
Owner

If your stepper motor has 200 steps per revolution and you're using 16 microstep setting, you therefore need to send 200 * 16 = 3200 step pulses to make a full rotation.
1rpm = 3200 pulses per minute = 53 pulses per second.
Time between pulses = 1s / 53 = 0.019s.
Note that a step is only executed on the rising edge of the pulse.

For more precise timing of the pulses look into Arduino timers and interrupts.

You can also use AccelStepper to control the pulses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants