View Single Post
Old 07-23-2009, 01:36 AM   #2066 (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
I don't think the problem is lack of resolution. The problem is that it's perfectly fine (according to the throttle-power scenario) at zero rpm for the current to go to 500 if the duty is very small, since all that matters is the product of current and duty. There would be no reason in the throttle proportional to power scenario to keep one extreme from happening when the other is the opposite (huge current, tiny pwmDuty or tiny current, huge pwmDuty for tiny throttle). It wouldn't know to make current smaller, since the product would be small.

TEMPERATURE IDEA: How nonlinear are your thermistors? Maybe you could use 2 lookup tables. Make an array of maybe 63 entries (for example). One, 'R', would contain the resistances, and the other, 'T', would contain the corresponding temperatures. The 63 entries would contain the resistances for T1 through T63, where T1 would be the lowest (room temp?) and T63 would be the highest temp resistance ( for 120 degC???). T0 would be a waste since this algorithm would never reach R[0]. hehe.

Then, you could do a binary search:

i = 32;
delta = 16;

while (delta >= 1) {
if (measuredResistance < R[i]) {
i += delta;
}
else if (measuredResistance > R[i]) {
i -= delta;
}
else break;
delta >>= 1;
}
// Now, you know the approximate resistance, so get the corresponding temperature!
measuredTemp = T[i];
// So, you need a lookup table for the resistances, and for the temperatures
////////////////////////////////////////////////////////////////////////////////////
That should give you an accuracy of +/- 2 degC or so. It would be really really fast too. At most 6 if..thens.
__________________
kits and boards
  Reply With Quote