Inline current sensing problem?

Hello all,

I am new to FOC community, so I started my FOC journey by running the example codes that have been provided. When I use the inline current sensing example code, however, I run into some issues. I can get data from serial monitor and plotter, but I do not think this data is correct. My power supply displays the amps supplied to the board so I am able to have a ballpark guess of what the serial monitor should be reading. Unfortunately, they don’t seem to be close. Also, the data was noisy, so I applied a simple filter. I don’t think that would have caused any problems though. Another thing I tried was combining the inline current sensing example code with the voltage control example code so I could see what would happen to the current when the motor was spinning at different speeds given different voltages. Though the current displayed on the serial monitor/plotter only changed a minuscule amount, the current display on the power supply seemed to change much more. Am I thanking about this all wrong? Or have others had a similar problem? Or am I just painfully ignorant :frowning:?

Kindest Regards

1 Like

What hardware are you using?

FOC shield V2.0.3 and a GM4108 gimble motor.

Here is my code and a picture of my setup.

#include <SimpleFOC.h>

// current sensor
// shunt resistor value
// gain value
// pins phase A,B
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
float current_magnitude;

void setup() {
  // initialise the current sensing
  current_sense.init();

  // for SimpleFOCShield v2.01/v2.0.2
  current_sense.gain_b *= -1;
  
  Serial.begin(115200);
  Serial.println("Current sense ready.");
}

void loop() {

     PhaseCurrent_s currents = current_sense.getPhaseCurrents();
    current_magnitude = current_magnitude*.98+.02*current_sense.getDCCurrent();

    Serial.print(currents.a*1000); // milli Amps
    Serial.print("\t");
    Serial.print(currents.b*1000); // milli Amps
    Serial.print("\t");
    Serial.print(currents.c*1000); // milli Amps
    Serial.print("\t");
    Serial.println(current_magnitude*1000); // milli Amps
}

thumbnail_IMG_2447

thumbnail_IMG_2446

Hey @cheeto_von_tweeto,

I am not sure what are you trying to measure using your code, but if you do not enable your l6234 driver circuit all the motor phases will be left open, and you will not measure any current. :slight_smile:
You can at least set pin 8 (enable) to high. You can also set the pins 5,9,6 to LOW. That should connect all the pages to ground and you should see some current passing when you rotate the motor by hand.

You can also look up the current sense amplifier chip you have on the board on the internet. I cannot see very well from the photo which chip is it. Those are the tyo chips next to the shunt resistors (the black components with R010 sign on them.
In my boards I’ve opted for ina240a2 which has the gain of 50. If they have changed the chip, you might need to change the gain value.

1 Like

Hello @Antun_Skuric

Thanks for your reply. I am trying to measure the current magnitude.

I have another code with the same problem that attempts to use current sensing while the motor is running. The motor wouldn’t run if the driver wasn’t working. So unfortunately, I do not think the driver is the problem.

I tried setting the pins to what you suggested and it didn’t seem to be the problem ether.

I have the same chip. So I am using the same gain.

This is what the serial plotter looks like without the signal conditioning. It does not show any noticeable change whether I move the motor by hand or change the voltage given from the power supply. The plotter looks the same when the motor is moving with the other code as well and shows no change when stalling the motor.

I really appreciate you guys trying to help me out with this.
Thanks a ton.
current_wo_motion

i have the same problem with you ,have you ever solved?