You could also use PWM to control the average voltage to the windings (which for a slow-moving motor controls the current
OK). You'd need to try something like 2 to 8kHz PWM frequency I think. And there are 4 different PWM signals needed
depending on phase although some H-bridges allow PWM on the enable input which means only one PWM signal per H-bridge.
The control loop is then something like:
phase += phase_step ; // phase_step == 0x400 would give 1/16th microstepping for instance
quadrant = phase >> 14 ; // get top two bits of phase
if (quadrant != old_quadrant)
{
// maybe adjust variables/pins to allow controlling the appropriate PWM pins from the sine and cosine values
old_quadrant = quadrant ;
}
analogWrite (pwm_sine_pin [quadrant], sinetable [(phase >> 8) & 0x3F]) ; // lookup sine
analogWrite (pwm_cosine_pin [quadrant], sinetable [0x40 - ((phase >> 8) & 0x3F)]) ; // lookup cosine
(So you can use table lookup in a small table of sines to get the analogWrite values, and use table
lookup to choose which PWM pins for the quadrant - there may be other house keeping like changing
direction of each H-bridge, etc)
For high performance stepper motor applications the chopper-method described by previous poster
is used which also allows running from a high voltage supply (which allows back EMF to be overcome
at higher rotation speeds).