03-23-2009, 01:50 PM
|
#621 (permalink)
|
PaulH
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832
Thanks: 1,362
Thanked 1,202 Times in 765 Posts
|
OK I'm back from my final today! I did some thinking and programming on paper! ya! Good idea Matt!
New control loop:
// iFeedback should be in 0 to 128, since that's all the resolution I have!
// Make sure iRef (from GetThrottlePos()) is also in the range 0 to 128,
// so you would need an extra step of shifting it. how annoying. maybe fix that.
// You want pwmDuty to be in 0 to 255.
// iFeedback in [0,128]
// iError in [0,128]
// pwmDuty in [0,255]
// iSum in [0,255]
// K1 in [0,1]
// K2 in [0,1]
// Start with K2 = 0.
//
void SetCurrent(void) {
iSum = 0;
do {
iFeedback = GetCurrent();
iError = iRef - iFeedback;
pwmDuty = K1*iErr + iSum;
OCR1A = pwmDuty;
iSum += K2*iErr;
if (iSum < 0)
iSum = 0;
} while (iFeedback != iRef);
}
void SetThrottle(void) {
iRef = GetThrottlePos();
GetTemperature();
//////////////////////////////////////////
// limit iRef based on temperature here //
//////////////////////////////////////////
SetCurrent(); // Sets the current to iRef.
}
That makes a lot of sense (throttle proportional to current only). I was just thinking that if there was a failure of the hall effect current sensor, that I would lose control of the car, and I don't know how failure proof those things are. But that wouldn't matter, would it?
Let's say you have a failure of the current sensor. It fails, being stuck reading an erroneous 499 amps. The PI loop would go forever (never exiting), and pwm duty would be driven to 0%, right, desperately (do computers get desperate?) trying to make the current drop. In that case, the car stops. So what! That's fine.
Now let's say you have a failure of the current sensor where it's stuck reading an erroneous 0 amps. Then if the throttle is even at 1%, the loop will drive the PWM duty all the way to 100%, trying desperately (hehe) to get the current to be 1% of 499 amps. This would be bad. But if the throttle was 0%, then the car would stop. OK. I think that's an acceptable risk. If the current sensor fails, just remove foot from gas pedal. Not catastrophic.
Now I need to tune the PI loop, to find the just right K1 and K2 values in the range of 0 to 1. Hey, I get to use fixed point math! I used to do that when making video games on my piece of crap 386 computer! ya!
|
|
|
Today
|
|
|
Other popular topics in this forum...
|
|
|
03-23-2009, 02:05 PM
|
#622 (permalink)
|
Master EcoModder
Join Date: Jun 2008
Location: London, Ontario
Posts: 1,096
Thanks: 0
Thanked 17 Times in 14 Posts
|
Paul, you sly devil... you're getting good at this stuff!
Second fail case - Hall stuck at 0. If you are already moving and the hall is stuck at 0, then it will try to push up the current. Then you realize th ings are bad and you drop throttle. Throttle and current will both be 0, so the PWM will NOT CHANGE from where it is! So yes, you ARE going to be rocktting down the road strapped to an electric death machine. I recommend a simple "if throttle = 0, kill it", but that might be harsh on the electronics.
Use excel to choose your values for you. Decide your settling time and overshoot this way. There is, unfortunately, an unknown variable which makes this a little more tricky than it looks. The rate of change of current with respect to PWM duty is NOT constant. At higher rpm, the rate of change of current with respect to pwm duty is lower than it is at low RPM. A properly designed state space version of this controller would alleviate that and you'd get good response across the board.
Be sure to run that calculation on a timer interrupt! You do not want to do this in the main loop.
|
|
|
03-23-2009, 02:09 PM
|
#623 (permalink)
|
Master EcoModder
Join Date: Jun 2008
Location: London, Ontario
Posts: 1,096
Thanks: 0
Thanked 17 Times in 14 Posts
|
Wait a tick... i just noticed that it is all happening in a while loop. Don't do that. Use static variables and just keep calling the function at a standard interval like 0.5ms or something... maybe faster if you can.
|
|
|
03-23-2009, 02:22 PM
|
#624 (permalink)
|
EV test pilot
Join Date: Jan 2008
Location: Oconomowoc, WI, USA
Posts: 4,435
Thanks: 17
Thanked 663 Times in 388 Posts
|
Quote:
Originally Posted by MazdaMatt
you ARE going to be rocktting down the road strapped to an electric death machine.
|
That's it.
I AM buying that parachute for my car...
|
|
|
03-23-2009, 02:24 PM
|
#625 (permalink)
|
Master EcoModder
Join Date: Jun 2008
Location: London, Ontario
Posts: 1,096
Thanks: 0
Thanked 17 Times in 14 Posts
|
Good luck, ben
|
|
|
03-23-2009, 02:38 PM
|
#626 (permalink)
|
PaulH
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832
Thanks: 1,362
Thanked 1,202 Times in 765 Posts
|
Quote:
Originally Posted by MazdaMatt
Throttle and current will both be 0, so the PWM will NOT CHANGE from where it is!
...
I recommend a simple "if throttle = 0, kill it", but that might be harsh on the electronics.
|
Yikes, good point. I didn't catch that. But instead of rebooting the computer from a coding error, we have to reboot Ben. haha! CLEAR! ZAP!!! haha! Just kidding Ben. It will be very safe when I ship it to you, but you will have that emergency disconnect nearby, right?
Excellent idea about excel! Thanks!
|
|
|
03-23-2009, 02:38 PM
|
#627 (permalink)
|
EcoModding Lurker
Join Date: Feb 2009
Location: rochester ny
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
Just wanted to Say hi and Congratulate everyone on their excellent work. I have been a long time lurker on this thread and I am very impressed with what you guys have been able to accomplish. Keep up the good work and I will be putting my order in for a pre milled power section if you offer them!
-Copertop
|
|
|
03-23-2009, 03:20 PM
|
#628 (permalink)
|
MAD Modder
Join Date: May 2008
Location: NorCal
Posts: 70
Thanks: 0
Thanked 3 Times in 3 Posts
|
Quote:
Originally Posted by MPaulHolmes
Yikes, good point. I didn't catch that. But instead of rebooting the computer from a coding error, we have to reboot Ben. haha! CLEAR! ZAP!!! haha! Just kidding Ben. It will be very safe when I ship it to you, but you will have that emergency disconnect nearby, right?
Excellent idea about excel! Thanks!
|
Is he going to use something like this?
Plasma Boy Racing Photos :: Emergency Disconnect!
Should be easy to build and handle plenty of amps (pun intended?)
Looks amazing, must read from 3-4 pages back and get caught up, a lot happened this weekend while I was out of town
|
|
|
03-23-2009, 06:08 PM
|
#629 (permalink)
|
EcoModding Apprentice
Join Date: Sep 2008
Location: Upstate NY
Posts: 190
Thanks: 0
Thanked 5 Times in 3 Posts
|
Just curious, this controller is capable of 144 volts and 500 amps for a total of 72 kw's? If that's the case that's incredibly impressive amount of capacity. More then capable of driving a vehicle with large electric motors for greater acceleration.
I was also wondering which program you were using as your C++ editor?
__________________
http://benw385.vox.com/
'Blog' on the open source electric motorcycle project.
Please come visit and comment!
|
|
|
03-23-2009, 06:56 PM
|
#630 (permalink)
|
EV test pilot
Join Date: Jan 2008
Location: Oconomowoc, WI, USA
Posts: 4,435
Thanks: 17
Thanked 663 Times in 388 Posts
|
Quote:
Originally Posted by Blue Bomber Man
this controller is capable of 144 volts and 500 amps for a total of 72 kw's?
|
yep.
That comes pretty close to 100 ELECTRIC HP.
You DO know how much better electric horsepowers are than gasoline horsepowers, right?
Dang, I DO gotta instal the parachute!
|
|
|
|