# Question on Lying to FOC controller



## cmcnall (Aug 12, 2015)

I would love someone familiar with FOC theory to weigh in on this thought i have.

If you have a FOC controller in an EV and you falsely turn the gain on the phase current sensors down will it try and drive the motor harder? or will it freakout.

AFAIK it measures the voltage in the legs for timing PWM signals and moving the motor forward(speed) but it measures the current in the legs to determine how much power it is delivering. If you somehow turned the gain on the current sensor down the voltage on the legs shouldn't change I would imagine but the controller would believe that it is not delivering as much current to the motor.
Therefore you could trick the controller to believe that it is driving the motor at 50kw instead of the 100kw it is really supplying. Your battery current meter would still know what is really going on.

I could be completely wrong on this assumption though.

thoughts?
Thanks.

If you are wondering why, it would be to eek a little more power out of the current leaf inverter/controller.


----------



## CKidder (Dec 12, 2009)

cmcnall said:


> I would love someone familiar with FOC theory to weigh in on this thought i have.
> 
> If you have a FOC controller in an EV and you falsely turn the gain on the phase current sensors down will it try and drive the motor harder? or will it freakout.
> 
> ...


Hmmm... Interesting idea... In FOC the three phase currents are measured to find the direct and quadrature currents. The ratio of these is based upon the differences between the three phase currents. Causing the currents to be reported lower than they really are would not change the Id, Iq values except to scale them both. That is, so long as you scale all currents by the exact same amount. It is the Id/Iq values that the FOC algorithm needs. You wouldn't be changing the way the motor position is calculated so the scaled currents would still yield coherence and sensible values for the Id/Iq currents and everything should still be OK. Voltage measurements are kind of secondary in FOC. You don't really *need* to measure the voltage to do FOC. The chief reason for voltage measuring is to figure out when to go into field weakening. When the back EMF reaches the forward voltage you have to counter it with weakening so you need to know the voltage to figure that out. But, voltage is not otherwise part of the FOC calculation.

You're right, this would cause it to think that less power is going to the motor. That in turn causes it to believe that less torque is being produced and so the PID loops will try to increase the PWM output to ramp the torque up to where it wants it to be. At that point you will actually have more torque than requested just as you wanted. 

Now, there are various problems with this. For one, you cannot go past a maximum duty sine wave so there comes a point where it will want to increase the power but there is no headroom to do so. At this point the controller will be going full bore in terms of power. This in turn will really heat the controller up. You're potentially asking for trouble with thermal overload. Depending on what else you're using it might also confuse some devices as they see current higher than what they're expecting. You'd need to be sure your wiring can handle it, that you have proper fuses, etc. Also, there's no telling if they've got other limiting circuitry that might freak out if a higher than expected power is detected. 

But, I suppose there's only one way to know for sure.


----------



## cmcnall (Aug 12, 2015)

"But, I suppose there's only one way to know for sure."

Exactly! I think i'll start lurking copart for a trashed leaf(my wife would get a little upset if i started taking hers apart!)

The biggest issue is that usually the current sensors are 2.5v for zero current so a standard voltage divider won't work. But it would be much better to have a microcontroller that looked at the actual current and adjusted the gain not to exceed the IGBT limit.

just playing in the leaf today it took a second or two for it to ramp to full current. the better question is if that ramp is hard coded for current increase per second(could fool) or rpm/second(harder to fool)

Thanks for the reply.


----------



## bigmouse (Sep 28, 2008)

cmcnall said:


> The biggest issue is that usually the current sensors are 2.5v for zero current so a standard voltage divider won't work. But it would be much better to have a microcontroller that looked at the actual current and adjusted the gain not to exceed the IGBT limit.
> 
> just playing in the leaf today it took a second or two for it to ramp to full current. the better question is if that ramp is hard coded for current increase per second(could fool) or rpm/second(harder to fool)


Not all current sensors are ratiometric about Vin/2 like you describe (your 2.5V assumes a 5V supply). Toyota uses a sensor centered on about 5V with an output that swings negative at full scale.

In any case, you can divide the voltage with resistors and still keep it centered on 5V. Just make a "T" with the resistors. The middle of the "T" goes to the output of the sensor, one leg goes to ground, the other leg goes to the supply voltage (5V in your assumption). The analysis on this isn't too hard, you can figure out the expression for attenuation pretty easily, then select resistor values to give you what you want.

The throttle ramp rate is likely hard coded in the inverter. Though depending on where the throttle pedal signal gets converted to a torque command, you may be able to intercept it. If the inverter reads the pedal directly, you're probably out of luck. If the pedal is read by some ECU in the car which then sends a torque command to the inverter, you might have a chance (if you're willing to reverse engineer the communications).


----------



## MPaulHolmes (Feb 23, 2008)

You bet you can fool it. For example, I always use Lem Hass current sensors. If you stick in a 50amp sensor, it will have way less torque than if you stick in a 500amp sensor, but all the FOC works exactly the same. IT's just that when it thinks it's doing 1 amp, it's really doing 10. It just scales everything.


----------



## cmcnall (Aug 12, 2015)

Does anyone know what current sensors the leaf has mounted between motor and inverter? It seems like a swap might be feasible. I looked in the service manual and the leaf cuts current back when the igbt gets too hot. I wonder what the failure mode of overdriving the IGBTs are. Shoot-through would be the least preferred.


----------

