Thanks, MazdaMatt!!! I really appreciate all your input. I tested out the controller with a sort of fast, technician's PI loop. Now, in the worst case scenario above, where the wheel is spinning with PWM duty of 100%, and very low current, and instantly stopping the wheel, instead of like 230 iterations to getting current under control, it takes about 7 or 8. And under normal circumstances, it takes 1 or 2 iterations to get current under control.
for (i = 0; i < 8; i++) {
// check current
ADCSRA |= 64;
while (ADCSRA & 64); // Do nothing until the conversion is done.
current = ADCH;
if (current > currentLimit) {
correction = (1 << i);
if (gentleThrottlePos >= correction) {
gentleThrottlePos -= correction;
OCR1AL = gentleThrottlePos;
}
else {
gentleThrottlePos = 0;
OCR1AL = 0;
return;
}
}
else {
return; // Ya! Current is under control.
}
}
So, under all normal circumstances, getting current under control is a matter of dropping gentleThrottlePos by 1 or 2. In a catastrophic situation as described above, gentleThrottle gets dropped by 1, 2, 4, 8, 16, 32, 64, 128. (their sum is 255). At each stage, it checks to see if current has gotten under control. If it is, then it exits out of the loop and moves on.
By the way, I would love to hear some suggestions on good boards that can program in system. Also, suggestions on nice fast 32 bit 16 bit resolution A/D channel stuff.
|