I am trying to (accurately) count the number of pulses fed to a stepper motor driver TI DRV8711. This driver "converts" one rising edge, depending on the settings, to a full step or microstep. The MCU I am using to generate those PWM pulses is a Freescale MPC5602D. The pulse frequency is going to be less than 30kHz per stepper motor.
The application I am using this device for is position control with a stepper motor. This requires accurate knowledge of the steps taken (given the stepper motor does not stall).
How are those kind of drivers normally driven? Using a regular GPIO pin that is asserted in a timer interrupt routine or via PWM? I want to avoid cramming the main loop with asserting and deasserting a GPIO pin. (I have to control 5+ stepper motors simultaneously)
Counting the PWM pulses sent to the driver is trivial with a regular GPIO pin.
On the other hand, how is one going to approach the problem of accurately counting the number of PWM pulses? Is this done by feeding the PWM output back to the MCU and using a counter to count the rising edges? I guess I have to decrease the PWM frequency before I reach the desired number of pulses in order to disable the PWM before the last pulse and thus guaranteeing not to "overshoot" the setpoint.