SOR.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "SOR.h"
  2. void SOR_Init(void)
  3. {
  4. sord_flg_firstRun = true;
  5. }
  6. //-------------------------------------------------------------------------
  7. void SOR(void)
  8. {
  9. static uint16_T sorn_R_cellEE[cmnc_num_cellUNumMax];
  10. static uint16_T sorn_R_cellEEArr[5][cmnc_num_cellUNumMax];
  11. uint16_T sorn_ohm_cellRSum[cmnc_num_cellUNumMax];
  12. static uint16_T sorn_V_cellU[cmnc_num_cellUNumMax];
  13. static uint8_T sorn_num_ctn;
  14. static int16_T sorn_I_curr;
  15. uint16_T i;
  16. uint16_T j;
  17. //
  18. if(sord_flg_firstRun)
  19. {
  20. sorn_num_ctn = 0;
  21. sorn_I_curr = sfmd_I_curr;
  22. memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
  23. }
  24. if(sord_flg_firstRun)
  25. {
  26. if(ArrMax(sorv_R_cellEi, cmnc_num_cellUNum) > 65000)
  27. {
  28. memset(sorn_R_cellEE,0, sizeof(sorn_R_cellEE));
  29. }
  30. else
  31. {
  32. memcpy(sorn_R_cellEE,sorv_R_cellEi, sizeof(sorv_R_cellEi));
  33. }
  34. }
  35. if(socd_pct_battSoc >= 550 && socd_pct_battSoc <= 700 && sorn_num_ctn < 5)
  36. {
  37. if(sfmd_I_curr - sorn_I_curr > 200 || sfmd_I_curr - sorn_I_curr < -200)
  38. {
  39. for(i = 0;i < cmnc_num_cellUNum;i++)
  40. {
  41. sorn_R_cellEEArr[sorn_num_ctn][i] = (uint16_T)( ((real_T)(sorn_V_cellU[i] - sfmv_V_cellU[i]) * 0.001) / ((real_T)(sorn_I_curr - sfmd_I_curr) * 0.1) * 1000000 );
  42. }
  43. sorn_num_ctn = sorn_num_ctn + 1;
  44. memset(sorn_ohm_cellRSum,0, sizeof(sorn_ohm_cellRSum));
  45. for(i = 0;i < cmnc_num_cellUNum;i++)
  46. {
  47. for(j = 0;j < sorn_num_ctn;j++)
  48. {
  49. sorn_ohm_cellRSum[i] = sorn_ohm_cellRSum[i] + sorn_R_cellEEArr[j][i];
  50. }
  51. sorn_R_cellEE[i] = sorn_ohm_cellRSum[i]/sorn_num_ctn;
  52. }
  53. }
  54. }
  55. memcpy(sorv_R_cell,sorn_R_cellEE, sizeof(sorn_R_cellEE));
  56. memcpy(sorv_R_cellEo,sorn_R_cellEE, sizeof(sorn_R_cellEE));
  57. sorn_I_curr = sfmd_I_curr;
  58. memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
  59. sord_flg_firstRun = false;
  60. }