I am building an x/y table, and in one direction I have a stepper motor connected to a belt drive (for linear motion in x). For some initial analysis I have my motor completing N steps in both directions, repeatedly, and I simply want to include a timer in my code that prints out the times elapsed when the motor begins and ends rotation in one direction. In other words, get the ti & tf over which the component attached to the belt drive has moved a certain length, which will allow for a calculation of speed.
I want to avoid manual timing to eliminate timing errors. Your help is appreciated.
The code takes care of that for me. For example, it runs the motor 2000 steps in one direction, of course with a defined delay-between-steps. There is a 2-second pause, and it switches direction and repeats. For each time it moves the timing belt, I want a timer running (can be continuous) so I can print out the time when the motor starts and stops (at counts 0 and 2000).
Correct, but is it safe to assume that grabbing the ?t from the code would be a more accurate estimate than human timing? I don't need it to be extremely accurate, yet I don't want the relatively large human error.
EDIT: I guess I am assuming the current flows for pretty much the same amount of time the motor is in motion.
I'm not worried which time-scale to use, as long as I can obtain a conversion.
May I ask you how you would approach this task? The length measurement is no problem, just want accurate timing.
Here is the setup photo, just for a visual. The stepper is in the foreground, and you can see how the system drives the belt and ultimately the linear slider (toward background).
So, if I use millis(), and have the time printed out each start/stop of the code's current delivery, will it be a sufficient estimate of when the motor starts/stops?
If you haven't figured it out, I'm learning C coding (again) while building the table. Thanks for your patience.
Thank you for your reply. I found out earlier millis() alone can do the trick and threw it in my code, similar to what you have above. I appreciate the help!