My config:
Windows 11
Arduino UNO
simpleFOC shield V2.03
AMT 103 2048 PPR
BGN\M4108-130T
The code below is my attempt to make a simple motor speed control. It initializes and syncs the motor and encoder, but then it just moves about a quarter turn and stops.What needs to change to keep it rotating at a selected speed?
As a side comment, you can achieve what you’re doing with the counter in the main loop also by setting:
motor.motion_downsample = 25;
then you don’t need the check in the loop and can just call:
motor.loopFOC();
motor.move();
In terms of the actual problem, I think the pole pair number is a good bet for what may be wrong.
Another potential problem could be the high PPR count of the encoder - at 2048 PPR in quadrature mode that’s 8196 interrupts per revolution that the UNO has to handle. If it gets overloaded and starts to miss interrupts, the measured position will drift compared to the real one, and you will lose control of the motor (because the electrical zero will be wrong).
I turned off quadrature mode to reduce the interrupts to 2048 and still don’t get the expected movement.
Here is the current code. What else might be wrong?
Despite it looking to me like the motor has 12 poles, I set it to 11 and now it does the expected rotation.
It also requires the encoder quadrature mode to be OFF. With those two changes, it works as expected. Thanks for the help!
Yeah, it looks to me like the motor has 24 electro-magnets on the stator, but the pole-pairs is the number of permanent magnets on the rotor, divided by two.
That’s something to look into… I think we actually have some code examples for encoders in the examples directory that use the AMT 103. Perhaps it’s a CPR/PPR confusion and the correct setting is 512 PPR in quadrature? Or maybe it’s just that the 8196 really was too much for the Arduino at the speed you were testing.
I just tried 512 with quadrature ON and it just vibrates uncontrollable. 2048 and quadrature off seems to be the right solution.
I have a sparkfun Teensy adapter that will allow me to use a Teensy 3.2 and the simpleFOC shield. When it arrives, I will try the 2048 and quadrature ON combination.