After optimizing current gains, I was unable to run sensored FOC as the PID outputs would saturate. After looking around I think this is because of the qep.ElecTheta parameter. If I output rg1.Out and qep. ElecTheta, ElecTheta should be lagging rg1.Out by just a little. On the scope, it appears that the phase difference between ElecTheta and rg1 continually increases, eventually causing them to be in phase and then once again the phase difference continually increases. The calibration angle is detected using the sequence in the HV sensored FOC (and manually altering it does not affect this phenomenon).
I think this is why the motor can be run in sensorless mode (using the GUI and otherwise) but not in sensored mode. Qep module has been appropriately initialised (pole pairs, encoder lines etc.) Ideas on how to get to the bottom of this and fix it?
PS: The QEP macro is detecting the correct number of encoder lines for each revolution.

