Browse Source

1,修改车速检测
2,修改温度表参数

Deyauo 5 months ago
parent
commit
682ae87f18

+ 49 - 38
1.FrameLayer/Source/TimeTask_Event.c

@@ -58,7 +58,7 @@ UWORD MovFiltCnt=0;
 UWORD MovFiltVault=20;
 ASS_MODE event_enMode;
 _Bool event_blCurrentAssFlag = FALSE;
-void BOKESPEED_Handler(void);
+void BIKESPEED_Handler(void);
 void TAPIN_Handler(void);
 /******************************
  *
@@ -164,8 +164,8 @@ void  Event_1ms(void)
      StartSelectAssistMode();
      if(power_stPowStateOut.powerstate == POWER_ON_END)
      {
-     BOKESPEED_Handler();
-     TAPIN_Handler();
+         BIKESPEED_Handler();
+         TAPIN_Handler();
      }
 }
 
@@ -697,7 +697,7 @@ void StartSelectAssistMode(void)
 }
 
 /***************************************************************
- Function: BOKESPEED_Handler;
+ Function: BIKESPEED_Handler;
  Description: calc bike  speed
  Call by:
  Input Variables: N/A
@@ -705,34 +705,46 @@ void StartSelectAssistMode(void)
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-void BOKESPEED_Handler(void)
+void BIKESPEED_Handler(void)
 {
 
-  /* add user code begin TMR16_GLOBAL_IRQ 0 */
-//Bike Speed
-   UWORD uwIntSource = 0;
+    /* add user code begin TMR16_GLOBAL_IRQ 0 */
+    //Bike Speed
+    UWORD uwIntSource = 0;
 
-       uwIntSource = 1;
-        /* CadenceCal and BikespeedCal */
-        bikespeed_voBikeSpeedCal(uwIntSource);
+    uwIntSource = 1;
+    /* CadenceCal and BikespeedCal */
+    bikespeed_voBikeSpeedCal(uwIntSource);
 
-       if(adc_stUpOut.MotorTempReg>1241 )// 1241=1V
-       {
-           bikespeed_stFreGetOut.blBikeSpeedPort=TRUE;
-       }
-       else if(adc_stUpOut.MotorTempReg<372)//372-0.3V
-       {
-           bikespeed_stFreGetOut.blBikeSpeedPort=FALSE;
-       }
-       if(bikespeed_stFreGetOut.blBikeSpeedPort !=bikespeed_stFreGetOut.blBikeSpeedPortState)
-      {
+#if 1 //中置,速度传感器独立IO
+    if(Get_Speed_PORT() == RESET)
+    {
+        bikespeed_stFreGetOut.blBikeSpeedPort=FALSE;
+    }
+    else
+    {
+        bikespeed_stFreGetOut.blBikeSpeedPort=TRUE;
+    }
+#else //轮毂,速度和电机温度复用
+    if(adc_stUpOut.MotorTempReg>1241 )// 1241=1V
+    {
+       bikespeed_stFreGetOut.blBikeSpeedPort=TRUE;
+    }
+    else if(adc_stUpOut.MotorTempReg<372)//372-0.3V
+    {
+       bikespeed_stFreGetOut.blBikeSpeedPort=FALSE;
+    }
+#endif
+
+    if(bikespeed_stFreGetOut.blBikeSpeedPort !=bikespeed_stFreGetOut.blBikeSpeedPortState)
+    {
         bikespeed_stFreGetOut.blBikeSpeedPortState=bikespeed_stFreGetOut.blBikeSpeedPort;
-           if(bikespeed_stFreGetOut.blBikeSpeedPortState != FALSE )
-           {
-               uwIntSource = 3;
-               bikespeed_voBikeSpeedCal(uwIntSource);
-           }
-      }
+        if(bikespeed_stFreGetOut.blBikeSpeedPortState != FALSE )
+        {
+            uwIntSource = 3;
+            bikespeed_voBikeSpeedCal(uwIntSource);
+        }
+    }
 
 }
 /***************************************************************
@@ -748,28 +760,27 @@ UWORD cadcntcal=0;
 //UWORD uwTaPinPortSta=2;
 void TAPIN_Handler(void)
 {
-  /* add user code begin TMR17_GLOBAL_IRQ 0 */
-  //韪忛牷
-  UWORD uwIntSource = 0;
+    /* add user code begin TMR17_GLOBAL_IRQ 0 */
+
+    UWORD uwIntSource = 0;
 
-   uwIntSource = 1;
-   /* CadenceCal and BikespeedCal */
+    uwIntSource = 1;
+    /* CadenceCal and BikespeedCal */
     cadence_voCadenceCal(uwIntSource);
 
     if(Get_CAD_FRE_PORT() == RESET)
