I have a for loop that governs the rotation of a stepper motor. I was wondering if there was a way to output the time it takes for the motor to complete whatever rotation I set. Essentially, is there a way to calculate RPM?
Thanks
I have a for loop that governs the rotation of a stepper motor. I was wondering if there was a way to output the time it takes for the motor to complete whatever rotation I set. Essentially, is there a way to calculate RPM?
Thanks
Print millis() at the start then print mills() after the finish.
You could subtract one from the other then do a print.
Although the act of printing slows down the loop. It is a simplistic way of controlling a stepping motor speed. You need a better way. Something like a timer driven interrupt call.
LarryD:
Print millis() at the start then print mills() after the finish.You could subtract one from the other then do a print.
I'm new to Arduino, so bear with me.
How would I go about doing this? Declare a few variables, set x=mills at the beginning, then y=mills at the end, then z=y-x? print z?
Grumpy_Mike:
Although the act of printing slows down the loop. It is a simplistic way of controlling a stepping motor speed. You need a better way. Something like a timer driven interrupt call.
Could you explain to me what you mean by that? My guess is that I set the motor to run and have it break after a certain amount of time has passed?
unsigned int x;
void setup()
{
Some code.
}
void loop()
{
Some code.
x=millis();
Your code you are measuring.
serial.Println(millis()-x);
Etc.
Mr. Gammon has a function you might be interested in using to do timing.
.
LarryD:
unsigned int x;void setup()
{
Some code.
}void loop()
{
Some code.
x=millis();
Your code you are measuring.
serial.Println(millis()-x);
Etc.
LarryD:
Mr. Gammon has a function you might be interested in using to do timing.
Gammon Forum : Electronics : Microprocessors : Timer library (ProfileTimer) - times code on the Arduino.
Thanks! I'll give both of these a try.
kin101:
My guess is that I set the motor to run and have it break after a certain amount of time has passed?
A stepping motor will only move when you send it a pulse. You can not set it going. What you are trying to do is silly because the act of measuring disturbes what you are trying to measure.
kin101:
I have a for loop that governs the rotation of a stepper motor. I was wondering if there was a way to output the time it takes for the motor to complete whatever rotation I set. Essentially, is there a way to calculate RPM?
I wonder if you are trying to figure out a way to CONTROL the stepper speed? Your description, and the replies to it is about MEASURING the speed?
Have a look at this simple stepper code. The value of millisBetweenSteps governs the speed of the motor. The second example (which does not use delay() ) is the one to use - the first example is just for demos.
...R
Stepper Motor Basics
Even with the 'delay' of using millis you're still getting an accurate enough representation of RPM...
It might slow down the loop, but it still times the loop.