Wondering if the code has been tested with a 0.9 degree stepper. I’m unable to get closed loop working with a L298. I think i’ve swapped all the motor input wires and encoder wires at least 20 times. Not sure what else to try. Open loop velocity works fine but closed velocity loop just doesn’t seem to keep trying, there is some movement but then it just pulses IN1 and IN3, IN2/4 have no signal.
The one thing i wonder about, I have my encoder attached to the stepper shaft via a belt, and since the encoder shaft is 6mm and i don’t happen to have any gt2 pullies with a 6mm id I’m using a 1/4" (6.35mm) shaft and it wobbles. I’ve tried to pull the belt much tighter by hand but it didn’t make a difference for closed loop velocity. I would have thought a high P would just try harder but maybe this doesn’t work for a stepper.
Now in terms of pulley. Since the stepper that you have has 100 pole pairs (if I calculated well) then the precision of the encoder is much much more important than for example 10 pole pairs gimbal motor. For 10 pole pair a 60 impulse encoder is enough to run FOC, but for 100pp stepper you need at least 400 impulses.
The number of pole pairs is very important, make sure to put it in right. So it should be number of steps per revolution/4. You can test this by running the open loop position mode. If you set the 6.28 rad position (2pi) and if your pp number is correct the motor should do a full rotation.
Also any misalignment of the encoder will cause it to fail, so if your pulley is 6.36/6 ration this will cause an error for sure.
I swapped a 200 step stepper and I was able to get it to work. My encoder is 600ppr and I guess that isn’t enough resolution for a 400 step stepper. I don’t think the belt was the issue, the 200 step stepper was just hand held for belt tension.
Taking a break, i spent an hour and a half trying to get a blue pill working but I haven’t messed with one since the new stm32 core and i couldn’t even get the serial working.
I have some magnetic encoders but they are not supported. I may take a stab at implementing them. The first is als31313 and the other is a mlx90393.