Kaynağa Gözat

增加gearsensor;助力低bug修复

Ye Jin 1 yıl önce
ebeveyn
işleme
a738fe16a7

+ 4 - 0
User project/1.FrameLayer/Source/FSM_1st.c

@@ -24,6 +24,7 @@
 #include "torquesensor.h"
 #include "bikebrake.h"
 #include "display.h"
+#include "bikegearsensor.h"
 /******************************
  *
  *  Parameter
@@ -122,6 +123,9 @@ void SysInit_hook(void)
         
         /* Bike Brake Init */
         bikebrake_voBikeBrakeInit();
+        
+        /* Bike gearsensor Init */
+        bikegearsensor_voBikeGearsensorInit();
 
         /* Bike Cadence Init */
         cadence_voCadenceInit();

+ 6 - 2
User project/1.FrameLayer/Source/TimeTask_Event.c

@@ -28,6 +28,7 @@
 #include "power.h"
 #include "bikebrake.h"
 #include "display.h"
+#include "bikegearsensor.h"
 /******************************
  *
  *  Parameter
@@ -107,6 +108,9 @@ void  Event_1ms(void)
         /* Bike brake info update */
         bikebrake_voBikeBrakeDetect();
         
+        /* Bike Gearsensor info update */
+        bikegearsensor_voBikeGearsensorDetect();
+        
         // Tor assist cal
 
         ass_stCalIn.SOCValue = MC_RunInfo.SOC;
@@ -344,8 +348,8 @@ void Event_100ms(void)
                                              100;  
 
         /* Bike Throttle Assist */
