Brushless Motor Direction control

The basic concept is that you're feeding the motor 3 phase AC power with each phase offset by 120 degrees (or 2/3 PI radians). Increase the frequency and the motor spins faster; stop the frequency and the motor stops, etc.

With the L2634 the control is via the IN1, IN2, IN3 inputs. It's basically three half bridges allowing each of the outputs to source or sink current. You have to analogWrite() to the inputs to get your smooth motion; analogWrite(pin, 0) makes the pin sink, analogWrite(pin, 128) is off, analogWrite(pin, 255) is source. So -- going out on a limb here with totally untested code -- for a smooth movement between two poles of the motor:

for (x = 0; x < 2 * M_PI; x += speed) {
  analogWrite(IN1, 128 + 128 * sin(x));
  analogWrite(IN2, 128 + 128 * sin(x + 2/3 * M_PI));
  analogWrite(IN3, 128 + 128 * sin(x + 4/3 * M_PI));
  delay(100);
}

Is that right? My trigonometry is horrible. :disappointed_relieved: