Several times, (during the smart pin presentation, and here
, for example) questions have been asked about brushless motors and encoders. I think it's time to start a separate thread to bundle them. I think the P2 is an excellent device for motion control and drive applications. It is even powerful enough to control a whole machine so that running a single motor is just a sub-feature that can be handled by a single cog using some smart pins.
First, I'd like to set apart two different applications. All three phase motors are somewhat "brushless" but there are different types and different methods how to control them.
1. Driving fans, pumps, vehicles and so on. Here you only need velocity or torque control ("throttle") and don't care about the exact position of the rotor. There are two sub-cases:
a) Induction motors (squirrel cage) are mainly used in industrial machines. Simpler drives just apply three phase shifted sine waves with a fixed V/f ratio and hope that the motor will follow (and not stall). This is OK for fans or propellers which have little friction. Better drives examine the phase shift between voltage and current (vector control) to measure torque/load and adapt voltage and frequency accordingly. This can still be done sensorless (without encoder, resolver or hall sensors).
b) Permanent magnet or so-called "brushless DC" motors are used in model aircrafts, robots, power drills and similar devices. Because of the permanent magnets in the rotor the commutation of the windings has to fit the current rotor position exactly to generate torque. This is usually done by applying voltage (PWM) to only two of the three motor terminals and axamining the zero crossing of the third and then switching to the next winding pair in the right moment.
2. If you need exact position control and/or torque control near zero speed (for example, for a Segway like vehicle or for an industrial robot, mill or lathe) the sensorless control methods doen't work any longer. You need some sort of position sensor. For an induction motor an incremental encoder would be sufficient because the starting angle of the rotor doesn't matter. However, in applications where weight or size matters permanent motors are used because of their better power density. But now you need some absolute information about the rotor position for commutation.
a) Older or cheap chinese servo drives use hall sensors plus an incremental encoder. Hall sensors (or the equvalent emulated signals from an absolute optical encoder) provide 6 states per electrical revolution or a resolution of 60°. This is enough for a rough guess of the rotor position and can be used for startup. However, to get optimum torque and symetry a more precise position information should be acquired as soon as possible by sampling the next state transition (edge) of the hall signals or an index pulse of the incremental encoder if available. Once you have an exact snapshot of the position you can forget about the hall signals and solely use the incremental signals. The disadvantage of this method is that you need cables and connectors with many wires and pins, up to 14 for differential A/B/Z (incremental quadrature + index) and U/V/W (hall sensor) signals plus power.
b) Resolvers: these are rotating differential transformers which have a primary winding and two secondary windings. A sine or square wave of fixed amplitude and frequency (around ~10V and 10kHz) is applied to the primary winding. The secondary windings output two sine waves with identical phase but an amplitude modulated with sine and cosine of the rotor angle. The original angle can be computed with the arctan function of the relative amplitude ratio of the two secondary signals. Offset, gain and phase errors are cancelled out. Resolvers need only 6 wires and are very robust because the don't need a glass disc or other sensitive components.
c) Modern "state of the art" servo motors have absolute encoders. There are several different methods of how to achieve absolute encoding (parallel gray code, magnetic "compass-like" sensors, incremental encoders with a second nonius track to name a few) but in the end it doesn't matter how they work internally because they can be treated as a black box. They use a serial protocol to transmit the position information digitally. The big advantage is that you only need 4 wires to connect most of them (2 lines for RS485 data and 2 for power) and you don't need a complicated analogue front end as for resolvers.
Incremental encoders usually have resolutions of 500 to 5000 lines per revolutions resulting in 2000 to 20000 quadrature states per revolution. Resolvers and high end absolute encoders can reach 14 to 20 bits (up to ~1 million states) per revolution. And although nobody needs to resolve arc-seconds high resolution helps a lot getting better velocity and acceleration values.
The next questions are: do we need drivers for the P2 supporting brushless motors? What are the most common target applications? Is anybody interested at all? Are stepper motors more important?
I've already written some drivers for different types of encoders and resolvers but I think they are not of much use to anybody except me. But if there are any specific questions of how to connect any of theese sensors to the P2 I think I can help.