Temp.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * @file Power.c
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Power of ebike
  5. * @version 0.1
  6. * @date 2021-09-29
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #include "syspar.h"
  16. #include "typedefine.h"
  17. #include "mathtool.h"
  18. #include "gd32f30x.h"
  19. #include "Temp.h"
  20. /******************************
  21. *
  22. * Parameter
  23. *
  24. ******************************/
  25. SLONG tmp_CurCalibCoef[CURCALIBNUM] = {
  26. 30224, // 0-19 Q10
  27. 53743, // 20-39
  28. 77427, // 40-59
  29. 101477, // 60-79
  30. 125143, // 80-99
  31. 149524, // 100-119
  32. 174172, // 120-139
  33. };
  34. static SWORD PCB_swRTempTab[TEMPNUM] = {
  35. 3362, // 0.01kOnm IPM voltage at 0 C
  36. 1253, // 0.01kOnm IPM voltage at 20 C
  37. 530, // 0.01kOnm IPM voltage at 40 C
  38. 248, // 0.01kOnm IPM voltage at 60 C
  39. 127, // 0.01kOnm IPM voltage at 80 C
  40. 69, // 0.01kOnm IPM voltage at 100 C
  41. 40, //120C
  42. };
  43. static SWORD PCB_swRTempCofTab[TEMPNUM] = {
  44. -10, // Q10 0-19 Coef of R
  45. -28, // Q10 20-39 Coef of R
  46. -72, // Q10 40-59 Coef of R
  47. -167, // Q10 60-79 Coef of R
  48. -349, // Q10 80-99 Coef of R
  49. -696, // Q10 100-119
  50. -1301,// Q10 120-139
  51. };
  52. /* motor NTC intercept array */
  53. SLONG q10_motor_tmp_CurCalibCoef[CURCALIBNUM] = {
  54. 112056, // 70-81 Q10
  55. 125480, // 81-91
  56. 139284, // 92-102
  57. 152248, // 103-113
  58. 166113, // 114-124
  59. 178913, // 125-135
  60. 198400, // 136-146
  61. };
  62. /* motor NTC resistance */
  63. static SWORD motor_swRTempTab[TEMPNUM] = {
  64. 223, // 0.01kOnm IPM voltage at 70 C
  65. 163, // 0.01kOnm IPM voltage at 81 C
  66. 120, // 0.01kOnm IPM voltage at 92 C
  67. 91, // 0.01kOnm IPM voltage at 103 C
  68. 69, // 0.01kOnm IPM voltage at 114 C
  69. 54, // 0.01kOnm IPM voltage at 125 C
  70. 43, //0.01kOnm IPM voltage at 136 C
  71. };
  72. /* motor NTC fitting slope array */
  73. static SWORD q10_motor_swRTempCofTab[TEMPNUM] = {
  74. -182, // Q10 70-81 Coef of R
  75. -263, // Q10 81-91 Coef of R
  76. -378, // Q10 92-102 Coef of R
  77. -519, // Q10 103-113 Coef of R
  78. -715, // Q10 114-124 Coef of R
  79. -947, //Q10 125-135
  80. -1393, //Q10 136-146
  81. };
  82. SWORD tmp_PcbTemp = 0;
  83. SWORD tmp_MotTemp = 0;
  84. /***************************************************************
  85. Function: TempInit;
  86. Description: cadence frequency get initialization
  87. Call by: functions in main loop;
  88. Input Variables: N/A
  89. Output/Return Variables: N/A
  90. Subroutine Call: N/A;
  91. Reference: N/A
  92. ****************************************************************/
  93. void TempInit(void)
  94. {
  95. #if 0
  96. UWORD CNT = 0;
  97. for (CNT = 0; CNT < (TEMPNUM - 1); CNT++)
  98. {
  99. PCB_swRTempCofTab[CNT] = ((SLONG)20 << 10) / (PCB_swRTempTab[CNT + 1] - PCB_swRTempTab[CNT]);
  100. }
  101. #endif
  102. }
  103. /***************************************************************
  104. Function: PcbTempCal;
  105. Description: Calculation of Pcb Temp using PcbR
  106. Call by: functions in main loop;
  107. Input Variables: N/A
  108. Output/Return Variables: N/A
  109. Subroutine Call: N/A;
  110. Reference: N/A
  111. ****************************************************************/
  112. #if 0
  113. void PcbTempCal(SWORD PcbR)
  114. {
  115. if (PcbR >= PCB_swRTempTab[temp_0])
  116. {
  117. tmp_PcbTemp = 0;
  118. }
  119. else if (PcbR < PCB_swRTempTab[temp_0] && PcbR >= PCB_swRTempTab[temp_20])
  120. {
  121. tmp_PcbTemp = 0 + (((PcbR - PCB_swRTempTab[temp_0]) * PCB_swRTempCofTab[temp_coef_0_20]) >> 10);
  122. }
  123. else if (PcbR < PCB_swRTempTab[temp_20] && PcbR >= PCB_swRTempTab[temp_40])
  124. {
  125. tmp_PcbTemp = 20 + (((PcbR - PCB_swRTempTab[temp_20]) * PCB_swRTempCofTab[temp_coef_20_40]) >> 10);
  126. }
  127. else if (PcbR < PCB_swRTempTab[temp_40] && PcbR >= PCB_swRTempTab[temp_60])
  128. {
  129. tmp_PcbTemp = 40 + (((PcbR - PCB_swRTempTab[temp_40]) * PCB_swRTempCofTab[temp_coef_40_60]) >> 10);
  130. }
  131. else if (PcbR < PCB_swRTempTab[temp_60] && PcbR >= PCB_swRTempTab[temp_80])
  132. {
  133. tmp_PcbTemp = 60 + (((PcbR - PCB_swRTempTab[temp_60]) * PCB_swRTempCofTab[temp_coef_60_80]) >> 10);
  134. }
  135. else if (PcbR < PCB_swRTempTab[temp_80] && PcbR >= PCB_swRTempTab[temp_100])
  136. {
  137. tmp_PcbTemp = 80 + (((PcbR - PCB_swRTempTab[temp_80]) * PCB_swRTempCofTab[temp_coef_80_100]) >> 10);
  138. }
  139. else if (PcbR < PCB_swRTempTab[temp_100])
  140. {
  141. tmp_PcbTemp = 100;
  142. }
  143. else
  144. {}
  145. }
  146. #endif
  147. /*!
  148. * @brief Fault state called in fast state machine
  149. *
  150. * @param 1)current NTC resistance 2) NTC resistance array
  151. * 3)fitting slope array 4)intercept array 5)140C correspond resistance
  152. *
  153. * @return current temperature
  154. */
  155. #if 1
  156. SWORD TempCal(SWORD PcbR, SWORD *ptemp_tab, SWORD *p_temp_coef, SLONG *p_cali_coef, SWORD temp_140)
  157. {
  158. SWORD per_temp;
  159. if (PcbR >= *(ptemp_tab+temp_0))
  160. {
  161. per_temp = 0;
  162. }
  163. else if (PcbR < *(ptemp_tab+temp_0) && PcbR >= *(ptemp_tab+temp_20))
  164. {
  165. per_temp = (PcbR * (*(p_temp_coef+temp_0)) + (*(p_cali_coef+temp_0))) >> 10;
  166. }
  167. else if (PcbR < *(ptemp_tab+temp_20) && PcbR >= *(ptemp_tab+temp_40))
  168. {
  169. per_temp = (PcbR * (*(p_temp_coef+temp_20)) + (*(p_cali_coef+temp_20))) >> 10;
  170. }
  171. else if (PcbR < *(ptemp_tab+temp_40) && PcbR >= *(ptemp_tab+temp_60))
  172. {
  173. per_temp = (PcbR * (*(p_temp_coef+temp_40)) + (*(p_cali_coef+temp_40))) >> 10;
  174. }
  175. else if (PcbR < *(ptemp_tab+temp_60) && PcbR >= *(ptemp_tab+temp_80))
  176. {
  177. per_temp = (PcbR * (*(p_temp_coef+temp_60)) + (*(p_cali_coef+temp_60))) >> 10;
  178. }
  179. else if (PcbR < *(ptemp_tab+temp_80) && PcbR >= *(ptemp_tab+temp_100))
  180. {
  181. per_temp = (PcbR * (*(p_temp_coef+temp_80)) + (*(p_cali_coef+temp_80))) >> 10;
  182. }
  183. else if (PcbR < *(ptemp_tab+temp_100) && PcbR >= *(ptemp_tab+temp_120))
  184. {
  185. per_temp = (PcbR * (*(p_temp_coef+temp_100)) + (*(p_cali_coef+temp_100))) >> 10;
  186. }
  187. else if(PcbR < *(ptemp_tab+temp_120))
  188. {
  189. per_temp = (PcbR * (*(p_temp_coef+temp_120)) + (*(p_cali_coef+temp_120))) >> 10;
  190. }
  191. else if(PcbR < temp_140)
  192. {
  193. per_temp = 150;
  194. }
  195. else
  196. {
  197. }
  198. return per_temp;
  199. }
  200. void PcbTempCal(SWORD PcbR)
  201. {
  202. tmp_PcbTemp = TempCal(PcbR, PCB_swRTempTab, PCB_swRTempCofTab, tmp_CurCalibCoef, temp_pcb_140);
  203. }
  204. void MotorTempCal(SWORD PcbR)
  205. {
  206. tmp_MotTemp = TempCal(PcbR, motor_swRTempTab, q10_motor_swRTempCofTab, q10_motor_tmp_CurCalibCoef, temp_motor_150);
  207. }
  208. #endif
  209. /*************************************************************************
  210. End of this File (EOF)!
  211. Do not put anything after this part!
  212. *************************************************************************/