The following is the documentation for the three phase motor controller, an open source project. Our current use case is on the 3 Phase Driver Board with the Quanum MT5206.
The motor controller has:
The servo simulates the 3 sin waves needed to drive a 3-phase motor with a ~31KHz PWM of 3 half-H bridges.
code here
The driver handles the sin wave generation based on a [0-767]
integer.
It also uses an amplitude [0-255]
.
Based on the math of 3 Phase sine generation, one output can be held at ground and the other 2 are the difference between themselves and the low phase. Each of the two non-ground phases are symmetric and therefore can use the same table (aka limitedSinTable).
Amplitude adjusts the output so the motor doesn't go full force. It uses an approximate division by 255.
Currently limit amplitude to 30 or 40 (of 255) because inductive voltage spikes caused by the motor may blow up the FETs and/or FET drivers. More research is necessary to understand why and how to prevent such exposive events.
code here
The 3-phase controller handles injesting predictor data to understand current position and push at a 90° (electrical rotational) angle to current position.
Controller passes along amplitude command to driver.
code here
Recieves the input commands for amplitude, velocity, or positional commands.
- Amplitude passes values along to controller
- Velocity command has a deadband and a step change in amplitude if outside of the deadband
- Positional command uses a PID controller. Sum of P, I, and D terms.
- P value (default: ?) multipled by difference between desired and current position in phase units.
- I (not implemented)
- D value (default: ?) multiplied by velocity in velocity units.
- Distance command resets the rotation counter and sets a position command of current position + distance
For driving the motor we need to know the current angular position. We use a Magnetometer to determine the location at low speeds and with high resosultion. It is possible to use the Back EMF sensing at high speeds.
Since reading occur with some lag and the reading is much slower then uses we must estimate the current location when using the data. This prediction happens in the Predictor.
Using MLX90363 - SOIC8 package - communicating over SPI.
This device allows for 14 bit precision and is updated at a rate of ~1 kHz. Reads from the device happen at ~800 Hz.
Maximum revolutions per second of Turnigy 480 - 1320kv is 262. Given 800 Hz read speed this allows for more then 2 readings per mechanical revolution. This is sufficient to determine positions and velocity at all drivable velocities for Turnigy 480 - 1320kv. However, 800 Hz update rate is insufficant for use as exact position in pwm cycle, therefore we must use a predictor.
NOT YET IMPLEMENTED
Magnetometer has sensor lag and slow reads compared to pwm cycles. Therefore, we must attempt to predict current position and velocity when the controller requests it.
Predictor estimates velocity by having a current estimate (initially 0). Every Magnetometer reading, if the estimate was incorrect shift the estimate by a step (currently 5 velocity units) in the correct direction.