The PI ratio was just a variable that was there for when the "auto" PI test was running. It gave a starting point for how to check a bunch of values. So, if you had the PI ratio be 100, the "run-pi-test" would do:
Kp = 100
Ki =1
Kp = 200
Ki = 2
.....
but it doesn't come into play when you are independently setting Kp and Ki. So, let's say you did this:
pi-ratio 50
kp 1000
ki 10
the variable named "pi-ratio" would still be 50, even though now Kp / Ki = 100.
The rotor time constant can vary a lot from one motor to another. The motor will run horribly if you are way off. It will run OK if you are a little off, and it will run the best if it's perfect. The "run-rotor-test" only works on an unloaded motor. I"ve only ever tested it on a bench with no transmission. If a transmission is hooked up, you man need to change the default commanded Id and Iq in the rotor test function "RunRotorTest" from
IdRefRef = 300
IqRefRef = 300
To something bigger. Those numbers just worked OK for me on a bench with a unloaded motor at maybe 60v or whatever it was I was using for the test.
If you can't get the run-rotor-test to work, you can just try guesses from 5 up to 150 (5mS up to 150mS for the rotor time constant):
rotor-time-constant 5
rotor-time-constant 6
...
rotor-time-constant 150
and see what gives the best acceleration.
Arber, does your ABZ encoder have a single index pulse per mechanical revolution, or is it 4 per mechanical revolution? That's the only difference from motor type 2 to motor type 3. One possibility is your encoder doesn't like one of the settings below:
Code:
case PERMANENT_MAGNET_MOTOR_WITH_ENCODER:
QEICONbits.QEIM = 0b110; // enable QEI x4 mode with position counter reset by INDEX pulse.
QEICONbits.PCDOUT = 1; // Position Counter Direction Status Output Enable (QEI logic controls state of I/O pin)
QEICONbits.POSRES = 1; // Position counter is reset by index pulse.
QEICONbits.SWPAB = savedValues2.swapAB; // don't swap QEA and QEB inputs.
DFLTCONbits.CEID = 1; // Interrupts due to position count errors disabled
DFLTCONbits.QEOUT = 1; // Digital filter outputs enabled. QEA, QEB. 0 means normal pin operation.
DFLTCONbits.QECK = 0b011; // clock prescaler of 16. So, QEA or QEB must be high or low for a time of 16*3 Tcy's.
// Fcy = 30MHz. 3*16Tcy is the minimum pulse width required for QEA or QEB to change from high to low or low to high.
// You can do at most 30,000,000/(3*16) = ??? of those pulses per second. So, you can have at most
// ??? * 2 clock counts per second, since resolution has been multiplied by 2 (QEA and QEB up and down transitions all cause a pulse to be seen by the microcontroller..)
//
DFLTCONbits.IMV = 0b00; // INDEX pulse MUST happen when QEA & QEB is low. It didn't work for QEA being low with the Leaf motor.
MAXCNT = (savedValues2.encoderTicks << 2) - 1; // If going backwards, poscnt will go from 0 to maxcnt, ONLY IF it is caused by an index pulse!!! Multiply by 4 since I"m doing 4* the resolution.
// Use this for the AC controller. It's easier to measure speed of rotor with this setting, if there's no INDEX signal on the encoder.
POSCNT = 15000; // It starts in an unknown state before the index pulse happens. Do this so I can know the index pulse hasn't happened yet. It will vary from 14000 up to 16000 or whatever, and suddenly be forever trapped in [0,MAX_CNT] once the index pulse happens.
myFirstEncoderIndexPulseTest.startTime = 0;
myFirstEncoderIndexPulseTest.currentAngleOffset = 0;
myFirstEncoderIndexPulseTest.testRunning = 1;
// encoderTicksDivPolePairs = __builtin_divsd((long int)savedValues2.encoderTicks,(int)savedValues2.numberOfPolePairs);
break;
I would try changing "DFLTCONbits.IMV = 0b00;" to
"DFLTCONbits.IMV = 0b01;", or DFLTCONbits.IMV = 0b10;, or DFLTCONbits.IMV = 0b11;
Those are the possible required states of A and B, when the index pulse happens, and I don't know what state A and B are in when the index pulse happens on your encoder, so you would just have to try them all. This is why companies pick a specific motor and specific position sensor and just make a specific controller for it. Everybody has their own standards.