What is your DC input? Do you have current sensors on all 3 lines? Try changing this piece of code:
Code:
if (myPI.error_q < -120/*-80*/) { // if it overshot the target by 80, move on to the next one. We don't want overshoot.
MoveToNextPIValues();
}
else if (myPI.error_q > IqRef + 200) { // IqRef is a constant 511. If Iq swung to -200, that's bad. Move on. Iq shouldn't go below zero much.
MoveToNextPIValues();
}
else if (myPI.zeroCrossingIndex == -1 && myPI.iteration > myPI.maxIterationsBeforeZeroCrossing) { // myPI.zeroCrossingIndex == -1 means it hasn't crossed zero yet.
MoveToNextPIValues(); // CONVERGENCE TOO SLOW!!! Move on!
}
else if (myPI.error_q > 120/*80*/ && myPI.zeroCrossingIndex >= 0) { // it already crossed zero, but now is way back up again. This is oscillation. move on!
MoveToNextPIValues();
}
Where it says -120 and 120, change those to -200 and 200. Maybe the noise on your current sensors is higher.
Also, find this piece of code:
Code:
void InitPIStruct() {
myPI.Kp = (long)savedValues.Kp;
myPI.Ki = (long)savedValues.Ki;
myPI.error_d = 0l;
myPI.pwm_d = 0l;
myPI.errorSum_d = 0l;
myPI.error_q = 0l;
myPI.pwm_q = 0l;
myPI.errorSum_q = 0l;
myPI.testFinished = 0;
myPI.testFailed = 0;
myPI.testRunning = 0;
myPI.ratioKpKi = 62; //savedValues2.ratioKpKi;
myPI.zeroCrossingIndex = -1; // initialize to -1.
myPI.iteration = 0; // how many times have you run the PI loop with the same Kp and Ki? This is used in the PI auto loop tuning.
myPI.maxIterationsBeforeZeroCrossing = 20; //20
myPI.previousTestCompletionTime = counter10k;
}
and change myPI.maxIterationsBeforeZeroCrossing to maybe 100. If you can't get the PI loop tuned, nothing is going to work. The goal right now is to just get the test to pass, and then slowly make it more restrictive.