Lowside current sense problem

First of all, thanks to simplefoc, i can easily use bldc to build my own exoskeleton.
I am now use lowside current sense on motor M3508 that is produced by DJI. It works fine under position mode and velocity mode.Howerver, under torque mode, the current graph looks strange.
My understanding is that I can set the current_q value under torque mode, but the graph seems didn’t reach my target (T2). Although it didn’t reach my target on the graph, I do can feel torque is increasing when i increase my target.



T2,in the condition of motor stall

Please can you share which microcontroller are you using and which power driver IC? There are many variables that need to be defined before the low side or any side current sensing works accurately. Also, torque control should work properly prior to velocity and angle.


IR2104 is a power driver IC, it doesn’t have any current sensor IC. In order to measure the current, you will need a current sensor IC and shunt resistor. Please provide the schematics then we might be able to help.


thanks for your reply!
Please excuse me for my poor hardware knowledge.
this is the schematics

Dear @def_abc ,

could you also share your code? If you don’t mind, it would help to find problems.

Did you try tuning of the current-PID?

It looks like you have made a nice design!

Actually,I bought this circuit board online, not designed it.But i am working on designing my board now.Hardware knowledge is really hard for me.hahaha
Here is my code

BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(25, 26, 27, 33);

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

LowsideCurrentSense current_sense = LowsideCurrentSense(0.005,10, 34, 35, 32);
void setup()





driver.voltage_power_supply = 22;



motor.voltage_sensor_align = 0.5;

motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

motor.torque_controller = TorqueControlType::foc_current;

motor.controller = MotionControlType::torque;

motor.P_angle.P = 7.0;

motor.P_angle.limit = 50;

motor.LPF_angle.Tf = 0.08;

motor.PID_velocity.P = 0.2; //

motor.PID_velocity.I = 0;

motor.PID_velocity.limit = 40;

motor.LPF_velocity.Tf = 0.08;

motor.PID_current_q.P = 0.4;

motor.PID_current_q.I = 0;

motor.LPF_current_q.Tf = 0.08;

motor.PID_current_q.limit = motor.voltage_limit;

motor.PID_current_d.P = 0.4;

motor.PID_current_d.I = 0;

motor.LPF_current_d.Tf = 0.08;

motor.PID_current_d.limit = motor.voltage_limit;

// Limits

motor.velocity_limit = 100;

motor.voltage_limit = 12;

motor.current_limit = 3;

motor.voltage_sensor_align = 1;


// comment out if not needed


// initialise motor



current_sense.skip_align = true;

current_sense.gain_a *= -1;

current_sense.gain_b *= -1;

current_sense.gain_c *= -1;


// align encoder and start FOC


// set the inital target value

motor.target = 0;

// define the motor id

command.add(‘M’, onMotor, (char *)“motor”);

command.add(‘T’, doTarget, (char *)“target”);

command.add(‘A’, mode_select, (char *)“mode”);

Serial.println(“Motor ready,Current Control Low_side Mode.”);



Have you tried to tune these values? If you say the current never meets your target, you might try raising the P value slightly?

Strangely, I can still use speed mode and position mode。

In terms of gains for the current loop(s), I’ve had good success using small gains for P, and large one for I. Try something like P = 1, and I = 100 for both the q and d current loops.

thanks ,i will try it.