Using FOC Software
Synchronous motors have turned out only to be well drivable when their stator current is controlled by means of a feedback current loop. Due to this, the existing feed forward control used for induction motors could not be extended for use with synchronous motors. Therefor the well known field oriented control approach was implemented in a separate software.
Here is a video manual, created by Johannes Hubner and Damien Maguire, which describes process of setting up FOC-operated system from the very beginning: https://youtu.be/1SlL6cEoRBgv It is strongly recommended to watch it carefully. (also available with chapters: https://youtu.be/tirDQJ6iH28 ).
Note by eightdot and giplt, about the table at time 40:00 : We think that 2 of the 4 combinations will work (you will just find the wrong 'dip' first, see the part about adding 32768 below), the other 2 should also work by xoring pinswap with 2.
Field oriented control is only implemented for permanent magnet motors. Moreover it is optimized for IPM motors (interior permanent magnet). So it will not drive BLDC motors in an efficient manner. It will yield no movement at all with induction motors.
Since the absolute rotor position is a key factor with synchronous motors, said software requires an absolute position feedback device. This can be a resolver or a sin/cos chip MLX91204 or MLX90380 on top of a small magnet. Resolvers will need a so-called excitation. That is a high frequency (4.4kHz in our case) sine wave. Only V3 main boards generate this excitation signal. sin/cos chips do not need excitation and can also be run with V2 main boards.
Most of Damiens Toyota Designs implement V3 main board circuitry.
So to sum up
- IPM (Interior Permanent Magnet Synchronous Motor)
- Resolver or sin/cos chip
- V3 Mainboard
The rev3 mainboard requires sin and cos resolver/encoder inputs between 0 and 3.3V, centred around 1.65V. The Melexis MLX91204 encoder chip linked above unfortunately does not operate on 3.3V, and requires 5V, and it outputs 0.5-4.5V (centred around 2.5V). This is easy enough to 'fix' by using a simple resistor potential divider, but it can be difficult to arrive at a strong signal centred on 1.65V. The openinverter software will cope with a small offset, but to improve encoder performance, a new parameter 'sincosofs' has been introduced (committed on 23rd Feb, no new releases since then as yet). To set this, slowly turn the motor while measuring the voltage from the encoder (after your resistor divider). Note down min and max voltages (these should be between, but as close as possible, to 0V and 3.3V) and calculate the average (min voltage + max voltage, divide by two). This gives your signal midpoint. To convert to digits, divide this by 3.3, then multiply by 4096. Enter your result as sincosofs, and save parameters.
With the MLX90380 running on 3.3V this offset won't be necessary.
First of all you need to flash your board with preferable the latest FOC version (stm32_foc.bin or hex). It will identify itself with the version value of "X.YY.R-foc". Version 4.97.R is the last one that supports switching from Run mode to Manual Run mode! Silly Johannes keeps forgetting to fix this. So temporarily switch to 4.97.R.
If not using a pretuned kit (like Leaf dropin board) do the usual current and voltage calibration. Be aware that polarity is important. So if current flows from the IGBT to the motor the reading must be positive. Therefor it is possible to set negative gain. When setting negative gain ocurlim must be negative also.
Find out the number of stator pole pairs. Resolver polepairs are either the same as stator pole pairs or 1. sin/cos is always respolepairs=1. Set "encmode" to "Resolver" or "sin/cos", respectively. Set syncadv=10.
It is important that the PWM channels line up with the current sensors. So current sensor "il1" must sense the phase generated by "PWM1", same for il2. You don't need to hardware-swap anything since we have parameter "pinswap". For example on some inverters current sensors are on phases 1 and 3. (next software revision) has the entry "PWMOutput23" in pinswap. That will essentially make PWM channel 3 responsible for phase 2 and PWM channel 2 becomes phase 3.
Next step is to find out your motors "syncofs". That is the offset between what the resolver reports as 0° and what actually is 0° alignment between the stator and the rotor magnetic field. To do this, a test mode has been implemented. First start your inverter with the "start" input, then switch to manual mode with the corresponding button on the web interface. Warning: manual mode does not implement any rotor speed limit! When used carelessly you might overspeed your motor to the point were it looses structural integrity - it explodes. So have means to brake your motor externally e.g. by doing this tuning with an already mounted motor and jacked up wheels. Then you can use your cars friction brakes. If the motor doesn't spin at all during the process but you hear the PWM whine and il1 and il2 show current flowing, try swapping 2 of the motor phases over. or swap the resolver inputs (xor pinswap with 2)
- Go into manual mode -> start input, then button on web interface. Select forward direction.
- Observe value "angle" and turn rotor by hand -> you should see angle changes between 0 to 360°. If not, check resolver connection and excitation signal.
- Start with syncofs=0
- enter a positive value for "manualid". Start low, with respect to motor rating. E.g. 5% of rated current
- Keep increasing the value until you notice that the motor starts to spin - make sure you hear PWM going
- If motor spins, change syncofs in 1000 digit increments until it stops spinning. If you need to go below 0, like -1000 enter 64536 (=65536-1000)
- If manualid is less than about max_motor_current/2 go back to 4. When approaching rated_motor_current/2 make your increments/decrements smaller, like down to 300 digits
- You have found 1 of 2 possible offsets. Now you can enter a small value for "manualiq" and set "manualid" to 0.1, the motor should spin smooth in both directions
- If it behaves differently in forward and reverse, add 32768 to syncofs. If the resulting value is > 65535, subtract 32768 instead (or do modulo addition in the first place)
Congratulations, the most difficult step is done. The default values or curkp and curki can usually stay untouched, I don't know a good tuning procedure anyway. It are dependent on the motor inductance and higher values can yield higher stability. Next set up the "throtcur" parameter. It defines how many motor amps are produced per % of throttle travel.
Internally, this is split into a so-called direct and a quadrature current by means of the "Most Torque Per Amp" algorithm (MTPA). MTPA usually needs setup for the motor that your working with. You can customize the two parameters lqminusld and fluxlinkage, ideally with the real values of your motor. Otherwise keep fluxlinkage at its default, start with lqminusld=1 and slowly raise it until you get best acceleration.
SPM motors (magnets mounted outside the rotor) need lqminusld set to 0.