BLC.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #include "BLC.h"
  2. ////////////////////////////////////////////////////////////////////////////
  3. void BLC_Init(void)
  4. {
  5. blcd_flg_firstRun = true;
  6. }
  7. ///////////////////////////////////////////////////////////////////////////
  8. void BLC(void)
  9. {
  10. uint16_T i;
  11. static uint16_T blcn_Q_reqCpEE[cmnc_num_cellUNumMax];
  12. static uint32_T blcn_Q_totalCpEE[cmnc_num_cellUNumMax];
  13. static boolean_T blcn_flg_judge;
  14. boolean_T blcn_flg_enable;
  15. uint16_T blcn_pct_cellSoc[cmnc_num_cellUNumMax];
  16. uint16_T blcn_pct_cellSocMin;
  17. static uint16_T blcn_Q_reqCpNow[cmnc_num_cellUNumMax];
  18. real_T Qmin;
  19. real_T QL;
  20. real_T reqCp;
  21. static uint16_T blcn_Q_reqCpEo_Delay[cmnc_num_cellUNumMax];
  22. boolean_T blcn_flg_stop[cmnc_num_cellUNumMax];
  23. boolean_T blcn_flg_pause[cmnc_num_cellUNumMax];
  24. static real_T temp[cmnc_num_cellUNumMax];
  25. uint16_T blcn_Q_impleCp[cmnc_num_cellUNumMax];
  26. if(blcd_flg_firstRun)
  27. {
  28. memset(blcn_Q_reqCpEo_Delay,0,sizeof(blcn_Q_reqCpEo_Delay));
  29. memset(temp,0,sizeof(temp));
  30. }
  31. //=========================================================================
  32. //---------------------------------EE校验----------------------------------
  33. //=========================================================================
  34. if(blcd_flg_firstRun)
  35. {
  36. if(ArrMax(blcv_Q_reqCpEi, cmnc_num_cellUNum) > cmnc_Q_ratedCp)
  37. {
  38. memset(blcn_Q_reqCpEE, 0, sizeof(blcn_Q_reqCpEE));
  39. memset(blcn_Q_totalCpEE,0, sizeof(blcn_Q_totalCpEE));
  40. }
  41. else
  42. {
  43. memcpy(blcn_Q_reqCpEE, blcv_Q_reqCpEi, sizeof(blcv_Q_reqCpEi));
  44. memcpy(blcn_Q_totalCpEE,blcv_Q_totalCpEi, sizeof(blcn_Q_totalCpEE));
  45. }
  46. }
  47. //=========================================================================
  48. //---------------------------------使能判断--------------------------------
  49. //=========================================================================
  50. if(blcd_flg_firstRun)
  51. {
  52. blcn_flg_judge = (ihd_tm_parkTime >= cmnc_tm_parkTime)&& !sfmd_flg_cellUInval && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
  53. }
  54. blcn_flg_enable = ((sfmd_st_fltAct >> 7) & 0x01) != 1;
  55. //=========================================================================
  56. //---------------------------------需求计算--------------------------------
  57. //=========================================================================
  58. if(blcd_flg_firstRun)
  59. {
  60. //压差法
  61. if(blcn_flg_judge)
  62. {
  63. blcn_pct_cellSocMin = look1_u16tu16(sfmd_V_cellUMin,cmnm_V_ocv, cmnm_pct_soc, 13);
  64. for (i = 0; i < cmnc_num_cellUNum; i++)
  65. {
  66. blcn_pct_cellSoc[i] = look1_u16tu16(sfmv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13);
  67. }
  68. for (i = 0; i < cmnc_num_cellUNum; i++)
  69. {
  70. if(sfmv_V_cellU[i] - sfmd_V_cellUMin > blcc_V_low)
  71. {
  72. blcn_Q_reqCpNow[i] = (uint16_T) ((real_T)(cmnc_Q_ratedCp * 0.1) * (real_T)((blcn_pct_cellSoc[i] - blcn_pct_cellSocMin) * 0.1) /100 * 1000);
  73. }
  74. else
  75. {
  76. blcn_Q_reqCpNow[i] = 0;
  77. }
  78. }
  79. }
  80. else
  81. {
  82. memcpy(blcn_Q_reqCpNow,blcn_Q_reqCpEE, sizeof(blcn_Q_reqCpEE));
  83. }
  84. /*/ 最大化容量法
  85. if(blcn_flg_judge)
  86. {
  87. Qmin = (real_T)(sohv_Q_cellCap[0] * 0.1) * (real_T)(blcn_pct_cellSoc[0] * 0.1)/100;
  88. for(i = 0; i < cmnc_num_cellUNum; i++)
  89. {
  90. if (Qmin > (real_T)(sohv_Q_cellCap[i] * 0.1) * (real_T)(blcn_pct_cellSoc[i] * 0.1)/100)
  91. {
  92. Qmin = (real_T)(sohv_Q_cellCap[i] * 0.1) * (real_T)(blcn_pct_cellSoc[i] * 0.1)/100;
  93. QL = (real_T)(sohv_Q_cellCap[i] * 0.1) - Qmin;
  94. }
  95. }
  96. for(i = 0; i < cmnc_num_cellUNum; i++)
  97. {
  98. reqCp = QL- (real_T)(sohv_Q_cellCap[i] * 0.1)*(real_T)(blcn_pct_cellSoc[i] * 0.1)/100;
  99. if (reqCp >0.001)
  100. {
  101. blcn_Q_reqCpNow[i] =uint16_T(reqCp * 1000);
  102. }
  103. }
  104. }
  105. else
  106. {
  107. memcpy(blcn_Q_reqCpNow,blcn_Q_reqCpEE, sizeof(blcn_Q_reqCpEE));
  108. } */
  109. }
  110. //=========================================================================
  111. //---------------------------------stop计算--------------------------------
  112. //=========================================================================
  113. for(i = 0; i < cmnc_num_cellUNum; i++)
  114. {
  115. if(blcn_Q_reqCpEo_Delay[i] > 0)
  116. {
  117. blcn_flg_stop[i] = false;
  118. }
  119. else
  120. {
  121. blcn_flg_stop[i] = true;
  122. }
  123. }
  124. //=========================================================================
  125. //---------------------------------pause计算-------------------------------
  126. //=========================================================================
  127. for(i = 0; i < cmnc_num_cellUNum; i++)
  128. {
  129. blcn_flg_pause[i] = false;
  130. }
  131. //=========================================================================
  132. //--------------------------------指令及实际均衡容量计算--------------------
  133. //=========================================================================
  134. for(i = 0; i < cmnc_num_cellUNum; i++)
  135. {
  136. if(blcn_flg_enable && !blcn_flg_pause[i] && ! blcn_flg_stop[i])
  137. {
  138. blcv_flg_excute[i] = true ;
  139. temp[i] = temp[i] + (real_T) (sfmv_V_cellU[i] * 0.001) / (real_T) (blcc_R_esr * 0.1);
  140. }
  141. else
  142. {
  143. blcv_flg_excute[i] = false ;
  144. }
  145. blcn_Q_impleCp[i] = (uint16_T) (temp[i] /3600 * 1000);
  146. blcv_Q_reqCpEo[i] = ((int16_T)(blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]) < 0 ? 0 :blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]);
  147. blcv_Q_totalCpEo[i] = (uint32_T) (blcn_Q_totalCpEE[i] + blcn_Q_impleCp[i]);
  148. }
  149. //
  150. blcd_flg_firstRun = false;
  151. memcpy(blcn_Q_reqCpEo_Delay,blcv_Q_reqCpEo, sizeof(blcn_Q_reqCpEE));
  152. }