Folken said:
Hi Gwhy!
I'm still using your current limiting algorithm. But I never saw any evidence that it actually limits phase current, not just battery current.
If phase current limiting worked, I would see the battery current dropping as speed decreases. But the code accurately maintains the battery current at constant until the motor almost stops (brakes applied or very steep uphill).
I would really like to get the phase current limited to some maximum value. This will limit the maximum torque and prevent slippage of my friction drive.
Can you please explain how your algorithm _should_ work?
Code:
// this line is what sets the maximum phase limit in this case phase current is set for 2 x battery current
phaseMax = Current_pot*2;
// this routine computes the throttle output required it current control is needed
throttleCurrent = max_throttleOut - currentGain*(SensorRT - Current_pot)/100;
// max_throttleOut is the last throttle value sent to the controller
// throttleCurrent now holds the new value of max_throttleOut that may be sent to the controller if battery current needs to be limitied
//-------------------------------------------------------------------------------------------------------------------------------------------
// compute the phase current phase current = shunt current/throttle
phaseCurrent = SensorRT * 1023 /max(max_throttleOut,25); //set last term to be appx 2.5% of throttle max - throttle min
// calculates the approx phase current using last throttle value sent to the controller which was max_throttleOut
//--------------------------------------------------------------------------------------------------------------------------------------------
// this routine computes the throttle output required it phase control is needed
throttlePhase = max_throttleOut - phaseGain*(phaseCurrent - phaseMax)/100;
// max_throttleOut is the last throttle value sent to the controller
// throttlePhase now holds the new value of max_throttleOut that may be sent to the controller if phase current needs to be limitied
throttleCurrent = min(throttleCurrent,throttlePhase); //choose lower value to send to the controller of phase or battery throttle
max_throttleOut = min(Throttle_Pulse,throttleCurrent); // use the lower of current-limited or user requested throttle value
// Now max_throttleOut is the new value that need to be sent to the controller and this value will then be used for the next phase and battery current limits
if the current limiting starts then the throttle value will come down and its this reduced values that gets used to calculate the phase current .
edit:
this line calculates the phase current
phaseCurrent = SensorRT * 1023 /max(max_throttleOut,25);
so lets put some values into it if SensorRT=900 ( lets assume that your set battery limit is 1023) and the last max_throttleOut=1023 ( no limiting and you are at WOT )
then
phase current = 900 // at this point its the same as battery current
but if software starts to limit the battery current then the max_throttleOut will start to drop
i.e
SensorRT=1023 and max_throttleOut=800 ( system limiting )
then
phase current = 1308 // the phase current is rising
if your phase current setting is 2x battery current ( puts the phase current limiting value at 2046 )then max_throttleOut will need to be 512 before the set phase current will have any effect.
you can use programming to make this more dynamic to suit your needs :wink: .
in the extreme if SensorRT=1023 and max_throttleOut=40 ( system limiting ) // nearly at a standstill but throttle request is still WOT
phase current= 26163
I hope I have explained ok
edit2:
you could try using a higher phase current gain value.. this will reduce the max_throttleOut value faster.
or reducing the battery/phase ratio ... lowering the phase current limit
the value 25 in this part.... phaseCurrent = SensorRT * 1023 /max(max_throttleOut,25);
means that the max_throttleOut value will never be 0. it will always be 25 or higher so even if current limiting ( WOT ) and at a standstill there will always be a small throttle signal trying to power the motor this signal still may be enough to give you your max current limit displayed.
what you can do is display the phase current and you should see this value drop when phase limiting is active .. but this dont mean to say that battery current will also drop unless the max_throttleOut value is falling fast enough