PID TUNING ISSUE: Current Loop Gains for B-G431B-ESC1 inverter boards

Hello Everyone,

I’m new to this and I’ve tried to search the community forums for an answer but I I didn’t come across any threads that were helpful to my issue.

My issue:

I am trying to control the speed of my PM-SMPM motor (24V, 10 pole pairs, 96Kv, Rs 1.7, Ls 1.15, 2300 max speed, 15A max A) using the B-G431B-ESC1 inverter board and the simpleFOC library. I have an MT6701 (1024PPR) used for speed feedback as a quadrature encoder.

There are 2 nested loops. The outer speed loop and the inner torque/current loop. Initially, I assumed I would just run with default values for the torque loop and focus on fine-tuning the speed loop. Zero’ed the gains for the speed PID, starting only with the P and progressed from there. Very difficult to control. Had to stop.

I suspected that perhaps the inner loop was the cause. So I decided to focus on that. At first, i thought the default values for current loops that came with the simpleFOC library may be wrong, so I decided to use MC Workbench (input all parameters) and have it auto-calculate the PID gains for current loops Q & D and applied those instead.

Neither worked.

Now without going into the details of all my trials, I thought perhaps I can get some guidance on this from the community. How does one tune the PID gains of the current D & Q loops of this inverter board ? Do you even do that or just run with default values. I saw a few posts on how to tune PID of speed or position loops but nothing about the current loops.

I am using simpleFOC Webcontroller as an interface to change the relevant PID values and set the correct control loop configuration to test.

Before fine-tuning, I need to test the torque/current loop alone, I would select as Motion Control: Torque, and Torque Mode: FOC Current.

Then what are the proper steps to take? Set currentQ Target to 1A ? 0.2 A? What am I monitoring ? Phase voltage Q ? I see it oscillate … but how much is too much ? from looking at the actual motor, it is not spinning smoothly at all … so that’s a dead giveaway ? What should I expect ?

Furthermore, the FOC Current has two PIDs current Q and current D … is it better to run DC Current mode first and fine time currentQ alone … and then switch to FOC Current, keeping the same PID values for currentQ and then start adjusting currentD ? Use the same current PID values for both?

Any and all help is appreciated. The more detailed the better, please keep in mind I’m a novice.


I’ve been able to get SimpleFOC working in current mode for a few types of motors using the B-G431. Before going into the parameters for the current loops gains, can I ask if you’ve been able to control the motor in voltage mode? Does the motor produce torque given a voltage target in the move() function? Does the encoder return proper values?


Hello @wrcman555 ,

Thanks for responding. Yes I have tried it several times in torque/voltage mode … I tried it without any engine parameter input (except pole pairs = 10) and then I tried it with the addition of phase resistance and subsequently even added the Kv and L(H), …

I would set the target to 0 to begin with and then slowly increase it to in 0.01 small increments … and at around 0.15 the motor would start to move and jumps to a speed of about 7 rad/sec and from there I would increase it to 0.2 and reach 10 rad/sec … but in both cases it is by no means stable … oscillating by a good measure of +/- 30% from target and increases over a short time until it becomes unstable and flatlines …

I don’t know what is wrong. Sensor is aligned. Sensor reads perfectly well. It’s an MT6701 (1024PPR).

I dialed in the phase resistance as supplied by manufacturer and even did my own measurements, KV was also provided.