Author Topic: Data types of Kp and Ki parameters for PI Control  (Read 168 times)


  • Active Member
  • *
  • Posts: 1
Data types of Kp and Ki parameters for PI Control
« on: July 14, 2020, 03:30:43 AM »

I'd like to ask a few questons about data types of Kp and Ki parameters for PI Control.

I think the Kp and Ki have been specified to have fixed point format of Q16.16 and those registers are 32-bit.
I saw FocDevice.cpp file (from line 157) describes TORQUE_KP_REG, TORQUE_KP_REG, etc., as below.
add_parameter_value(config->init, parameterRegisters, TORQUE_KP_REG, 5000);      // Torque Kp = 1.0
add_parameter_value(config->init, parameterRegisters, TORQUE_KI_REG, 0);      // Torque Ki = 0
add_parameter_value(config->init, parameterRegisters, RPM_KP_REG, -200);      // Speed Kp = 2.88
add_parameter_value(config->init, parameterRegisters, RPM_KI_REG, -5);         // Speed Ki

Could you tell me why "TORQUE_KP_REG, 5000" is "Torque Kp = 1.0" and "RPM_KP_REG, -200" is "Speed Kp = 2.88"?

For RPM_KI_REG, TORQUE_KP_REG and TORQUE_KI_REG, what do the -5, -20000 and -5000 represent?
add_parameter_value(config->torque, parameterRegisters, TORQUE_KP_REG, -20000);
add_parameter_value(config->torque, parameterRegisters, TORQUE_KI_REG, -5000);

PI_Control function specifies int16_t Kp and int16_t Ki, but above registers are 32-bit.
How does the PI_Control function in foc.cpp calculate above the fixed point format of Q16.16?


Andrei Errapart

  • Active Member
  • *
  • Posts: 31
Re: Data types of Kp and Ki parameters for PI Control
« Reply #1 on: July 23, 2020, 01:16:02 PM »
I am sorry for the delay in answer.

You are right in your observations. The documentation should read Q8.8 for the proportional setpoint and Q0.16 for the integral setpoint.

The comments require updates as follows:
// Torque Kp (Q8.8 ): register contents 5000 for the value of 19.53.
// Speed Kp (Q8.8 ): register contents -200 for the value of -0.78
// Speed Ki (Q0.16): registers contents -5 for the value of -0.000076

If there are any further questions, don't hesitate to ask.