# BLDC motor and encoder alignment with FOC

Hello everyone!

I am trying to make my own FOC driver, and after tunning the current regulator it came time to make the motor angle actually align with the encoder (in my case it is an absolute encoder). I came up with two methods, which are:

1. Fixed Current Method :
• This method involves setting the current to a fixed value and then adjusting the angle to find the smoothest rotation and lowest current consumption whilst maintaining speed or increasing it.
• The idea behind this method is that the angle difference that results in the smoothest rotation and lowest current consumption is likely the optimal angle difference between the encoder and the motor.
• This method is focused on optimizing the motorâ€™s efficiency and performance, as the smoothest rotation and lowest current consumption indicate the best alignment between the encoder and the motor.
1. Torque Measurement Method :
• In this method, you installed a 3D printed arm of known length and measured the weight with a sale so therefore the torque output of the motor (with some good old math) at different angles of difference between the encoder and the motor.
• The goal of this method is to directly measure the torque output of the motor at different angle differences and find the angle that results in the maximum torque output.
• This method is more focused on directly measuring the motorâ€™s torque characteristics and finding the angle difference that maximizes the torque output.

My problem is that I got two different answers. The first method gave me a value of 6 degrees for for â€śpositive currentâ€ť and -2 for â€śnegative currentâ€ť. And the torque-based method gave me a value of 2.5 degrees in both directions.

My question is, which one is correct? Is there a more widely spread method for doing this?

Is that in electrical degrees or physical degrees? And how many pole pairs is your motor?

These values are close enough together that it makes sense. Different methods (and even different trials of the same method) will have some variationâ€¦ perhaps the best approach is to take the average of all of them.

Both your methods are a little bit involved to run. Both have validity. Running the motor at a fixed speed without load will tend to take field weakening effects into account - i think maybe thatâ€™s where you get the difference between forward or backward direction in the current measurement method.

SimpleFOC uses a different method: by setting a known D/Q angle at one of the â€śsnap pointsâ€ť we observe the measured sensor angle and hence have our electrical zero. The method is simple and works pretty well on many different motors, but there are always some exceptions.

Another method I have used is to run the motor slowly in open loop velocity mode, and track the sensor positions corresponding to the open loop electrical angle zero positions. In this way I can run it forward and backward and take the average of all the electrical zeros over several revolutionsâ€¦

1 Like

Physical degrees. And the motor is 22 pole pairs.

This looks interesting. Maybe as an init_motor functionâ€¦ I will try. I am curious though, how can this not work? What are the exceptions for this method?

22 poles / 11 pole pairs? That would be a common configurationâ€¦

Then the 8 physical degrees difference is 88 electrical degrees, thatâ€™s not so goodâ€¦
But if you take the average of the two youâ€™re pretty close to the other resultâ€¦

The failure modes are of three main types:

1. The motor runs in open loop during alignment, so you have to choose a voltage limit for this. If you choose it too low, the motor doesnâ€™t move well/enough during alignment and results are bad. If the motor has high friction, cogging torque or is loaded during alignment then it can also affect the result, especially in combination with too low voltage.

2. Some motors have very low phase resistance and itâ€™s more or less impossible to run them open loop without burning something. Then the alignment voltage has to be set so low it doesnâ€™t work right.

3. Some motors have very low friction and low pole counts. For a 1-pole pair motor the â€śsnapping actionâ€ť during alignment can move the motor by a large amount. If the motor also has low friction and high rotor inertia then it can oscillate around the snap point by quite a lot, rather than settling quickly. Then you get a bad result.

Hi,

Does SimpleFOC with D/Q angle change the value of moter?