-        //if(((bikethrottle_stBikeThrottleOut.uwThrottlePercent > 200) || Event_pvt_uwAssistCnt == 2)&& (cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stFlg.RunPermitFlg == TRUE) && (BikeBrake_blGetstate() == FALSE))
-        if((bikethrottle_stBikeThrottleOut.uwThrottlePercent > 200)  && (cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stFlg.RunPermitFlg == TRUE) && (BikeBrake_blGetstate() == FALSE))
+        //if(((bikethrottle_stBikeThrottleOut.uwThrottlePercent > 200) || Event_pvt_uwAssistCnt == 2)&& (cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stFlg.RunPermitFlg == TRUE) && (BikeBrake_blGetstate() == FALSE) && (bikegearsensor_blBikeGetState() == FALSE))
+        if((bikethrottle_stBikeThrottleOut.uwThrottlePercent > 200)  && (cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stFlg.RunPermitFlg == TRUE) && (BikeBrake_blGetstate() == FALSE) && (bikegearsensor_blBikeGetState() == FALSE))
         {
             Event_pvt_blBikeThroFlg = TRUE;
 

+ 2 - 2
User project/2.MotorDrive/Source/spdctrmode.c

@@ -599,10 +599,10 @@ void  scm_voTorqCtrMdTbs(void)
        //swTestIqref  = uart_swTorqRefNm - (((SLONG)swTmpSpdRateLpf.slY.sw.hi * cof_uwJmPu * 2 << 11) / cof_uwFluxPu);  //Q15+Q0+Q11-Q12=Q14
        
        /* Speed fluctuation compensation*/
-//        swTestIqref = uart_swTorqRefNm - swTmpSpdRateLpf.slY.sw.hi;
+        swTestIqref = uart_swTorqRefNm - swTmpSpdRateLpf.slY.sw.hi;
          
        /* Torgque observer */
-       swTestIqref  = uart_swTorqRefNm - scm_stIqLoadLpf.slY.sw.hi;
+       //swTestIqref  = uart_swTorqRefNm - scm_stIqLoadLpf.slY.sw.hi;
     }
     else
     {

+ 66 - 0
User project/3.BasicFunction/Include/bikegearsensor.h

@@ -0,0 +1,66 @@
+/**
+ * @file bikegearsensor.h
+ * @author Zhou xiong(zhouxiong9@midea.com)
+ * @brief Gear Sensor of ebike
+ * @version 0.1
+ * @date 2023-02-03
+ *
+ * @copyright Copyright (c) 2021
+ *
+ */
+/************************************************************************
+ Beginning of File, do not put anything above here except notes
+ Compiler Directives:
+*************************************************************************/
+#ifndef BIKEGEARSENSOR_H
+#define BIKEGEARSENSOR_H
+
+#include "typedefine.h"
+/****************************************
+ *
+ *          Definitions & Macros
+ *
+ ****************************************/
+#define GEARSENSOR_OUT_DEFAULT \
+    {                         \
+        0,0, FALSE              \
+    }                        // Default value
+
+/***************************************
+ *
+ *          Type  Definations
+ *
+ ***************************************/
+
+/**
+ * @brief Bike Gear Sensor out
+ *
+ */
+typedef struct
+{
+    UWORD uwDetectTimeCnt;   // Cnt of detect GPIO state change
+    UWORD uwGearSensorCnt;   // Cnt of detect GPIO state change
+    BOOL  blGearSensorOnFlg; // flag of GearSensor on or off
+} BIKE_GEARSENSOR_OUT;
+
+/*****************************************
+ *
+ *           Exported variable
+ *
+ ****************************************/
+
+/***************************************
+ *
+ *          Function  Definations
+ *
+ ***************************************/
+void bikegearsensor_voBikeGearsensorInit(void);   // api function
+void bikegearsensor_voBikeGearsensorDetect(void); // api function
+BOOL bikegearsensor_blBikeGetState(void);
+/************************************************************************/
+
+#endif
+/************************************************************************
+ End of this File (EOF):
+ Do not put anything after this part!
+*************************************************************************/

+ 5 - 5
User project/3.BasicFunction/Source/AssistCurve.c

@@ -20,7 +20,7 @@
 #include "bikebrake.h"
 #include "Cadence.h"
 #include "flash_master.h"
-
+#include "bikegearsensor.h"
 /******************************
  *
  *  Parameter
@@ -681,7 +681,7 @@ static void AssitCuvApplPerVolt(void) /* parasoft-suppress METRICS-28 "本项目
         
         
         /* Switch to ReduceCurrent FSM */
-        if((ass_stCalIn.uwcadancePer == 0) || (ass_stCalIn.uwGearSt == 0) || BikeBrake_blGetstate() == TRUE)
+        if((ass_stCalIn.uwcadancePer == 0) || (ass_stCalIn.uwGearSt == 0) || (BikeBrake_blGetstate() == TRUE) || (bikegearsensor_blBikeGetState() == TRUE))
         {
             /* When CandanceFreq=0 or BikeGear=0*/
             ass_stCalCoef.swAss2SpdCNT = 0;
@@ -775,7 +775,7 @@ static void AssitCuvApplPerVolt(void) /* parasoft-suppress METRICS-28 "本项目
         }
                  
         /* Switch to ReduceCurrent FSM */
-        if((ass_stCalIn.uwcadancePer == 0) || (ass_stCalIn.uwGearSt == 0) || BikeBrake_blGetstate() == TRUE)
+        if((ass_stCalIn.uwcadancePer == 0) || (ass_stCalIn.uwGearSt == 0) || (BikeBrake_blGetstate() == TRUE) || (bikegearsensor_blBikeGetState() == TRUE))
         {
             /* When CandanceFreq=0 or BikeGear=0*/
             ass_stCalOut.blTorqPIFlg = FALSE;
@@ -846,7 +846,7 @@ static void AssitCuvApplPerVolt(void) /* parasoft-suppress METRICS-28 "本项目
     case StopAssit:
        ass_stCalOut.swTorSpdLoopCurrentTemp = 0;
        /* Switch to Startup FSM */
-       if ((BikeBrake_blGetstate() == FALSE) && (ass_stCalIn.uwGearSt > 0))
+       if ((BikeBrake_blGetstate() == FALSE) && (bikegearsensor_blBikeGetState() == FALSE) && (ass_stCalIn.uwGearSt > 0))
        {
               if (ass_stCalIn.uwbikespeed < 449) // 0.3Hz,  (2.19m轮径下  2.36km/h )
               {
@@ -887,7 +887,7 @@ static void AssitCuvApplPerVolt(void) /* parasoft-suppress METRICS-28 "本项目
             }
         }
        
-        if ((ass_stCalCoef.sw2StopCNT > TIME_MS2CNT(3000)) || (ass_stCalIn.uwGearSt == 0) || (BikeBrake_blGetstate() == TRUE))// 3s
+        if ((ass_stCalCoef.sw2StopCNT > TIME_MS2CNT(3000)) || (ass_stCalIn.uwGearSt == 0) || (BikeBrake_blGetstate() == TRUE)|| (bikegearsensor_blBikeGetState() == TRUE))// 3s
         {
             ass_stCalCoef.sw2StopCNT = 0;
             ass_stCalCoef.blAssistflag = FALSE;            

+ 103 - 0
User project/3.BasicFunction/Source/bikegearsensor.c

@@ -0,0 +1,103 @@
+/**
+ * @file bikegearsensor.c
+ * @author Zhou xiong(zhouxiong9@midea.com)
+ * @brief Gear Sensor of ebike
+ * @version 0.1
+ * @date 2023-02-03
+ *
+ * @copyright Copyright (c) 2021
+ *
+ */
+
+/************************************************************************
+ Beginning of File, do not put anything above here except notes
+ Compiler Directives:
+*************************************************************************/
+#include "api.h"
+#include "board_config.h"
+#include "bikegearsensor.h"
+
+/******************************
+ *
+ *  Parameter
+ *
+ ******************************/
+BIKE_GEARSENSOR_OUT bikegearsensor_stBikeGearsensorOut = GEARSENSOR_OUT_DEFAULT;
+
+/***************************************************************
+ Function: bikegearsensor_voBikeGearsensorInit;
+ Description: bike light control initialization
+ Call by: functions in main loop;
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void bikegearsensor_voBikeGearsensorInit(void)
+{
+    bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
+    bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
+    bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
+}
+/***************************************************************
+ Function: bikegearsensor_voBikeGearsensorDetect;
+ Description: bike light control initialization
+ Call by: functions in main loop;
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void bikegearsensor_voBikeGearsensorDetect(void)
+{
+    if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == FALSE && (iGpio_Read(HW_GPIO_UARTTX_PIN) == 0))
+    {
+        bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
+        if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt > 10)
+        {
+            bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = TRUE;
+            bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
+            bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
+        }
+    }
+
+    if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == TRUE && (iGpio_Read(HW_GPIO_UARTTX_PIN) != 0))
+    {
+        bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
+        if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++ > 10)
+        {
+            bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
+            bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
+            bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
+        }
+    }
+
+    if(bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt !=0 )
+    {
+        bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt++;
+        if(bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt == 50)
+        {
+            bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
+            bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
+        }
+    }
+
+}
+/***************************************************************
+ Function: bikegearsensor_blBikeGetState;
+ Description: get bike gearsensor state
+ Call by: functions in main loop;
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+BOOL bikegearsensor_blBikeGetState(void)
+{
+    return bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg;
+}
+
+/*************************************************************************
+ End of this File (EOF)!
+ Do not put anything after this part!
+*************************************************************************/

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/user.h

@@ -47,7 +47,7 @@ Update Time
 #define MOTOR_WELLING_CITY_48V    0x30
 #define MOTOR_WELLING_MTB_48V     0x31
 
-#define MOTOR_ID_SEL              MOTOR_WELLING_CITY_36V    ///< syspar.h中也需要选择36V/48V系统
+#define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V    ///< syspar.h中也需要选择36V/48V系统
 
 /*======================================================================*
     Motor Parameters

+ 6 - 0
WLMCP_PACKED.ewp

@@ -2624,6 +2624,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikebrake.h</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikegearsensor.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikelight.h</name>
                 </file>
@@ -2693,6 +2696,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikebrake.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikegearsensor.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikelight.c</name>
                 </file>