I'm working on a project in C++ with a stepper motor moving a platform back and forth. I need to be able to change the motor's speed and measure the exact distance the motor (and stage) has travelled. Currently, I can successfully step the motor and change the speed by changing the frequency of the PWM while keeping it at a constant 50% duty cycle, but I can't seem to find an accurate way to measure the distance travelled.
Prior to implementing PWM, I kept count of the number of steps since the motor was permanently set at 32 micro steps and thus kept a fixed step-distance, and this method was highly reproducible and accurate. However, now that PWM is constantly changing the stepping frequency this method isn't applicable anymore.
Does anyone have any ideas on how to overcome this? Thanks in advance!