-      {
+    {
         if(cadence_stFreGetOut.uwTaPinPortSta!=0)
         {
             cadence_stFreGetOut.uwTaPinPortSta =0;
-          uwIntSource = 2;
-          cadence_voCadenceCal(uwIntSource);
-          cadcntcal++;
+            uwIntSource = 2;
+            cadence_voCadenceCal(uwIntSource);
+            cadcntcal++;
         }
-      }
+    }
     else
     {
         cadence_stFreGetOut.uwTaPinPortSta =1;
     }
 
-
 }

+ 28 - 34
2.MotorDrive/Source/adc.c

@@ -366,51 +366,45 @@ void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out)
     out->uwU5VPu = (SLONG)out->uwU5VReg * cof->uwU5VReg2Pu >> 10;    // Q14=Q24-Q10;
     out->uwU12VPu = (SLONG)out->uwU12VReg * cof->uwU12VReg2Pu >> 10; // Q14=Q24-Q10;
 
-    /* PCB温度采样:注意与车速信号共用一根线,需要在高电平时采样 */
+    /* 温度采样 */
     switch(ubTempCalType)
     {
         case 0:		//PCB_TEMP
-            out->PCBTempR = (ULONG)4096 * PCB_TEMP_SAMPLER / out->PCBTempReg - PCB_TEMP_SAMPLER; // Q14=Q24-Q10;
-             PcbTempCal(out->PCBTempR);
-            out->PCBTemp = tmp_PcbTemp;
-    #if(MOTOR_TEMP_DETECT == 1)
+            if(out->PCBTempReg !=0 )
+            {
+                out->PCBTempR = (ULONG)4096 * PCB_TEMP_SAMPLER / out->PCBTempReg - PCB_TEMP_SAMPLER; // Q14=Q24-Q10;
+                PcbTempCal(out->PCBTempR);
+                out->PCBTemp = tmp_PcbTemp;
+            }
+            #if(MOTOR_TEMP_DETECT == 1)
             ubTempCalType = 1;
-    #else
+            #else
             ubTempCalType = 0;
             out->MotorTemp = tmp_PcbTemp;
-    #endif
-        break;
+            #endif
+            break;
         case 1:		//MOTOR_TEMP
-           if( out->MotorTempReg>1241)//1241-1V if(Get_MOTTEMP_PORT()!=0)//(iGpio_Read(HW_GPIO_MOTTEMP_PIN) != 0)
-            {	
-                if(ulDelayTimes++ > 30000)					/* prevent overflow */
-                {
-                    ulDelayTimes = 30000;	
-                }
-                if((ulDelayTimes > 50 && ulDelayTimes < 70) || (ulDelayTimes >= 20000))	/* remove signal rise and fall influence */
-                {
-                    out->MotorTempR = ((ULONG)MOTOR_TEMP_AD_VCC * out->MotorTempReg * (MOTOR_TEMP_R1 + MOTOR_TEMP_R2) - MOTOR_TEMP_VCC * 4096 * MOTOR_TEMP_R2) / (MOTOR_TEMP_VCC * 4096 - 33 * out->MotorTempReg);
-                    MotorTempCal(out->MotorTempR);
-                    if(tmp_MotTemp > (out->MotorTemp+2))
-                    {
-                        out->MotorTemp = out->MotorTemp + 2;
-                    }
-                    else if((tmp_MotTemp+2)<out->MotorTemp)
-                    {
-                        out->MotorTemp = out->MotorTemp - 2;
-                    }
-                    else
-                    {
-                        out->MotorTemp = tmp_MotTemp;	
-                    } 
-                }
+            if(out->MotorTempReg < 2730) //Rt 大于2KΩ,按2KΩ处理
+                out->MotorTempR = ((ULONG)out->MotorTempReg * MOTOR_TEMP_R1 ) / (4096 - out->MotorTempReg);
+            else
+                out->MotorTempR = 200;
+            MotorTempCal(out->MotorTempR);
+            if(tmp_MotTemp > (out->MotorTemp + 2))
+            {
+                out->MotorTemp = out->MotorTemp + 2;
+            }
+            else if((tmp_MotTemp + 2) < out->MotorTemp)
+            {
+                out->MotorTemp = out->MotorTemp - 2;
             }
             else
             {
-                ulDelayTimes = 0;	
+                out->MotorTemp = tmp_MotTemp;
             }
+
             ubTempCalType = 0;
-        break;
+            break;
+        default:break;
     }
     
      ////////////////// Single Resitance Current Sample//////////////////////////////////////////////////////
@@ -451,7 +445,7 @@ void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out)
  Reference: N/A
 ****************************************************************/
 SWORD swSingleReg,swRdsonReg;
