Closed-loop Control Issues with AS5600

Hello! I am currently trying to control the velocity of a T-Motor GB2208 with an Arduino and a SimpleFOC Mini driver. I am also using an AS5600 magnetic encoder. It’s like the kind on the small white PCB you can get on Amazon. When I run the SimpleFOC open-loop velocity control example code, the motor works great, but when I change to the closed-loop control with a PID controller, it doesn’t. Instead of moving at some set velocity, it holds its position. It’s not dead, it’s applying torque to the motor, but not only is it not rotating, but it’s not letting me rotate it. It does the same thing in the Torque control example; however, instead of just applying a constant torque to hold its position, regardless of the value I set to the motor as it does in velocity control, it actually reflects what I set the voltage to be. For example, it’s way harder to move it out of its position when I set the voltage to 6 than when I set it to 2. There clearly seems to be something going on with the encoder, but I don’t know what. When I ran the SimpleFOC as5600 example code, it read accurate values. It does, however, hit a minimum twice in a 360-degree rotation for some reason, which means the direction is not always accurate. Here’s the serial port I got when it initialized:

MOT: Init

MOT: Enable driver.

MOT: Align sensor.

MOT: sensor_direction==CW

MOT: PP check: fail - estimated pp: 23.41

MOT: Zero elec. angle: 4.33

MOT: No current sense.

MOT: Ready.

Obviously, the pole pair count is not 23.41, it’s supposed to be 6 for this motor, so that’s another reason why I think something’s wrong with the encoder, but again I have no idea what, because it gives good values in the example code. How should I go about fixing this?

Hi @MaxMakes , welcome to SimpleFOC!

First question:

Is the DIR pin tied to either GND or VCC?

Second question:

are you confident the magnet is the correct diametrically magnetized type? The white boards from AliExpress or Amazon are often delivered with the wrong magnet (axial instead of diametrically magnetized).
In that case the sensor often kinda works when you turn it by hand, but utterly fails when the motor is moving by itself.

Third question:

Is the power configuration correct (3.3V vs 5V) - the sensor can do either, but the electrical connections are a bit different for each (see Datasheet)

Oh and you have the pole pairs wrong - this motor is 12N14P according to the website, so it has 7 pole pairs