/** * @file Power.c * @author Wang, Zhiyu(wangzy49@midea.com) * @brief Power of ebike * @version 0.1 * @date 2021-09-29 * * @copyright Copyright (c) 2021 * */ /************************************************************************ Beginning of File, do not put anything above here except notes Compiler Directives: *************************************************************************/ #include "syspar.h" #include "typedefine.h" #include "mathtool.h" //#include "at32f421.h"//#include "stm32f10x.h" #include "Temp.h" /****************************** * * Parameter * ******************************/ //b SLONG tmp_CurCalibCoef[CURCALIBNUM] ={ 8008, // -20~0 30224, // 0-19 Q10 53743, // 20-39 77427, // 40-59 101477, // 60-79 125143, // 80-99 149524, // 100-119 174172, // 120-139 }; //value static SWORD PCB_swRTempTab[TEMPNUM] = { 10102, // 0.01kOnm IPM voltage at -20 C 3362, // 0.01kOnm IPM voltage at 0 C 1253, // 0.01kOnm IPM voltage at 20 C 530, // 0.01kOnm IPM voltage at 40 C 248, // 0.01kOnm IPM voltage at 60 C 127, // 0.01kOnm IPM voltage at 80 C 69, // 0.01kOnm IPM voltage at 100 C 40, //120C }; //K static SWORD PCB_swRTempCofTab[TEMPNUM] = { -3, // Q10 -20~-1 Coef of R -10, // Q10 0-19 Coef of R -28, // Q10 20-39 Coef of R -72, // Q10 40-59 Coef of R -167, // Q10 60-79 Coef of R -349, // Q10 80-99 Coef of R -696, //Q10 100-119 -1301, //Q10 120-139 }; /* motor NTC intercept array */ SLONG q10_motor_tmp_CurCalibCoef[CURCALIBNUM] = { 113172, // 70-81 Q10 126361, // 81-91 139612, // 92-102 151296, // 103-113 166287, // 114-124 179722, // 125-135 195184, // 136-146 }; /* motor NTC resistance */ static SWORD motor_swRTempTab[TEMPNUM] = { 223, // 0.01kOnm IPM voltage at 70 C 163, // 0.01kOnm IPM voltage at 81 C 120, // 0.01kOnm IPM voltage at 92 C 90, // 0.01kOnm IPM voltage at 103 C 69, // 0.01kOnm IPM voltage at 114 C 53, // 0.01kOnm IPM voltage at 125 C 41, //0.01kOnm IPM voltage at 136 C }; /* motor NTC fitting slope array */ static SWORD q10_motor_swRTempCofTab[TEMPNUM] = { -186, // Q10 70-81 Coef of R -267, // Q10 81-91 Coef of R -377, // Q10 92-102 Coef of R -525, // Q10 103-113 Coef of R -718, // Q10 114-124 Coef of R -970, //Q10 125-135 -1340, //Q10 136-146 }; SWORD tmp_PcbTemp = 0; SWORD tmp_MotTemp = 0; /*************************************************************** Function: TempInit; Description: cadence frequency get initialization Call by: functions in main loop; Input Variables: N/A Output/Return Variables: N/A Subroutine Call: N/A; Reference: N/A ****************************************************************/ void TempInit(void) { #if 0 UWORD CNT = 0; for (CNT = 0; CNT < (TEMPNUM - 1); CNT++) { PCB_swRTempCofTab[CNT] = ((SLONG)20 << 10) / (PCB_swRTempTab[CNT + 1] - PCB_swRTempTab[CNT]); } #endif } /*************************************************************** Function: PcbTempCal; Description: Calculation of Pcb Temp using PcbR Call by: functions in main loop; Input Variables: N/A Output/Return Variables: N/A Subroutine Call: N/A; Reference: N/A ****************************************************************/ #if 0 void PcbTempCal(SWORD PcbR) { if (PcbR >= PCB_swRTempTab[temp_0]) { tmp_PcbTemp = 0; } else if (PcbR < PCB_swRTempTab[temp_0] && PcbR >= PCB_swRTempTab[temp_20]) { tmp_PcbTemp = 0 + (((PcbR - PCB_swRTempTab[temp_0]) * PCB_swRTempCofTab[temp_coef_0_20]) >> 10); } else if (PcbR < PCB_swRTempTab[temp_20] && PcbR >= PCB_swRTempTab[temp_40]) { tmp_PcbTemp = 20 + (((PcbR - PCB_swRTempTab[temp_20]) * PCB_swRTempCofTab[temp_coef_20_40]) >> 10); } else if (PcbR < PCB_swRTempTab[temp_40] && PcbR >= PCB_swRTempTab[temp_60]) { tmp_PcbTemp = 40 + (((PcbR - PCB_swRTempTab[temp_40]) * PCB_swRTempCofTab[temp_coef_40_60]) >> 10); } else if (PcbR < PCB_swRTempTab[temp_60] && PcbR >= PCB_swRTempTab[temp_80]) { tmp_PcbTemp = 60 + (((PcbR - PCB_swRTempTab[temp_60]) * PCB_swRTempCofTab[temp_coef_60_80]) >> 10); } else if (PcbR < PCB_swRTempTab[temp_80] && PcbR >= PCB_swRTempTab[temp_100]) { tmp_PcbTemp = 80 + (((PcbR - PCB_swRTempTab[temp_80]) * PCB_swRTempCofTab[temp_coef_80_100]) >> 10); } else if (PcbR < PCB_swRTempTab[temp_100]) { tmp_PcbTemp = 100; } else {} } #endif /*! * @brief Fault state called in fast state machine * * @param 1)current NTC resistance 2) NTC resistance array * 3)fitting slope array 4)intercept array 5)140C correspond resistance * * @return current temperature */ #if 1 SWORD TempCal(SWORD PcbR, SWORD *ptemp_tab, SWORD *p_temp_coef, SLONG *p_cali_coef, SWORD temp_140) { SWORD per_temp; if (PcbR >= *(ptemp_tab+temp_0)) { per_temp = 0; } else if (PcbR < *(ptemp_tab+temp_0) && PcbR >= *(ptemp_tab+temp_20)) { per_temp = (PcbR * (*(p_temp_coef+temp_0)) + (*(p_cali_coef+temp_0))) >> 10; } else if (PcbR < *(ptemp_tab+temp_20) && PcbR >= *(ptemp_tab+temp_40)) { per_temp = (PcbR * (*(p_temp_coef+temp_20)) + (*(p_cali_coef+temp_20))) >> 10; } else if (PcbR < *(ptemp_tab+temp_40) && PcbR >= *(ptemp_tab+temp_60)) { per_temp = (PcbR * (*(p_temp_coef+temp_40)) + (*(p_cali_coef+temp_40))) >> 10; } else if (PcbR < *(ptemp_tab+temp_60) && PcbR >= *(ptemp_tab+temp_80)) { per_temp = (PcbR * (*(p_temp_coef+temp_60)) + (*(p_cali_coef+temp_60))) >> 10; } else if (PcbR < *(ptemp_tab+temp_80) && PcbR >= *(ptemp_tab+temp_100)) { per_temp = (PcbR * (*(p_temp_coef+temp_80)) + (*(p_cali_coef+temp_80))) >> 10; } else if (PcbR < *(ptemp_tab+temp_100) && PcbR >= *(ptemp_tab+temp_120)) { per_temp = (PcbR * (*(p_temp_coef+temp_100)) + (*(p_cali_coef+temp_100))) >> 10; } else if(PcbR < *(ptemp_tab+temp_120)) { per_temp = (PcbR * (*(p_temp_coef+temp_120)) + (*(p_cali_coef+temp_120))) >> 10; } else if(PcbR < temp_140) { per_temp = 150; } else { } return per_temp; } //PCB Temp SWORD PCBTempCal(UWORD PcbR, SWORD *ptemp_tab, SWORD *p_temp_coef, SLONG *p_cali_coef, SWORD temp_140) { SWORD per_temp; if (PcbR >= *(ptemp_tab+PCBtemp_N20)) { per_temp = -20; } else if (PcbR < *(ptemp_tab+PCBtemp_N20) && PcbR >= *(ptemp_tab+PCBtemp_0)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_N20)) + (*(p_cali_coef+PCBtemp_N20))) >> 10; //-20~0 } else if (PcbR < *(ptemp_tab+PCBtemp_0) && PcbR >= *(ptemp_tab+PCBtemp_20)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_0)) + (*(p_cali_coef+PCBtemp_0))) >> 10;//0-20 } else if (PcbR < *(ptemp_tab+PCBtemp_20) && PcbR >= *(ptemp_tab+PCBtemp_40)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_20)) + (*(p_cali_coef+PCBtemp_20))) >> 10;//20-40 } else if (PcbR < *(ptemp_tab+PCBtemp_40) && PcbR >= *(ptemp_tab+PCBtemp_60)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_40)) + (*(p_cali_coef+PCBtemp_40))) >> 10;//40-60 } else if (PcbR < *(ptemp_tab+PCBtemp_60) && PcbR >= *(ptemp_tab+PCBtemp_80)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_60)) + (*(p_cali_coef+PCBtemp_60))) >> 10;//60-80 } else if (PcbR < *(ptemp_tab+PCBtemp_80) && PcbR >= *(ptemp_tab+PCBtemp_100)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_80)) + (*(p_cali_coef+PCBtemp_80))) >> 10;// 80-100 } else if (PcbR < *(ptemp_tab+PCBtemp_100) && PcbR >= *(ptemp_tab+PCBtemp_120)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_100)) + (*(p_cali_coef+PCBtemp_100))) >> 10;// 100-120 } else if(PcbR < *(ptemp_tab+PCBtemp_120)) { per_temp = (PcbR * (*(p_temp_coef+PCBtemp_120)) + (*(p_cali_coef+PCBtemp_120))) >> 10; } else if(PcbR < temp_140) { per_temp = 150; } else { } return per_temp; } void PcbTempCal(UWORD PcbR) { tmp_PcbTemp = PCBTempCal(PcbR, PCB_swRTempTab, PCB_swRTempCofTab, tmp_CurCalibCoef, temp_pcb_140); } void MotorTempCal(SWORD PcbR) { tmp_MotTemp = TempCal(PcbR, motor_swRTempTab, q10_motor_swRTempCofTab, q10_motor_tmp_CurCalibCoef, temp_motor_150); } #endif /************************************************************************* End of this File (EOF)! Do not put anything after this part! *************************************************************************/