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!