View Single Post
Old 05-25-2009, 01:34 AM   #1386 (permalink)
MPaulHolmes
PaulH
 
MPaulHolmes's Avatar
 
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,368
Thanked 1,202 Times in 765 Posts
Kp = 1/4 and Ki = 1/8 give VERY VERY VERY good results on flat ground and on hills for driving with a 6.7" diameter 60 pound motor. It's the best I've had. Yesterday, I was using Ki = 100 or 500 or something ridiculous like that. Needless to say, that caused problems. I was using huge Ki values because a website suggested large Ki values, but that was for a very different situation where they were trying to control the RPM on a tiny motor.

It's optimized for speed, so a little hard to understand.
Here's the code piece (in case like a moron I erase it on accident again):
//////////////////////////////////////////////////////////////////////////////////
errorNew = _throttlePos - _current;
pwmDutyFine += (((int32_t)(errorNew - errorOld)) << 13) + (int32_t)(errorOld << 2);
errorOld = errorNew;
pwmDuty = (int16_t)(pwmDutyFine >> 15);
///////////////////////////////////////////////////////////////////////////////////
The whole thing takes 15 uS, whereas a single floating point multiply takes about 100 microseconds.

EDIT: The multiply isn't as slow as I thought. Oh dang it! I might be able to improve that time a bit. I'm going to try something.
__________________
kits and boards

Last edited by MPaulHolmes; 05-25-2009 at 02:01 AM..
  Reply With Quote