- UWORD uwCalGainflg;
+UWORD uwCalGainflg;
  
 void adc_voSRCalibration(ADC_COF *cof , ADC_SUMCOF *Sum_out)
 {

+ 2 - 5
3.BasicFunction/Include/Temp.h

@@ -28,10 +28,7 @@ WLBDM_M0_SR_20170814-new FSM1.1, by cyf, create this file;
 
 #define MOTOR_TEMP_DETECT	1		//
 
-#define MOTOR_TEMP_R1	 	150	//0.01K
-#define MOTOR_TEMP_R2	 	82		//0.01k
-#define MOTOR_TEMP_VCC		51		//0.1V  PCB霍尔板供电电压大约5.1V
-#define MOTOR_TEMP_AD_VCC 	33		//0.1V
+#define MOTOR_TEMP_R1	 	100	    //0.01K
 
 #define TEMPNUM          	8
 #define CURCALIBNUM      	8
@@ -56,7 +53,7 @@ WLBDM_M0_SR_20170814-new FSM1.1, by cyf, create this file;
 #define temp_100 5
 #define temp_120 6
 
-#define temp_motor_150 	31
+#define temp_motor_150 	21
 #define temp_pcb_140 	25
 
 #define temp_coef_0_20   0

+ 41 - 40
3.BasicFunction/Source/Temp.c

@@ -26,25 +26,25 @@
  ******************************/
 //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
+    10017, // -20~0
+    32891, // 0-19      Q10
+    55994, // 20-39
+    79315, // 40-59
+    102904, // 60-79
+    126058, // 80-99
+    151406,  // 100-119
+    179931,  // 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
+    3318, // 0.01kOnm IPM voltage at 0 C
+    1252, // 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
+    247,  // 0.01kOnm IPM voltage at 60 C
+    125,  // 0.01kOnm IPM voltage at 80 C
+    67,   // 0.01kOnm IPM voltage at 100 C
+    39,   //120C , 25 at 140 C
 };
  //K
 static SWORD PCB_swRTempCofTab[TEMPNUM] = {
@@ -52,40 +52,41 @@ static SWORD PCB_swRTempCofTab[TEMPNUM] = {
     -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
+    -168, // Q10  60-79 Coef of R
+    -353, // Q10  80-99 Coef of R
+    -731,   //Q10 100-119
+    -1463,  //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
+    108660, // 70-81        Q10
+    120804, // 81-91
+    135836, // 92-102
+    146552, // 103-113
+    162816, // 114-124
+    182711,  // 125-135
+    185344,  // 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
+    174, // 0.01kOnm IPM voltage at 70 C
+    121, // 0.01kOnm IPM voltage at 81 C
+    85,  // 0.01kOnm IPM voltage at 92 C
+    62,  // 0.01kOnm IPM voltage at 103 C
+    45,  // 0.01kOnm IPM voltage at 114 C
+    34,   // 0.01kOnm IPM voltage at 125 C
+    27,   //0.01kOnm IPM voltage at 136 C, 21 at 146 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
+    -213,  // Q10  70-81 Coef of R
+    -313,  // Q10  81-91 Coef of R
+    -490,  // Q10  92-102 Coef of R
+    -663, // Q10  103-113 Coef of R
+    -1024, // Q10  114-124 Coef of R
+    -1609,   //Q10 125-135
+    -1707,  //Q10 136-146
 };
 
 SWORD tmp_PcbTemp = 0;
@@ -170,7 +171,7 @@ SWORD TempCal(SWORD PcbR, SWORD *ptemp_tab, SWORD *p_temp_coef, SLONG *p_cali_co
     SWORD per_temp;
     if (PcbR >= *(ptemp_tab+temp_0))
     {
-        per_temp = 0;
+        per_temp = 70;
     }
     else if (PcbR < *(ptemp_tab+temp_0) && PcbR >= *(ptemp_tab+temp_20))
     {

+ 1 - 0
4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/UserGpio_Config.h

@@ -33,6 +33,7 @@
 #define Get_CAD_DIR_PORT()              DL_GPIO_readPins(INPUT_Cadence_Dir_PORT, INPUT_Cadence_Dir_PIN)//  (GPIOB->idt &GPIO_PINS_9) // CAD
 #define Get_CAD_FRE_PORT()              DL_GPIO_readPins(INPUT_Cadence_Speed_PORT, INPUT_Cadence_Speed_PIN)//  (GPIOB->idt &GPIO_PINS_9) // CAD
 
+#define Get_Speed_PORT()                DL_GPIO_readPins(INPUT_Speed_In_PORT, INPUT_Speed_In_PIN)
 
 /* 前灯IO on/off */
 #define IO_FORWARDLED_ON()       1 // DL_GPIO_setPins(LIGHT_DETECT_FRONT_PORT, LIGHT_DETECT_FRONT_PIN)//   ( GPIOC->scr = GPIO_PINS_15 )  //PC15 璐熸帶