ADC is clipping, current measurments are wrong

My Iq and Id are always extremly hight values.
10mOhm shunt with INA240A2 (gain of 50V/V):

InlineCurrentSense current_sense0  = InlineCurrentSense(0.01f, 50.0f, 39, 36, _NC);

Using the following to check the current sense values:

PhaseCurrent_s currents0 = current_sense0.getPhaseCurrents();
Serial.print(currents0.a*1000);
Serial.print(currents0.b*1000);

The power supply is showing at most 750mA while the plot is showing clipping past 3A (you can easily stop the motor by hand, it’s not 3A):


I’ve tried adding analogSetAttenuation(ADC_11db); in the code but i see no difference.

I’m pretty sure my current sense is setup properly, verified with a constant current source from 1A down to 0A:

How does SimpleFOC decide on the gains? Why is it being so aggressive?

HI there,

What kind of motor do you have?

The saturation actually looks ok its around ±3A which is more or less ±1.5V (for the 3.3V logic).
Are you running your motor in the open loop?
What is the phase resistance of your motor?

It is eniterely possible that you have 3A on the motor and that you can stop it by hand, it really depens on your motor.

Also the power supply current is not equal to the phase current. The power is conserved (voltage*current) rather than the current magnitude (roughly).

So if you have a 20V power supply and you read 750mA. When you set 5V volatge to your motor you should read 20*0.7/5 = 3A. This is just an example though.

So it seems to me that this is likely a combination of the physical saturation of your current sensing and a high motor current.

Hi @Antun_Skuric,
Thanks for the input.
Here are is what i’m using:

MKS FOC DUAL PLUS v3.3 with INA240A2
AS5600 I2C 400kHz (waiting for MT6835 to arrive)
750KV WYE 0.22Ohms (0.182Ohms 4 wire measurement) 0,031mH motors.

I’m using 12V and I’m seeing your point (V limit is 3V). I guess it’s time to pull out the scope.
I was using closed loop Velocity in voltage mode. Estimated current kind of works but FOC current the motor just shakes and squeals a lot. The PSU is current limited to 4A and it clamps at 4A.

Well at least i understand now why the current sense initialization was failing with all currents same magnitude!, the ADC was clipping.

(i have touched something and the WebController is not connecting again, i’m getting initialization errors… will try again later)

Thanks!

Any news on this?

We have already had a couple of users that tried to use these boards and have had issues with the current sensing circuit design. Even though the board is capable of outputting 10+ Amps it is not capable of measuring more than 4A.

You would need to change the shunt resistors to a smaller value to allow measuring a larger range.

It is really a pity that they’ve done it this way.

So it you use voltage or estimated current control you do not use the current sensing circuit and you can use the full potential of the board. If you use the foc current control mode you will be limited to 4 amps.

And for your motor, 4 amps is not much.

Hi @Antun_Skuric,

There has been progress (just been busy and repairing my GPU that blew up xD)!

I’ve had to set the motor0.current_limit to 0.25A for initialization and before i start the the main loopFOC I set the limit to 4A. I seem to get consistent results now.

The motor now runs in FOC modes without going crazy. Still tuning the velocity, position and current loops again as i keep getting either vibrations or commands that don’t even send much current to the motors. I’m not sure if the vibrations are an AS5600 issue…
I may get some smaller shunt resistors or place some in parallel.

It does move around with 4A tho…

AS5600 will always vibrate a little bit. 14-bit is much better, and the 21-bit MT6835 is awesome.

Need to assemble the parts, but I’ve improved the magnet centering on the motor and decreased the distance between the encoder and motor. Added some extra room for ventilation too as at 4A they do get quite toasty and I’m worried about the longer term stability with PLA xD

… finding M2 screws for the encoder is gonna be a bit of a pain tho.

Well… that sure is a difference in performance and loop speed. From a loop time of under 2kHz to nearly 7kHz… I’m going to redo all the filters and parameters again because now instead of oscillations that would shake it to bits it’s now a squeal xD