The one you have right now is a current ramping code I believe. Increment current . It's not a PI loop. It sounds like at low RPM, the current was swinging back and forth. A properly tuned PI loop should be much better, but it might take a few tries to find the right P and I for your motor. I'm certain it would be different from mine. Probably smaller P and I values, but I don't know how much smaller.
The third option looks a little like this:
if (pwmDuty > throttlePos) {
pwmDuty--;
}
else if (current > throttlePos) {
pwmDuty--;
}
else if (pwmDuty < throttlePos) {
pwmDuty++;
}
So, you don't get the jerky starts from throttle only being proportional to pwmDuty, since current can't be bigger than throttle either.
|