Hello,
My goal is to create a torque controller that performs well at speeds close to 0 rpm using a high pole count motor and a high resolution incremental encoder. I have been working my way through the InstaSpin FOC/Motion Labs. However I started running into problems when I got to the sensored control example at Lab 12a/b.
I checked the st_obj.vel.conv.Pos_mrev variable to see wether encoder feedback was working as expected. There I discovered that I had a possible variable overflow bug. My encoder line count is 30 000 and in the file "enc.c", that value is used in the variable "uint16_t num_enc_slots". I think that uint16 was overflowing during the "4*num_enc_slots" multiplications. So I changed the num_enc_slots type to uint32_t in enc.c and enc.h. This seemed indeed to be the issue because st_obj.vel.conv.Pos_mrev is now reporting 1.0 after one rotation as expected.
Running lab12b now caused my motor to rotate but quite unstable. I assume this is caused by improper tuning of my speed controller. Since I don't want a speed controller anyway I left this and starting tying to modify the lab12b code to allow for direct torque control by doing the following:
Removing the following lines (from the updateGlobalVariables_motor function):
// get the iq reference from the speed controller
gMotorVars.IqRef_A = _IQmpy(STVELCTL_getTorqueReference(stObj->velCtlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));
and (from the ST_runVelCtl function) removing:
// Set the Iq reference that came out of the SpinTAC Velocity Control
CTRL_setIq_ref_pu(ctrlHandle, iqReference);
And adding the following lines (taken from the Lab4 code) in the main loop:
// update the Iq reference manually
_iq iq_ref = _IQmpy(gMotorVars.IqRef_A, _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A));
CTRL_setIq_ref_pu(ctrlHandle, iq_ref);
// update the direction
if(iq_ref < _IQ(0.0)) {
CTRL_setSpd_ref_krpm(handle, _IQ(-0.01));
} else if (iq_ref > _IQ(0.0)) {
CTRL_setSpd_ref_krpm(handle, _IQ(0.01));
}
However these modification don't seem to provide the desired result. Changing the gMotorVars.IqRef_A manually creates some torque but the commutation doesn't seem to work anymore. Therefore I have two questions: is my uint32_t num_enc_slots overflow fix correct? And how would I modify the lab12 code as to provide direct torque control instead of speed control?
Any help will be greatly appreciated! Best regards, Vleer