赞
踩
目录
输入电压和输入电流
输出电压
- void Init_PID(void)
- {
- pid_Udc.SetValue = 60;
- pid_Udc.ActualValue = 0;
- pid_Udc.KP = 0;
- pid_Udc.KI = 0.6;
- pid_Udc.KD = 0;
- pid_Udc.ek = 0;
- pid_Udc.ek_1 = 0;
- pid_Udc.ek_2 = 0;
- pid_Udc.PIDmax = tbprd;
- pid_Udc.PIDmin = -tbprd;
- pid_Udc.Sum_max = 3;
- pid_Udc.Sum_min = -3;
-
- pid_Iac.SetValue = 0;
- pid_Iac.ActualValue = 0;
- // pid_Iac.KP = 18; // 1000mH KP
- // pid_Iac.KP = 17;
- // pid_Iac.KP = 15;
- //pid_Iac.KP = 18; PF=97;
- // pid_Iac.KP = 20.5; 94
- //pid_Iac.KP=19.5; 94
- //pid_Iac.KP=17; 97 98
- pid_Iac.KP=17.5; // 50 60 欧姆
- // pid_Iac.KP=22;
- // pid_Iac.KP = 15;
- pid_Iac.KI = 0;
- pid_Iac.ek = 0;
- pid_Iac.ek_1 = 0;
- pid_Iac.ek_2 = 0;
- pid_Iac.PIDmax = 1;
- pid_Iac.PIDmin = -1;
-
- pid_Iac.Sum_max = 3;
- pid_Iac.Sum_min = -3;
- // pid_Iac.Sum_max = 5;
- // pid_Iac.Sum_min = -5;
- // 电流不需要限幅
- }
-
- float PID_Control_Inc(PID *pid, int flag) // 增量式PID
- {
- float inc = 0;
-
- pid->ek = pid->SetValue - pid->ActualValue;
- inc = pid->KP * (pid->ek - pid->ek_1) + pid->KI * pid->ek
- + pid->KD * (pid->ek - 2 * pid->ek_1 + pid->ek_2);
-
- if (inc > pid->PIDmax)
- return pid->PIDmax;
- if (inc < pid->PIDmin)
- return pid->PIDmin;
-
- return inc;
- }
- float PID_Control_Pos(PID *pid, int flag) // 位置式PID
- {
- float Pos = 0;
-
- pid->ek = pid->SetValue - pid->ActualValue;
-
- // int flag = 0; // 积分分离pid
- // if (fabsf(pid->ek) >= 20)
- // flag = 0;
- // else
- // flag = 1;
-
- pid->ek_sum += pid->ek;
- Pos = pid->KP * pid->ek + pid->KI * pid->ek_sum;
- // + pid->KD * (pid->ek - pid->ek_1);
-
- // 积分限幅
- if (pid->ek_sum > pid->Sum_max)
- pid->ek_sum = pid->Sum_max;
- if (pid->ek_sum < pid->Sum_min)
- pid->ek_sum = pid->Sum_min;
- pid->PIDout = Pos;
-
- if (flag == 0)
- {
- if (Pos > pid->PIDmax)
- {
- pid->PIDout = pid->PIDmax;
- return pid->PIDmax;
- }
- if (Pos < pid->PIDmin)
-
- {
- pid->PIDout = pid->PIDmin;
- return pid->PIDmin;
- }
- return pid->PIDout;
- }
- else
- return pid->PIDout;
- }
- #define DPLL_LOOP(X) LPF_LG.FilterInput = X * HPLL.CosFeedback ;\
- LPF_LG.U[2] = LPF_LG.FilterInput - LPF_LG.a*LPF_LG.U[1] - LPF_LG.b *LPF_LG.U[0];\
- LPF_LG.Filteroutput = LPF_LG.c*(LPF_LG.U[2] + 2*LPF_LG.U[1] + LPF_LG.U[0]);\
- LPF_LG.U[0]=LPF_LG.U[1];\
- LPF_LG.U[1]=LPF_LG.U[2];\
- HPLL.EphiIntegral +=LPF_LG.Filteroutput * Ts;\
- HPLL.w = HPLL.Kp * LPF_LG.Filteroutput + HPLL.Ki * HPLL.EphiIntegral;\
- HPLL.AngleVelocityIntegral = HPLL.AngleVelocityIntegral + ( HPLL.w + 100*PI)*Ts;\
- HPLL.wt = HPLL.AngleVelocityIntegral - ((int)(HPLL.AngleVelocityIntegral*0.15915494309189533576888376337251))*(2*PI);\
- HPLL.AngleVelocityIntegral = HPLL.wt;\
- HPLL.CosFeedback = cosf(HPLL.wt);
- #endif
-
- void LPF_Data_Init(struct LPF_But * LPF)
- {
- float m;
- m = LPF->SamplePeriod / PI / LPF->Fstop; // 2*Fs/wf
- LPF->a = 2 * (1 - m * m) / (m * m + m / LPF->QualityFactor + 1);
- LPF->b = (m * m - m / LPF->QualityFactor + 1)
- / (m * m + m / LPF->QualityFactor + 1);
- LPF->c = 1 / (m * m + m / LPF->QualityFactor + 1);
- LPF->e = m / LPF->QualityFactor / (m * m + m / LPF->QualityFactor + 1);
- }
- DPLL_LOOP(Uac);
-
- float wt = HPLL.wt + PFC.offset;
- float phase = sinf(wt);
- // // DAC output theta
- EALLOW;
- DacbRegs.DACVALS.bit.DACVALS = (uint) ((phase + 1) * 1241);
- EDIS;
-
- static int i = 0;
- // 电压外环闭环控制
- if (i >= 250)
- {
- pid_Udc.ActualValue = Udc;
- // Ref = 0.6;
- Ref = PID_Control_Pos(&pid_Udc, 1); // within limit
- Ref = 0.8 * Ref;
- i = 0;
- }
- i++;
-
- pid_Iac.SetValue = Ref * phase;
- pid_Iac.ActualValue = Iac;
-
- float temp = PID_Control_Pos(&pid_Iac, 1); // positional PID control
-
- // generate modulate wave spwm
- ModulateWave = (-temp + Uac + Ref * cosf(wt) * 0.15 * PI); // - 0.2 * PI * spll1.cos[1]); //- 0.34 * PI * spll1.cos[1]; // 调制波
-
- float temp1 = (0.5 * (tbprd + tbprd * 0.008 * ModulateWave));
- float temp2 = (0.5 * (tbprd - tbprd * 0.008 * ModulateWave));
-
- // limit modulate wave // 限幅考虑死区时间的占空比
- if (temp1 > 0.98 * tbprd)
- temp1 = 0.98 * tbprd;
- if (temp1 < 0.02 * tbprd)
- temp1 = 0.02 * tbprd;
- if (temp2 > 0.98 * tbprd)
- temp2 = 0.98 * tbprd;
- if (temp2 < 0.02 * tbprd)
- temp2 = 0.02 * tbprd;
-
- // assign modulate wave
- EPwm2Regs.CMPA.bit.CMPA = (uint) temp1;
- EPwm3Regs.CMPA.bit.CMPA = (uint) temp2;
https://download.csdn.net/download/xht2403267701/86326992?spm=1001.2014.3001.5503
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。