当前位置:   article > 正文

电压电流双闭环PFC单相PWM整流_电压环电流环双闭环程序

电压环电流环双闭环程序

目录

仿真

完整框图

pwm内部调制方式

仿真结果

关键源代码

PI参数初始化以及位置式PI计算

锁相环计算

PWM调制发波

完整工程代码链接


仿真

完整框图

pwm内部调制方式

 

仿真结果

输入电压和输入电流 

输出电压

关键源代码

PI参数初始化以及位置式PI计算

  1. void Init_PID(void)
  2. {
  3. pid_Udc.SetValue = 60;
  4. pid_Udc.ActualValue = 0;
  5. pid_Udc.KP = 0;
  6. pid_Udc.KI = 0.6;
  7. pid_Udc.KD = 0;
  8. pid_Udc.ek = 0;
  9. pid_Udc.ek_1 = 0;
  10. pid_Udc.ek_2 = 0;
  11. pid_Udc.PIDmax = tbprd;
  12. pid_Udc.PIDmin = -tbprd;
  13. pid_Udc.Sum_max = 3;
  14. pid_Udc.Sum_min = -3;
  15. pid_Iac.SetValue = 0;
  16. pid_Iac.ActualValue = 0;
  17. // pid_Iac.KP = 18; // 1000mH KP
  18. // pid_Iac.KP = 17;
  19. // pid_Iac.KP = 15;
  20. //pid_Iac.KP = 18; PF=97;
  21. // pid_Iac.KP = 20.5; 94
  22. //pid_Iac.KP=19.5; 94
  23. //pid_Iac.KP=17; 97 98
  24. pid_Iac.KP=17.5; // 50 60 欧姆
  25. // pid_Iac.KP=22;
  26. // pid_Iac.KP = 15;
  27. pid_Iac.KI = 0;
  28. pid_Iac.ek = 0;
  29. pid_Iac.ek_1 = 0;
  30. pid_Iac.ek_2 = 0;
  31. pid_Iac.PIDmax = 1;
  32. pid_Iac.PIDmin = -1;
  33. pid_Iac.Sum_max = 3;
  34. pid_Iac.Sum_min = -3;
  35. // pid_Iac.Sum_max = 5;
  36. // pid_Iac.Sum_min = -5;
  37. // 电流不需要限幅
  38. }
  39. float PID_Control_Inc(PID *pid, int flag) // 增量式PID
  40. {
  41. float inc = 0;
  42. pid->ek = pid->SetValue - pid->ActualValue;
  43. inc = pid->KP * (pid->ek - pid->ek_1) + pid->KI * pid->ek
  44. + pid->KD * (pid->ek - 2 * pid->ek_1 + pid->ek_2);
  45. if (inc > pid->PIDmax)
  46. return pid->PIDmax;
  47. if (inc < pid->PIDmin)
  48. return pid->PIDmin;
  49. return inc;
  50. }
  51. float PID_Control_Pos(PID *pid, int flag) // 位置式PID
  52. {
  53. float Pos = 0;
  54. pid->ek = pid->SetValue - pid->ActualValue;
  55. // int flag = 0; // 积分分离pid
  56. // if (fabsf(pid->ek) >= 20)
  57. // flag = 0;
  58. // else
  59. // flag = 1;
  60. pid->ek_sum += pid->ek;
  61. Pos = pid->KP * pid->ek + pid->KI * pid->ek_sum;
  62. // + pid->KD * (pid->ek - pid->ek_1);
  63. // 积分限幅
  64. if (pid->ek_sum > pid->Sum_max)
  65. pid->ek_sum = pid->Sum_max;
  66. if (pid->ek_sum < pid->Sum_min)
  67. pid->ek_sum = pid->Sum_min;
  68. pid->PIDout = Pos;
  69. if (flag == 0)
  70. {
  71. if (Pos > pid->PIDmax)
  72. {
  73. pid->PIDout = pid->PIDmax;
  74. return pid->PIDmax;
  75. }
  76. if (Pos < pid->PIDmin)
  77. {
  78. pid->PIDout = pid->PIDmin;
  79. return pid->PIDmin;
  80. }
  81. return pid->PIDout;
  82. }
  83. else
  84. return pid->PIDout;
  85. }

