vedderb / bldc

The VESC motor control firmware
2.1k stars 1.32k forks source link

[Feature] SIN/COS phase error compensation #569

Closed totosolat closed 1 year ago

totosolat commented 1 year ago

Some sin/cos encoders do not provide perfec 90° phase between the two signals.

It is in particular the case of son/cos encoders made of two hall effects sensors placed in front of the rotor magnets. When working with high pole pairs number, very light placement error on the hall effect sensors can induce important electric angle phase error between sin and cos signals.

Perfect encoder would provide 90° phase between the two signals. Assuming we have a rotor angle α and a phase error θ, the encoder will output:

ADC SIN → sin(α)
ADC COS → cos(α+θ) = cos(α)cos(θ) - sin(α)sin(θ)

We can correct the output the following way:

CORRECTED COS : cos(θ) = (cos(α+θ) + sin(α)sin(θ))/cos(α)

This feature has been tested on a motor with 10 pole pairs and an identified phase error of 8 deg electrical, we can see the inpact on FOC control. Without phase error compensation: phase_not_compensated2

With phase error compensation: phasecompensated

Note: I am planning to provide a lisp example to help identify this phase error θ and/or working on automatic SIN/COS calibration to identify all SIN/COS parameters at the same time.