|
|
@@ -212,22 +212,25 @@ void GetSrefKeyGear(void)
|
|
|
//转速曲线计算
|
|
|
if (isCtrlPowOn)
|
|
|
{
|
|
|
+ // VSP测试代码
|
|
|
+ // mcFocCtrl.Ref = mcFocCtrl.SREFValue;
|
|
|
+
|
|
|
// 计算公式为
|
|
|
// Ref = ( 区间UQ差 / 区间调速电压差) * (VSP - 调速下限) + 区间最小UQ值
|
|
|
- if (mcFocCtrl.SREFValue <= 1408)
|
|
|
- { mcFocCtrl.Ref = _Q15(0.120); }
|
|
|
- else if (mcFocCtrl.SREFValue <= 11640 )
|
|
|
- { mcFocCtrl.Ref = 0.864 * (mcFocCtrl.SREFValue - 1408) + _Q15(0.120); }
|
|
|
- else if (mcFocCtrl.SREFValue <= 15530 )
|
|
|
- { mcFocCtrl.Ref = 1.238 * (mcFocCtrl.SREFValue - 11640) + _Q15(0.390); }
|
|
|
- else if (mcFocCtrl.SREFValue <= 19480 )
|
|
|
- { mcFocCtrl.Ref = 1.543 * (mcFocCtrl.SREFValue - 15530) + _Q15(0.537); }
|
|
|
- else if (mcFocCtrl.SREFValue <= 21962 )
|
|
|
- { mcFocCtrl.Ref = 1.755 * (mcFocCtrl.SREFValue - 19480) + _Q15(0.723); }
|
|
|
- else if (mcFocCtrl.SREFValue <= 23368 )
|
|
|
- { mcFocCtrl.Ref = 2.004 * (mcFocCtrl.SREFValue - 21962) + _Q15(0.856); }
|
|
|
- else
|
|
|
- { mcFocCtrl.Ref = _Q15(0.942); }
|
|
|
+ if(mcFocCtrl.SREFValue <=GearMinVol)
|
|
|
+ { mcFocCtrl.Ref = 3094; }
|
|
|
+ else if(mcFocCtrl.SREFValue <=GearA)
|
|
|
+ { mcFocCtrl.Ref = 0.462 * (mcFocCtrl.SREFValue - GearMinVol) + 3094; }
|
|
|
+ else if(mcFocCtrl.SREFValue <=GearB)
|
|
|
+ { mcFocCtrl.Ref = 0.734 * (mcFocCtrl.SREFValue - GearA) + 9454; }
|
|
|
+ else if(mcFocCtrl.SREFValue <=GearC)
|
|
|
+ { mcFocCtrl.Ref = 0.949 * (mcFocCtrl.SREFValue - GearB) + 13303; }
|
|
|
+ else if(mcFocCtrl.SREFValue <=GearD)
|
|
|
+ { mcFocCtrl.Ref = 0.795 * (mcFocCtrl.SREFValue - GearC) + 18280; }
|
|
|
+ else if(mcFocCtrl.SREFValue <=GearE)
|
|
|
+ { mcFocCtrl.Ref = 1.011 * (mcFocCtrl.SREFValue - GearD) + 20887; }
|
|
|
+ else
|
|
|
+ { mcFocCtrl.Ref = 22875; }
|
|
|
}
|
|
|
else
|
|
|
{ mcFocCtrl.Ref = 0; }
|
|
|
@@ -306,135 +309,140 @@ void GetTargetRef(void)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- @brief 外部闭环控制函数,示例代码提供 电流环,速度环,功率环,UQ控制示例代码,可根据需要自行修改
|
|
|
- 建议使用默认1ms周期运行
|
|
|
- @date 2022-07-14
|
|
|
+ * @function LoopResponse
|
|
|
+ * @brief 闭环控制函数
|
|
|
+ * @param[in] None
|
|
|
+ * @return None
|
|
|
+ * @date 2024-08-28
|
|
|
*/
|
|
|
void LoopResponse(void)
|
|
|
{
|
|
|
static int16 refRampOut = 0;
|
|
|
|
|
|
-
|
|
|
- switch (mcFocCtrl.CtrlMode)
|
|
|
+ switch (mcFocCtrl.CtrlMode)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
{
|
|
|
- case 0:
|
|
|
+ if (mcFocCtrl.SpeedFlt > MOTOR_LOOP_RPM)
|
|
|
{
|
|
|
- if (mcFocCtrl.SpeedFlt > MOTOR_LOOP_RPM)
|
|
|
+ mcFocCtrl.Mode0HoldCnt++;
|
|
|
+
|
|
|
+ if (mcFocCtrl.Mode0HoldCnt > 10)
|
|
|
{
|
|
|
- mcFocCtrl.Mode0HoldCnt++;
|
|
|
-
|
|
|
- if (mcFocCtrl.Mode0HoldCnt > 10)
|
|
|
- {
|
|
|
- FOC_QKP = QKP;
|
|
|
- FOC_QKI = QKI;
|
|
|
- FOC_DKP = DKP;
|
|
|
- FOC_DKI = DKI;
|
|
|
- // FOC_THECOMP = _Q15(-25.0 / 180.0); // SMO 估算补偿角
|
|
|
- // 启动电流环与外环给定衔接
|
|
|
- #if (MOTOR_CTRL_MODE == SPEED_LOOP_CONTROL)
|
|
|
- LoopRefRamp.Out = mcFocCtrl.SpeedFlt;
|
|
|
- #elif (MOTOR_CTRL_MODE == POWER_LOOP_CONTROL)
|
|
|
- LoopRefRamp.Out = mcFocCtrl.Power;
|
|
|
- #elif (MOTOR_CTRL_MODE == UQ_LOOP_CONTROL)
|
|
|
- LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
- #elif (MOTOR_CTRL_MODE == UQ_POWER_CONTROL)
|
|
|
- LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
- #endif
|
|
|
- mcFocCtrl.LoopTime = LOOP_TIME;
|
|
|
- LoopRefRamp.Inc = RAMP_INC;
|
|
|
- LoopRefRamp.Dec = RAMP_DEC;
|
|
|
- mcFocCtrl.IqRef = FOC_IQREF;
|
|
|
- FOC_IDREF = ID_RUN_CURRENT; // D轴启动电流
|
|
|
- PI1_UKH = mcFocCtrl.IqRef;
|
|
|
- PI2_Init(); // PI初始化
|
|
|
- // 弱磁
|
|
|
- #if (MotorFiledWeakenEn)
|
|
|
- FiledWeakenInit();
|
|
|
- #endif
|
|
|
- // 电压补偿
|
|
|
- VoltageComp.Undervoltage_flag = 0;
|
|
|
- VoltageComp.IncVoltage = _Q15(40.0 / HW_BOARD_VOLT_MAX);
|
|
|
- VoltageComp.LineAngel = LinearCompensationAngel;
|
|
|
- VoltageComp.LineAngelMax = LinearCompensationAngel_MAX;
|
|
|
- VoltageComp.LineAngelMin = LinearCompensationAngel_MIN;
|
|
|
- VoltageComp.VCDelayCnt = VoltageCompensationDelayCnt;
|
|
|
- mcFocCtrl.CtrlMode = 1;
|
|
|
- }
|
|
|
+ FOC_QKP = QKP;
|
|
|
+ FOC_QKI = QKI;
|
|
|
+ FOC_DKP = DKP;
|
|
|
+ FOC_DKI = DKI;
|
|
|
+ // FOC_THECOMP = _Q15(-25.0 / 180.0); // SMO 估算补偿角
|
|
|
+ // 启动电流环与外环给定衔接
|
|
|
+ #if (MOTOR_CTRL_MODE == SPEED_LOOP_CONTROL)
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.SpeedFlt;
|
|
|
+ #elif (MOTOR_CTRL_MODE == POWER_LOOP_CONTROL)
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.Power;
|
|
|
+ #elif (MOTOR_CTRL_MODE == UQ_LOOP_CONTROL)
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
+ #elif (MOTOR_CTRL_MODE == UQ_POWER_CONTROL)
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
+ #endif
|
|
|
+ mcFocCtrl.LoopTime = LOOP_TIME;
|
|
|
+ LoopRefRamp.Inc = RAMP_INC;
|
|
|
+ LoopRefRamp.Dec = RAMP_DEC;
|
|
|
+ mcFocCtrl.IqRef = FOC_IQREF;
|
|
|
+ FOC_IDREF = ID_RUN_CURRENT; // D轴启动电流
|
|
|
+ PI1_UKH = mcFocCtrl.IqRef;
|
|
|
+ PI2_Init(); // PI初始化
|
|
|
+ // 弱磁
|
|
|
+ #if (MotorFiledWeakenEn)
|
|
|
+ FiledWeakenInit();
|
|
|
+ #endif
|
|
|
+ // 电压补偿
|
|
|
+ VoltageComp.Undervoltage_flag = 0;
|
|
|
+ VoltageComp.IncVoltage = _Q15(40.0 / HW_BOARD_VOLT_MAX);
|
|
|
+ VoltageComp.LineAngel = LinearCompensationAngel;
|
|
|
+ VoltageComp.LineAngelMax = LinearCompensationAngel_MAX;
|
|
|
+ VoltageComp.LineAngelMin = LinearCompensationAngel_MIN;
|
|
|
+ VoltageComp.VCDelayCnt = VoltageCompensationDelayCnt;
|
|
|
+ mcFocCtrl.CtrlMode = 1;
|
|
|
}
|
|
|
- else
|
|
|
- { mcFocCtrl.Mode0HoldCnt = 0; }
|
|
|
-
|
|
|
- break;
|
|
|
}
|
|
|
+ else
|
|
|
+ { mcFocCtrl.Mode0HoldCnt = 0; }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ mcFocCtrl.LoopTime++;
|
|
|
|
|
|
- case 1:
|
|
|
+ if (mcFocCtrl.LoopTime >= LOOP_TIME)
|
|
|
{
|
|
|
- mcFocCtrl.LoopTime++;
|
|
|
-
|
|
|
- if (mcFocCtrl.LoopTime >= LOOP_TIME)
|
|
|
+ mcFocCtrl.LoopTime = 0;
|
|
|
+ refRampOut = LoopRamp(mcFocCtrl.Ref); // 控制命令爬坡函数,用于实现调速信号之间平滑过渡
|
|
|
+ #if (MOTOR_CTRL_MODE == CURRENT_LOOP_CONTROL)
|
|
|
{
|
|
|
- mcFocCtrl.LoopTime = 0;
|
|
|
- refRampOut = LoopRamp(mcFocCtrl.Ref); // 控制命令爬坡函数,用于实现调速信号之间平滑过渡
|
|
|
- #if (MOTOR_CTRL_MODE == CURRENT_LOOP_CONTROL)
|
|
|
- {
|
|
|
- mcFocCtrl.IqRef = refRampOut;
|
|
|
- FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
- }
|
|
|
- #elif (MOTOR_CTRL_MODE == SPEED_LOOP_CONTROL)
|
|
|
- {
|
|
|
- mcFocCtrl.IqSpeedRef = HW_One_PI(refRampOut - mcFocCtrl.SpeedFlt);
|
|
|
- mcFocCtrl.LimitIqOut = HW_One_PI2(mcFocCtrl.PowerLimitValue - mcFocCtrl.Power); // 限制功率
|
|
|
-
|
|
|
- if ((mcFocCtrl.LimitIqOut < mcFocCtrl.IqSpeedRef)) // 限制输出电流
|
|
|
- {
|
|
|
- mcFocCtrl.ExtDec = (mcFocCtrl.IqRef - mcFocCtrl.LimitIqOut) / 3;
|
|
|
- mcFocCtrl.IqRef -= mcFocCtrl.ExtDec;
|
|
|
- }
|
|
|
- else
|
|
|
- { mcFocCtrl.IqRef = mcFocCtrl.IqSpeedRef; }
|
|
|
-
|
|
|
- #if (MotorFiledWeakenEn)
|
|
|
- FileWeakenControl();
|
|
|
- #else
|
|
|
- FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
- #endif
|
|
|
- }
|
|
|
- #elif (MOTOR_CTRL_MODE == POWER_LOOP_CONTROL)
|
|
|
- {
|
|
|
- mcFocCtrl.IqRef = HW_One_PI(refRampOut - mcFocCtrl.Power);
|
|
|
- FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
- }
|
|
|
- #elif (MOTOR_CTRL_MODE == UQ_LOOP_CONTROL)
|
|
|
- {
|
|
|
- mcFocCtrl.IqRef = HW_One_PI(refRampOut - mcFocCtrl.UqFlt);
|
|
|
- FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
- }
|
|
|
- #elif (MOTOR_CTRL_MODE == UQ_POWER_CONTROL)
|
|
|
+ mcFocCtrl.IqRef = refRampOut;
|
|
|
+ FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
+ }
|
|
|
+ #elif (MOTOR_CTRL_MODE == SPEED_LOOP_CONTROL)
|
|
|
+ {
|
|
|
+ mcFocCtrl.IqSpeedRef = HW_One_PI(refRampOut - mcFocCtrl.SpeedFlt);
|
|
|
+ mcFocCtrl.LimitIqOut = HW_One_PI2(mcFocCtrl.PowerLimitValue - mcFocCtrl.Power); // 限制功率
|
|
|
+
|
|
|
+ if ((mcFocCtrl.LimitIqOut < mcFocCtrl.IqSpeedRef)) // 限制输出电流
|
|
|
{
|
|
|
- // 反馈计算
|
|
|
- mcFocCtrl.LoopCalcValue = mcFocCtrl.UqFlt * 0.65 + mcFocCtrl.Power * 0.62;
|
|
|
-
|
|
|
- // 限幅
|
|
|
- if (mcFocCtrl.LoopCalcValue > 32440)
|
|
|
- { mcFocCtrl.LoopCalcValue = 32440;}
|
|
|
-
|
|
|
- mcFocCtrl.IqRef = HW_One_PI(refRampOut - mcFocCtrl.LoopCalcValue);
|
|
|
- FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
+ mcFocCtrl.ExtDec = (mcFocCtrl.IqRef - mcFocCtrl.LimitIqOut) / 3;
|
|
|
+ mcFocCtrl.IqRef -= mcFocCtrl.ExtDec;
|
|
|
}
|
|
|
+ else
|
|
|
+ { mcFocCtrl.IqRef = mcFocCtrl.IqSpeedRef; }
|
|
|
+
|
|
|
+ #if (MotorFiledWeakenEn)
|
|
|
+ FileWeakenControl();
|
|
|
+ #else
|
|
|
+ FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
#endif
|
|
|
}
|
|
|
-
|
|
|
- #if (SVPWM_5_Segment_Run_Enale == 1) // 开启五段式
|
|
|
+ #elif (MOTOR_CTRL_MODE == POWER_LOOP_CONTROL)
|
|
|
+ {
|
|
|
+ mcFocCtrl.IqRef = HW_One_PI(refRampOut - mcFocCtrl.Power);
|
|
|
+ FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
+ }
|
|
|
+ #elif (MOTOR_CTRL_MODE == UQ_LOOP_CONTROL)
|
|
|
{
|
|
|
- if (mcFocCtrl.SpeedFlt > Motor_F5SEG_Speed)
|
|
|
- { SetBit(FOC_CR2, F5SEG); }
|
|
|
- else if (mcFocCtrl.SpeedFlt < Motor_F7SEG_Speed)
|
|
|
- { ClrBit(FOC_CR2, F5SEG); }
|
|
|
+ mcFocCtrl.IqRef = HW_One_PI(refRampOut - mcFocCtrl.UqFlt);
|
|
|
+ FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
+ }
|
|
|
+ #elif (MOTOR_CTRL_MODE == UQ_POWER_CONTROL)
|
|
|
+ {
|
|
|
+ mcFocCtrl.LoopCalcInValue = mcFocCtrl.UqFlt*0.45 + mcFocCtrl.Power*0.65;
|
|
|
+ mcFocCtrl.LoopCalcOutValue = HW_One_PI(refRampOut - mcFocCtrl.LoopCalcInValue);
|
|
|
+ mcFocCtrl.LimitIqOut = HW_TWO_PI(mcFocCtrl.PowerLimitValue - mcFocCtrl.Power);
|
|
|
+ // 限制输出电流
|
|
|
+ if ((mcFocCtrl.LimitIqOut < mcFocCtrl.LoopCalcOutValue))
|
|
|
+ {
|
|
|
+ mcFocCtrl.ExtDec = (mcFocCtrl.IqRef - mcFocCtrl.LimitIqOut) / 3;
|
|
|
+ mcFocCtrl.IqRef -= mcFocCtrl.ExtDec;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { mcFocCtrl.IqRef = mcFocCtrl.LoopCalcOutValue; }
|
|
|
+
|
|
|
+ FOC_IQREF = mcFocCtrl.IqRef;
|
|
|
}
|
|
|
#endif
|
|
|
- break;
|
|
|
}
|
|
|
+
|
|
|
+ #if (SVPWM_5_Segment_Run_Enale == 1) // 开启五段式
|
|
|
+ {
|
|
|
+ if (mcFocCtrl.SpeedFlt > Motor_F5SEG_Speed)
|
|
|
+ { SetBit(FOC_CR2, F5SEG); }
|
|
|
+ else if (mcFocCtrl.SpeedFlt < Motor_F7SEG_Speed)
|
|
|
+ { ClrBit(FOC_CR2, F5SEG); }
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|