锁相环计算

  1. #define DPLL_LOOP(X) LPF_LG.FilterInput = X * HPLL.CosFeedback ;\
  2. LPF_LG.U[2] = LPF_LG.FilterInput - LPF_LG.a*LPF_LG.U[1] - LPF_LG.b *LPF_LG.U[0];\
  3. LPF_LG.Filteroutput = LPF_LG.c*(LPF_LG.U[2] + 2*LPF_LG.U[1] + LPF_LG.U[0]);\
  4. LPF_LG.U[0]=LPF_LG.U[1];\
  5. LPF_LG.U[1]=LPF_LG.U[2];\
  6. HPLL.EphiIntegral +=LPF_LG.Filteroutput * Ts;\
  7. HPLL.w = HPLL.Kp * LPF_LG.Filteroutput + HPLL.Ki * HPLL.EphiIntegral;\
  8. HPLL.AngleVelocityIntegral = HPLL.AngleVelocityIntegral + ( HPLL.w + 100*PI)*Ts;\
  9. HPLL.wt = HPLL.AngleVelocityIntegral - ((int)(HPLL.AngleVelocityIntegral*0.15915494309189533576888376337251))*(2*PI);\
  10. HPLL.AngleVelocityIntegral = HPLL.wt;\
  11. HPLL.CosFeedback = cosf(HPLL.wt);
  12. #endif
  13. void LPF_Data_Init(struct LPF_But * LPF)
  14. {
  15. float m;
  16. m = LPF->SamplePeriod / PI / LPF->Fstop; // 2*Fs/wf
  17. LPF->a = 2 * (1 - m * m) / (m * m + m / LPF->QualityFactor + 1);
  18. LPF->b = (m * m - m / LPF->QualityFactor + 1)
  19. / (m * m + m / LPF->QualityFactor + 1);
  20. LPF->c = 1 / (m * m + m / LPF->QualityFactor + 1);
  21. LPF->e = m / LPF->QualityFactor / (m * m + m / LPF->QualityFactor + 1);
  22. }

PWM调制发波

  1. DPLL_LOOP(Uac);
  2. float wt = HPLL.wt + PFC.offset;
  3. float phase = sinf(wt);
  4. // // DAC output theta
  5. EALLOW;
  6. DacbRegs.DACVALS.bit.DACVALS = (uint) ((phase + 1) * 1241);
  7. EDIS;
  8. static int i = 0;
  9. // 电压外环闭环控制
  10. if (i >= 250)
  11. {
  12. pid_Udc.ActualValue = Udc;
  13. // Ref = 0.6;
  14. Ref = PID_Control_Pos(&pid_Udc, 1); // within limit
  15. Ref = 0.8 * Ref;
  16. i = 0;
  17. }
  18. i++;
  19. pid_Iac.SetValue = Ref * phase;
  20. pid_Iac.ActualValue = Iac;
  21. float temp = PID_Control_Pos(&pid_Iac, 1); // positional PID control
  22. // generate modulate wave spwm
  23. ModulateWave = (-temp + Uac + Ref * cosf(wt) * 0.15 * PI); // - 0.2 * PI * spll1.cos[1]); //- 0.34 * PI * spll1.cos[1]; // 调制波
  24. float temp1 = (0.5 * (tbprd + tbprd * 0.008 * ModulateWave));
  25. float temp2 = (0.5 * (tbprd - tbprd * 0.008 * ModulateWave));
  26. // limit modulate wave // 限幅考虑死区时间的占空比
  27. if (temp1 > 0.98 * tbprd)
  28. temp1 = 0.98 * tbprd;
  29. if (temp1 < 0.02 * tbprd)
  30. temp1 = 0.02 * tbprd;
  31. if (temp2 > 0.98 * tbprd)
  32. temp2 = 0.98 * tbprd;
  33. if (temp2 < 0.02 * tbprd)
  34. temp2 = 0.02 * tbprd;
  35. // assign modulate wave
  36. EPwm2Regs.CMPA.bit.CMPA = (uint) temp1;
  37. EPwm3Regs.CMPA.bit.CMPA = (uint) temp2;

完整工程代码链接

https://download.csdn.net/download/xht2403267701/86326992?spm=1001.2014.3001.5503

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/135012
推荐阅读
相关标签
  

闽ICP备14008679号