Stepper motor cogging in angle mode

I’m trying to get a stepper motor running in constant angle mode.

I had this running quite well with a BLDC motor and the FOC shield. I would rotate the motor by hand and then it would return to a set position.

When I try to do this with a stepper motor controlled via 4PWM on an L298N stepper driver it does work a little but when I rotate it more than say 5 degrees it cogs over and does not return to the original set angle.

I’m using the AS5147U in it’s encoder mode where it outputs 4096 pulses per revolution.

I’m trying to replicate the behavior of the FOC stepper motor example in the docs and youtube video, seem like in the youTube video the motor can be rotated by hand in constant angle mode and doesn’t look to have the cogging problem.

Any ideas about what could be the problem here?

Hey Charles,

So in my experience I was not able te really solve the cogging issue completely without doing the full FOC control (measuring and controlling the current).
However you should be able to have an ok opération even without the full FOC.

In my example I’ve used an encoder rather than a magnetic sensor and maybe that’s the issue.
It’s very very very important to get the alignment between the motor axis and the magnet right. As steppers have lots of poles they are very sensitive to eccentricity of the sensor. So I’d suggest you to either go to encodes or to send a bit more time on aligning the magnet. Yeah I know it’s not really fun :slight_smile:

I’ve done an initial implementation of the alnticogging/eccentricity compensation for steppers, by extending the code from the SimpleFOC drivers repo but it’s still not ready for merging. :slight_smile: