0
\$\begingroup\$

I'm building a device that have to move in orders of thousandths of mm per minute. I've got suitable stepper motor and driver, it is working correctly but I'm unable to figure out the formula needed to calculate delay between steps to get to proper speed. I have Nextion display connected to an Arduino, that sends the speed (in mm/min), but I just can't figure out how to calculate the delays. I've measured following:

  • 1 step = 0.000004767mm
  • Driver is set to 1/6400 resolution

I have two end switches that will trigger interrupt once it reached end/start, so no worries about length. I also need the delay to be in us (microseconds). So far I've tried (0.000004676 / speed)x60000000. It seems to be OK in 0.0x range but when I go lower, it just doesn't work properly. Thanks for replies.

EDIT: So the formula seems correct, but I don't get why 0.01mm/min is pretty much perfectly accurate and 0.009mm/min is done in 28s.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm, did you check your specifications on the stepper motor and driver? You might want to add what exactly is "doesn't work properly" so we can help. (ex. over-current, stutters, etc?) \$\endgroup\$
    – Natsu Kage
    Jan 28, 2020 at 13:27
  • \$\begingroup\$ There is a limit for floats and ints, maybe you have to move to doubles and longs and/or change your units to help the microcontroller. Post some code so some of us can take a look \$\endgroup\$
    – Wesley Lee
    Jan 28, 2020 at 13:29

1 Answer 1

0
\$\begingroup\$

From Arduino Wiki:

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.

So doing math using floats with numbers like 0.000004767 and 60000000 is not gonna work with the standard float implementation in Arduino.

The easiest solution within Arduino is probably switching to integers and longs and use nanometers and nanoseconds as integers or use floats with micrometers and microseconds (then check if the variables are large enough to store the whole length if you need it, etc).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.