How-to
Driving Step and Direction Inputs From a Controller Velocity Output
Short answer
A step drive counts edges, so the velocity number must become a timed train: pulses per second equal steps per degree times degrees per second, the demand's sign drives the direction pin, and the drive's documented minimum pulse width and maximum input frequency decide whether the generator can deliver it. Command travel as target minus start position, never by integrating velocity.
On this page
A velocity output and a step input do not speak the same language: one is a signed number in engineering units per second, the other counts edges on a 5 V line. Never wire the number to the pin. Convert the demand's magnitude into a timed pulse train with pulses per second = steps per degree × degrees per second, drive the direction pin from the demand's sign, and take commanded travel from target position minus start position. Two datasheet numbers gate the design: the drive's minimum pulse width and its maximum input frequency. The worked example below scales a 90 °/s joint command to 1,500 pulses per second and shows the margin.
What the step and direction inputs actually accept #
A step and direction drive does not read levels, it counts edges. One pulse on the step input advances the motor by exactly one step, or one microstep when the drive is set to microstep; the level on the direction input selects the sense of rotation; the signals are 5 V TTL. A 1.8° motor therefore turns one revolution per 200 pulses in full-step mode. The drive's disable input is separate: wire it to the controller's enable and fault logic, because simply ending the pulse train stops the motor where it stands rather than decelerating it.
Scale the velocity demand into a pulse frequency #
The bridge between the two interfaces is one factor, k, the pulse density of the driven axis, in pulses per degree:
k = (full steps per rev × microsteps per full step × motor revs per axis rev) / 360
Full steps per rev is 360 divided by the step angle, which gives 200 for a 1.8° motor. This is the same scaling work that setting a gear ratio for degree moves on a rotary axis performs for a pulse-commanded servo axis, done here from the velocity side.
Calculated example, valid for these inputs only: a 1.8° motor at 10 microsteps per full step, a 3:1 reduction from motor to joint.
- Pulses per motor rev = 200 × 10 = 2,000 pulses/rev
- Pulses per joint rev = 2,000 × 3 = 6,000 pulses/rev
- k = 6,000 / 360 = 16.67 pulses per degree
- Commanded joint speed 90 °/s, so f = 16.67 × 90 = 1,500 pulses per second
- Cross-check: 90 °/s of joint is 0.75 motor rev/s, and 0.75 × 2,000 = 1,500 pulses/s
- Motor speed check: 1,500 × 60 / 2,000 = 45 rpm, ordinary stepper territory
Check the timing before choosing the generator #
Pulse width comes first. At 1,500 pulses per second the period is 1 / 1,500 = 666.7 µs, and a 50% duty train presents 333 µs per half-cycle. Read the minimum pulse width from the datasheet of your exact drive and compare: if it documents 2.5 µs (an illustrative input, not a rating), the margin is 333 / 2.5 ≈ 133 times. When frequency rises until the half-period approaches the documented minimum, the drive starts dropping steps.
Generator capability decides the architecture. A controller task that writes an output pin can change that pin once per cycle at best, and each pulse needs a rising and a falling edge. A 1 ms cyclic task therefore caps the train at 500 pulses per second; a 500 µs task caps it at 1,000. The example needs 1,500. The decision follows: generate the train with a hardware timer or PWM peripheral, a dedicated pulse-output module, or a drive that accepts the command natively over the network. Software bit-banging fails this example before timing is even measured.
Direction timing is the last gate. Set the direction level while the train is stopped and hold it for the whole move; the level must be stable around every step edge, and any stop lasting a task cycle or more clears the setup times drives document.
Command travel from position, not from velocity #
A single velocity sample carries speed, not distance, so the degrees to move cannot be recovered from it. Commanded travel = target position − start position; retain both in the axis logic wherever the drive block exposes only a velocity output. Pulses to issue = travel × k. For a 45° move: 45 × 16.67 = 750 pulses, which at 1,500 pulses per second is 0.5 s of train. Reconstructing travel by integrating the velocity output instead would accumulate every scaling, saturation and jitter error, while the position command is exact. Stop the train on pulse count or on closed position error, never on a velocity-derived estimate.
Close the loop where the feedback lands #
The drive executes pulses with no knowledge of load position, so the loop exists only where the controller compares actual position against commanded position and trims the train accordingly; an encoder by itself does not make a stepper closed loop, and how small an error the loop can resolve comes down to choosing encoder resolution to match a stepper's step response. Feed the scaled encoder value into the controller's position input. Commission with one short, slow move and confirm the actual position walks toward the target: a swapped direction or encoder sign makes the error grow instead of shrink and can drive the joint into its mechanical limit.
Commissioning sequence #
- Record from the datasheets: step angle, microstep setting, minimum pulse width, direction setup time, maximum input frequency.
- Compute k, the pulse frequency at maximum commanded speed, and the pulse count of the longest move.
- Compare that frequency against the drive's maximum and the generator's capability; if either falls short, coarsen the microstepping or change the generator.
- Wire step, direction and disable with a common ground reference, and verify the levels at the drive terminals before connecting the motor.
- Command a short, slow move with the mechanism clear of its end stops.
- Confirm rotation sense and encoder sign, and that the pulse count divided by k equals the measured travel in degrees.
- Raise speed in steps, checking position error after each move for dropped steps.
- Accept the axis only when the commanded-versus-actual error after a move stays inside the tolerance the application sets.
Questions asked
How fast can software toggle a step output?
One output change per task cycle is the ceiling, and a full pulse needs a rising and a falling edge, so a 1 ms task tops out near 500 pulses per second and a 500 µs task near 1,000. Above that, generate the train with a hardware timer, a dedicated pulse-output module, or a drive that takes the command over the network. Task jitter eats into even those figures.
What if the drive's maximum step frequency is below the rate I calculated?
Divide the drive's documented maximum input frequency by your pulses per degree; the result is the joint speed ceiling in degrees per second. With 16.67 pulses per degree, every 16.67 pulses per second of limit buys one degree per second of joint speed. If the ceiling is too low, coarser microstepping raises it, at the cost of smoothness and positioning resolution.
Can direction be changed while pulses are running?
Bring the velocity command through zero, let the train stop fully, change the direction level, then restart pulses. The direction line must be stable around every step edge; a change coincident with a step can be latched the wrong way and add or lose a step at each reversal. A stop of even one task cycle is normally far longer than the setup time a drive documents.
Does encoder feedback make the stepper closed loop?
Only on the controller side. The drive still executes whatever pulses arrive, with no knowledge of load position; the loop exists where the controller compares commanded against actual position and trims the train. An encoder on the motor by itself does not close it, and the feedback resolution sets the smallest error the loop can act on.