Bladeren bron

1.优化功率过冲问题
2.6管过流触发70A
3.12管过流触发值80A

CN\houcf5 4 maanden geleden
bovenliggende
commit
53151e8053

+ 2 - 2
1.FrameLayer/Source/main.c

@@ -215,9 +215,9 @@ int  main(void)
 
      //---over Cur of Valut
 #if((IPM_POWER_SEL == IPM_POWER_250W_6G) ||(IPM_POWER_SEL ==IPM_POWER_350W_6G))
-     DL_COMP_setDACCode0(COMP_0_INST, 0xC7);//12G-100A-0x99-1.97V   6G-70A--0xb5-2.33V
+     DL_COMP_setDACCode0(COMP_0_INST, 0xb5);//12G-100A-0x99-1.97V   6G-70A--0xb5-2.33V
 #else
-    DL_COMP_setDACCode0(COMP_0_INST, 0x99);//12G-100A-0x99-1.97V   6G-60A--0xb5-2.33V
+    DL_COMP_setDACCode0(COMP_0_INST, 0x81);//12G-100A-0x99-1.97V   6G-60A--0xb5-2.33V
 #endif
 
 //    hw_voHardwareSetup1();

+ 0 - 269
2.MotorDrive/Include/adc.h.bak

@@ -1,269 +0,0 @@
-/************************************************************************
- Project:             Welling Motor Control Paltform
- Filename:            adc.h
- Partner Filename:    adc.c
- Description:         The header file of adc.c
- Complier:            IAR Embedded Workbench for ARM 7.80, IAR Systems.
- CPU TYPE :           GD32F3x0
-*************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
-*************************************************************************
-Revising History (ECL of this file):
-
-************************************************************************/
-
-/************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
-*************************************************************************/
-#ifndef ADCDRV_H
-#define ADCDRV_H
-
-/************************************************************************
- Compiler Directives
-*************************************************************************/
-#ifdef _ADCDRV_C_
-#define _ADCDRV_EXT
-#else
-#define _ADCDRV_EXT extern
-#endif
-
-#include "typedefine.h"
-/************************************************************************
- Definitions & Macros (#define ...)
-*************************************************************************/
-#define SR_CURRENT_MAX_BAND -147  // 0.01A
-#define SR_CURRENT_MIN_BAND -4000 // 0.01A
-/************************************************************************
- TypeDefs & Structure defines (N/A)
-*************************************************************************/
-typedef struct
-{
-    SWORD swIaPu;     // Q14, Phase A current value
-    SWORD swIbPu;     // Q14, Phase B current value
-    SWORD swIcPu;     // Q14, Phase C current value
-    SWORD swSampIaPu; // Q14, Phase A current sampling value
-    SWORD swSampIbPu; // Q14, Phase B current sampling value
-    SWORD swSampIcPu; // Q14, Phase C current sampling value
-    UWORD uwIaAbsPu;  // Q14, Phase A current absolute value
-    UWORD uwIbAbsPu;  // Q14, Phase B current absolute value
-    UWORD uwIcAbsPu;  // Q14, Phase C current absolute value
-    UWORD uwIpeakPu;  // Q14, Max value of phase current
-
-    UWORD uwIaAvgPu; // Ia register value
-    UWORD uwIbAvgPu; // Ib register value
-    UWORD uwIcAvgPu; // Ic register value
-
-    UWORD uwIaReg; // Ia register value
-    UWORD uwIbReg; // Ib register value
-    UWORD uwIcReg; // Ic register value
-
-    UWORD uwFirstCurREG;
-    UWORD uwSecondCurREG;
-
-    UWORD uwADCSector;
-
-    ULONG ulUaRegSum;  // Ua register sum value when calibrate
-    ULONG ulUbRegSum;  // Ub register sum value when calibrate
-    ULONG ulUcRegSum;  // Uc register sum value when calibrate
-    ULONG ulIdcRegSum; // Idc register sum value when calibrate
-
-    ULONG ulIaRegSum; // Ia register value
-    ULONG ulIbRegSum; // Ib register value
-    ULONG ulIcRegSum; // Ic register value
-    ULONG ulIdcAvgRegSum;
-
-    UWORD uwADCCalibCt;  // Current calib count
-    BOOL  blADCCalibFlg; // ADC calib flag
-} ADC_DOWN_OUT;
-
-typedef struct
-{
-    SWORD uwUAPu;
-    SWORD uwUBPu;
-    SWORD uwUCPu;
-    UWORD uwIbusAvgPu;    // Q14, Ibus Average
-    UWORD uwIbusAvgLpfPu; // Q14, Ibus Average after LPF
-    UWORD uwVdcPu;        // Q14, Vdc
-    UWORD uwVdcLpfPu;     // Q14, Vdc after LPF
-    UWORD uwIbusPu;        // Q14, Vdc
-    UWORD uwIbusLpfPu;     // Q14, Vdc after LPF    
-    UWORD uwU6VPu;        // Q14, 12V power
-    UWORD uwU5VPu;        // Q14, 5V power
-    UWORD uwU12VPu;       // Q14, 5V power
-    UWORD uwTrottlePu;    // Q14, 5V power
-    UWORD PCBTempR;       // Not Pu 0.1kOhm
-    UWORD MotorTempR;     // Not Pu 0.1kOhm
-    SWORD PCBTemp;        // Not Pu, centigrade
-    SWORD MotorTemp;      // Not Pu, centigrade
-    SWORD MosfestTempEst; // Not Pu, centigrade
-
-    SWORD swCalibIaPu;
-    SWORD swCalibIbPu;
-    SWORD swCalibIcPu;
-
-//    UWORD uwUAReg;
-//    UWORD uwUBReg;
-//    UWORD uwUCReg;
-    UWORD uwIbusAvgReg;  // Ibus Average register value
-    UWORD uwVdcReg;      // Vdc register value
-    UWORD uwU6VReg;      // 12 V register value
-    UWORD uwU5VReg;      // 5 V register value
-    UWORD uwU12VReg;     // Q14, 5V power
-    UWORD uwThrottleReg; // Q14, 5V power
-    UWORD PCBTempReg;
-    UWORD MotorTempReg;
-    UWORD TorqTempReg;
-    
-    UWORD uwADCCalibCt;  // Current calib count
-    BOOL  blADCCalibFlg; // ADC calib flag
-    SWORD swIPMTempCe;   // PCB Temp to trig alam
-
-    SWORD  swSampCapIaPu;
-    SWORD  swSampCapIbPu;
-} ADC_UP_OUT;
-
-typedef struct
-{
-    UWORD uwVdcReg2Pu;    // Q24, Coefficient of Vdc register value to pu value
-    UWORD uwCurReg2Pu;    // Q24, Coefficient of current register value to pu value
-    UWORD uwCurIdcReg2Pu; // Q24, Coefficient of Idc current register value to pu value
-    UWORD uwCurIdcAvgReg2Pu;
-    UWORD uwUabcReg2Pu;   // Q24, Coefficient of Ua,Ub,Uc register value to pu value
-    UWORD uwU6VReg2Pu;    // Q24, Coefficient of Ua,Ub,Uc register value to pu value
-    UWORD uwU5VReg2Pu;    // Q24, Coefficient of Ua,Ub,Uc register value to pu value
-    UWORD uwU12VReg2Pu;   // Q24, Coefficient of Ua,Ub,Uc register value to pu value
-    UWORD uwCalibcoefIA;    // Q10, Coefficient of k = single resistance/Rdson
-    UWORD uwCalibcoefIB;    // Q10, Coefficient of k = single resistance/Rdson
-    UWORD uwCalibcoefMax;
-    UWORD uwCalibcoefMin;
-
-    UWORD uwIaOffset;     // Ia offset value
-    UWORD uwIbOffset;     // Ib offset value
-    UWORD uwIcOffset;     // Ib offset value
-    UWORD uwUaOffset;     // Ua offset value
-    UWORD uwUbOffset;     // Ub offset value
-    UWORD uwUcOffset;     // Ub offset value
-    UWORD uwIdcOffset;    // Idc offset value
-    UWORD uwIdcAveOffset; // Idc offset value
-
-    SWORD swPCBTempKcof;
-    SWORD swMotorTempKcof;
-    UWORD uwCalibCoefK;
-
-} ADC_COF;
-
-
-typedef struct
-{
-      UWORD Start_Calc;
-      UWORD RdsonGainCnt;
-      UWORD RdsonGainCnt2;
-      UWORD adc_RdsonADCGainMax;
-      UWORD adc_RdsonADCGainMin;
-      UWORD adc_RdsonADCGainSum2;
-      UWORD adc_RdsonADCGainRecord[10];
-      UWORD adc_RdsonADCGainSum;
-      UWORD uwCalibcoef;
-      ULONG GainTemp;
-      UBYTE uwCalibcomplete;
-
-} ADC_SUMCOF;
-
-/************************************************************************
-Constant Table
-*************************************************************************/
-
-/************************************************************************
- Exported Variables:
-*************************************************************************/
-#ifdef _ADCDRV_C_
-_ADCDRV_EXT ADC_COF      adc_stCof;
-_ADCDRV_EXT ADC_UP_OUT   adc_stUpOut;
-_ADCDRV_EXT ADC_DOWN_OUT adc_stDownOut;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMA;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMB;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMC;
-
-//_ADCDRV_EXT UWORD Start_Calc = 0;
-//_ADCDRV_EXT UWORD RdsonGainCnt = 0;
-//_ADCDRV_EXT UWORD RdsonGainCnt2 = 0;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMax;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMin;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum2;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainRecord[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum = 0;
-_ADCDRV_EXT UWORD adc_uwADDMAPhase1;
-_ADCDRV_EXT UWORD adc_uwADDMAPhase2;
-
-_ADCDRV_EXT UWORD adc_uwRdsonUReg;
-_ADCDRV_EXT UWORD adc_uwRdsonVReg;
-_ADCDRV_EXT UWORD adc_uwRdsonWReg;
-
-_ADCDRV_EXT UWORD adc_uwIaReg;
-_ADCDRV_EXT UWORD adc_uwIbReg;
-#else
-_ADCDRV_EXT ADC_COF      adc_stCof;
-_ADCDRV_EXT ADC_UP_OUT   adc_stUpOut;
-_ADCDRV_EXT ADC_DOWN_OUT adc_stDownOut;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMA;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMB;
-_ADCDRV_EXT ADC_SUMCOF  adc_LibSUMC;
-
-//_ADCDRV_EXT UWORD Start_Calc;
-//_ADCDRV_EXT UWORD RdsonGainCnt;
-//_ADCDRV_EXT UWORD RdsonGainCnt2;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMax;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMin;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum2;
-//_ADCDRV_EXT UWORD adc_RdsonADCGainRecord[10];
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum;
-_ADCDRV_EXT UWORD adc_uwADDMAPhase1;
-_ADCDRV_EXT UWORD adc_uwADDMAPhase2;
-
-_ADCDRV_EXT UWORD adc_uwRdsonUReg;
-_ADCDRV_EXT UWORD adc_uwRdsonVReg;
-_ADCDRV_EXT UWORD adc_uwRdsonWReg;
-
-_ADCDRV_EXT UWORD adc_uwIaReg;
-_ADCDRV_EXT UWORD adc_uwIbReg;
-
-#endif
-/************************************************************************
- RAM ALLOCATION:
-*************************************************************************/
-
-/************************************************************************
- Exported Function Call Prototypes (N/A)
-*************************************************************************/
-#ifdef _ADCDRV_C_
-_ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
-_ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
-_ADCDRV_EXT void adc_voSampleInit(void);
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof , ADC_SUMCOF *Sum_out);
-#else
-_ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
-_ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
-_ADCDRV_EXT void adc_voSampleInit(void);
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof , ADC_SUMCOF *Sum_out);
-#endif
-
-/************************************************************************
- Flag Define (N/A)
-*************************************************************************/
-
-/***********************************************************************/
-#endif
-/************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
- End of this File (EOF):
- !!!!!!Do not put anything after this part!!!!!!!!!!!
-*************************************************************************/

+ 0 - 139
2.MotorDrive/Include/brake.h.bak

@@ -1,139 +0,0 @@
-/************************************************************************
- Project:             Welling Motor Control Paltform
- Filename:            brake.h
- Partner Filename:    brake.c
- Description:         The header file of brake.c
- Complier:            IAR Embedded Workbench for ARM 7.80, IAR Systems.
- CPU TYPE :           GD32F3x0
-*************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
-*************************************************************************
-Revising History (ECL of this file):
-WLBDM_M4_SR_201809071-new FSM1.1, by mz, create this file;
-************************************************************************/
-#include "typedefine.h"
-/************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
-*************************************************************************/
-#ifndef BRAKE_H
-#define BRAKE_H
-/************************************************************************
- Compiler Directives (N/A)
-*************************************************************************/
-#ifdef _BRAKE_C_
-#define BRAKE_EXT
-#else
-#define BRAKE_EXT extern
-#endif
-
-#include "typedefine.h"
-/************************************************************************
- Definitions & Macros
-*************************************************************************/
-#define BRAKE_COF_DEFAULT                                        \
-    {                                                            \
-        20154, 20400, 237, 8704, -320, -4480, 2048, 10, 10, 1365 \
-    } // Default value of DBC_CALC_COF (410V,390V,Q14(0.15),Q14(1),Q14(6.8),Q14(0.25),Q14(3.5))
-#define BRAKE_OUT_DEFAULT \
-    {                     \
-        0, 0, 0, 0, FALSE \
-    } // Default value of DBC_CALC_OUT (Q14(0),Q14(0),FALSE)
-
-/************************************************************************
-             Typedefs & Structure Defines
-*************************************************************************/
-typedef struct // Input of " cvb_stBrakeCoef "
-{
-    UWORD uwVdcCvbVt;   // Real Value, unit:0.1V,	Voltage to keep for constant voltage braking
-    SWORD swIqRefMaxAp; // Real Value, unit:0.01A,	Iq limit max value
-    SWORD swIdRefMaxAp; // Real Value, unit:0.01A,	Id reference max value
-    SWORD swIdRefMinAp; // Real Value, unit:0.01A,	Id reference min value
-    UWORD uwVBaseVt;    // Real Value, unit:0.1V,	Voltage Base
-    UWORD uwIBaseAp;    // Real Value, unit:0.01A,	Current Base
-    UWORD uwFBaseHz;    // Real Value, unit:Hz,	Frequence Base
-    UWORD uwMotorPairs; // Real Value, unit:1,	    Motor Pairs
-    UWORD uwLowSpdRpm;  // Real Value, unit:rpm,	Low speed without Id
-} BRAKE_COFIN;
-
-typedef struct // Input of " cvb_stBrakeOut "
-{
-    UWORD uwVdcLpfPu;    // Q14, unit:Pu,		DC bus voltage
-    SWORD swSpdPu;       // Q15, unit:Pu,		Current speed
-    UWORD uwSpdLpfAbsPu; // Q15, unit:Pu,		Abs of Current speed feedback
-    SWORD swIqRefPu;     // Q14, unit:Pu,		Current Iq Reference
-    SWORD swIdRefPu;     // Q14, unit:Pu,		Current Id Reference
-    SWORD uwAngelPu;     // Q15, unit:Pu,		Obs angle
-    UWORD uwSpdState;
-} BRAKE_IN;
-
-typedef struct // Input of " cvb_stBrakeOut "
-{
-    UWORD uwVdcCvbPu;      // Q14, unit:Pu,		Voltage to keep for constant voltage braking
-    UWORD uwVdcLagAngelPu; // Q14, unit:Pu,		Voltage to lag angle constant voltage braking
-    UWORD uwVdcStartCvbPu; // Q14, unit:Pu,		Voltage to start iq limit of constant voltage braking
-    UWORD uwKAnglePu;      // Q8, unit:Pu,		Coefficient of delta Angle
-    SWORD swIqLimMaxPu;    // Q14, unit:Pu,		Iq limit max value
-    SWORD swIdRefMaxPu;    // Q14, unit:Pu,		Id reference max value
-    SWORD swIdRefMinPu;    // Q14, unit:Pu,		Id reference min value
-    SWORD swKcvb;          // Q14, unit:Pu,		Constant voltage braking cofficient
-    SWORD swIdDrpPu;       // Q14, unit:Pu,     delta Id drop
-    SWORD swIdRcyPu;       // Q14, unit:Pu,     delta Id recovery
-    UWORD uwLowSpdPu;      // Q15, unit:Pu,		Low speed without Id
-} BRAKE_COF;
-
-typedef struct // Output of " cvb_stBrakeOut "
-{
-    SWORD swIqRefPu; // Q14, unit:Pu,		Q axis current reference
-    SWORD swIqLimPu; // Q14, unit:Pu,		Q axis current limit
-    SWORD swIdRefPu; // Q14, unit:Pu,		D axis current reference
-    SWORD uwAngelPu; // Q15, unit:Pu,		Obs angle after brake lag
-    BOOL  blCvbFlg;  // Bool, constant voltage braking flag
-} BRAKE_OUT;
-
-/************************************************************************
- Exported Variables
-*************************************************************************/
-#ifdef _BRAKE_C_
-BRAKE_EXT BRAKE_COF cvb_stBrakeCoef = BRAKE_COF_DEFAULT;
-BRAKE_EXT BRAKE_OUT cvb_stBrakeOut = BRAKE_OUT_DEFAULT;
-#else
-BRAKE_EXT BRAKE_COF cvb_stBrakeCoef;
-BRAKE_EXT BRAKE_OUT cvb_stBrakeOut;
-#endif
-
-/************************************************************************
- RAM ALLOCATION (N/A)
-*************************************************************************/
-#define cvb_stBrakeIn     (*(BRAKE_IN *)TBC_BUFFER)
-#define cvb_stBrakeCoefIn (*(BRAKE_COFIN *)MN_BUFFER)
-/************************************************************************
- Exported Function Call Prototypes
-*************************************************************************/
-#ifdef _BRAKE_C_
-BRAKE_EXT void cvb_voBrake(BRAKE_IN *in, BRAKE_COF *coef, BRAKE_OUT *out);
-BRAKE_EXT void cvb_voBrakeCoef(BRAKE_COFIN *in, BRAKE_COF *out);
-BRAKE_EXT void cvb_voBrakeInit();
-#else
-BRAKE_EXT void cvb_voBrake(BRAKE_IN *in, BRAKE_COF *coef, BRAKE_OUT *out);
-BRAKE_EXT void cvb_voBrakeCoef(BRAKE_COFIN *in, BRAKE_COF *out);
-BRAKE_EXT void cvb_voBrakeInit();
-#endif
-
-/************************************************************************
- Local Function Call Prototypes (N/A)
-*************************************************************************/
-
-/************************************************************************
- Flag Define (N/A)
-*************************************************************************/
-#endif
-/************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
-*************************************************************************/

+ 5 - 0
2.MotorDrive/Include/pwrlim.h

@@ -89,6 +89,9 @@ typedef struct // Input of " pwr_voPwrLim "
     SWORD swPCBTemp;    /**< PCB温度,单位:摄氏度 */
     SWORD swMotorTemp;  /**< MOTOR温度,单位:摄氏度 */
     UWORD uwBatCap;     /**< 电池电量 */
+    SWORD swMotoriqref;  /**< MOTOR温度,单位:摄氏度 */
+    SWORD swMotoriqfdb;  /**< MOTOR温度,单位:摄氏度 */
+
 } PWRLIM_IN;
 
 typedef struct // Output of " pwr_voPwrLim "
@@ -98,6 +101,8 @@ typedef struct // Output of " pwr_voPwrLim "
     SWORD swErrorZ1;               /**< 功率限制值与功率间的误差,PuQ15 */
     SLONG slIqLimDetaSum;          /**< q轴电流限制减小值,PuQ30 */
     SWORD swIqLimDetaSum;          /**< q轴电流限制减小值,PuQ14 */
+    UWORD uwfisrttime;
+    UWORD  Mortor_time;
 } PWRLIM_OUT;
 
 /************************************************************************

+ 48 - 6
2.MotorDrive/Source/pwrlim.c

@@ -65,7 +65,7 @@ Reference:
 void pwr_voPwrLimCof(PWRLIM_COFIN *in, PWRLIM_COF *out)
 {
     UWORD uwPwrLim;
-    UWORD ulPbWt;
+    ULONG ulPbWt;
 
     if (in->uwIBaseAp > 32767)
     {
@@ -228,10 +228,14 @@ void pwr_voPwrLimPI(PWRLIM_IN *in, PWRLIM_COF *cof, PWRLIM_OUT *out)
     SWORD        swERROR, swErrorDeta;
     SLONG        slERROR, slIqLimDetaP, slIqLimDetaI;
     SLONG        slIqLimSum;
+    SLONG       slIqMaxLimSum ;
     static SWORD swPCBTempCurLimitPu, swMotorTempCurLimitPu;
+    SWORD   swMotorPwriqfdb;
     SWORD        swPwrLimActualPu1 = cof->swMotorPwrLimitPu, swPwrLimActualPu2 = cof->swMotorPwrLimitPu; ///< Q15
     SWORD        swIqlimPu1 = cof->swIqMaxPu, swIqlimPu2 = cof->swIqMaxPu;                               ///< Q14
-    /* 根据温度限制功率,电机测试模式开放 */                                                         
+
+    slIqMaxLimSum=(SLONG) cof->swIqMaxPu<<16;
+    /* 根据温度限制功率,电机测试模式开放 */
     if (cp_stFlg.RunModelSelect == ClZLOOP)
     {
         if (in->swPCBTemp < cof->swPwrLimStartThresholdTemp)
@@ -313,18 +317,56 @@ void pwr_voPwrLimPI(PWRLIM_IN *in, PWRLIM_COF *cof, PWRLIM_OUT *out)
     slIqLimDetaP = (SLONG)cof->uwPwrLimPIKp * swErrorDeta; // Q15+Q15 = Q30;
     slIqLimDetaI = (SLONG)cof->uwPwrLimPIKi * swERROR;     // Q15+Q15 = Q30;
     slIqLimSum = out->slIqLimDetaSum + slIqLimDetaP + slIqLimDetaI;
-    out->slIqLimDetaSum = slIqLimSum; // Q30
+  out->slIqLimDetaSum = slIqLimSum; // Q30
+
+  //--------------------
+  if(in->swMotoriqfdb<0)
+  {
+      swMotorPwriqfdb=-in->swMotoriqfdb;
+  }
+  else
+  {
+      swMotorPwriqfdb=in->swMotoriqfdb;
+  }
+    if(pwr_stPwrLimOut2.swErrorZ1 <0)
+       {
+         if(pwr_stPwrLimOut2.uwfisrttime==0)
+         {
+           //  pwr_stPwrLimOut2.Mortor_time++;
+         //  if(pwr_stPwrLimOut2.Mortor_time>800)  //
+           {
+               pwr_stPwrLimOut2.Mortor_time=8000;
+               pwr_stPwrLimOut2.uwfisrttime=1000;
+               out->slIqLimDetaSum= ( swMotorPwriqfdb-cof->swIqMaxPu)<<16;
+           }
+         }
+
+       }
+       else
+       {
+           if(pwr_stPwrLimOut2.Mortor_time>0)
+           {
+               pwr_stPwrLimOut2.Mortor_time--;
+           }
+           else
+           {
+               pwr_stPwrLimOut2.uwfisrttime=0;
+           }
+       }
+    //---------------------
     if (out->slIqLimDetaSum > 0)
     {
         out->slIqLimDetaSum = 0;
     }
-    else if (out->slIqLimDetaSum < -1073741824)
+    else if (out->slIqLimDetaSum <-slIqMaxLimSum)// -1073741824)
     {
-        out->slIqLimDetaSum = -1073741824;
+        out->slIqLimDetaSum = -slIqMaxLimSum;//-1073741824;
     }
     else
     {}
-    out->swIqLimDetaSum = out->slIqLimDetaSum >> 16; // Q30-Q16 =Q14;
+
+
+    out->swIqLimDetaSum = out->slIqLimDetaSum >> 16; // Q30-Q16 =Q14; 
 
     swIqlimPu2 = cof->swIqMaxPu + out->swIqLimDetaSum;
 

+ 1 - 0
2.MotorDrive/Source/spdctrFSM.c

@@ -166,6 +166,7 @@ void ClzLoop_TbcupHook(void)
     pwr_stPwrLimIn.swPCBTemp = scm_stPCBTempLpf.slY.sw.hi;  
     pwr_stPwrLimIn.swMotorTemp = scm_stMotorTempLpf.slY.sw.hi;  
     pwr_stPwrLimIn.uwBatCap = MC_RunInfo.SOC;
+    pwr_stPwrLimIn.swMotoriqfdb=scm_swIqFdbLpfPu;
     pwr_voPwrLimPI(&pwr_stPwrLimIn, &pwr_stPwrLimCof, &pwr_stPwrLimOut2); // Q14
 }
 

+ 0 - 186
3.BasicFunction/Include/Cadence.h.bak

@@ -1,186 +0,0 @@
-/**
- * @file Cadence.h
- * @author Wang, Zhiyu(wangzy49@midea.com)
- * @brief Cadence 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:
-*************************************************************************/
-#ifndef CADENCE_H
-#define CADENCE_H
-#include "user.h"
-#include "typedefine.h"
-/****************************************
- *
- *          Definitions & Macros
- *
- ****************************************/
-//#if (ASSIST_MODE == TORQUE_ASSIST)
-//力矩相关参数
-#define TORQUE_NUMBERS_PULSES           38  //24   //24 48 64(350W-bike)          //numbers of pulses per cycles
-#define TORQUE_START_INTERVALTIME_MS    1000 // 250     //interveal time of detect valid pulses to start, ms
-#define TORQUE_NUMBERS_VALIDPULSE2START  1    // numbers of valid pulses that needed to start
-#define TORQUE_LF_RECORDTIME_MS         500  // time of Recording pulses per cycle, ms
-#define TORQUE_LF_MINFRE                25   // Min frequency of human foot in Low frequency method, 0.01Hz
-#define TORQUE_HF_MAXTIME_MS            150  // 3000             //Min time of valid pulses, ms
-#define TORQUE_ERROR_RESETTIME_MS       5000 // TIMER PERIOD,ms
-#define TORQUE_TIM_TIMERUNIT_US         ((SLONG)1000000/FTBS_HZ)   //25   // TIMER PERIOD,ms    us
-#define TORQUE_LPF_GAIN                 80   //%
-#define TORQUE_MAX_FREQUENCY            5    // Hz, human foot
-//#elif (ASSIST_MODE == CADENCE_ASSIST)
-//踏频相关参数
-#define CADENCE_NUMBERS_PULSES           12   //24 48 64(350W-bike)          //numbers of pulses per cycles
-#define CADENCE_START_INTERVALTIME_MS    5000 // 250     //interveal time of detect valid pulses to start, ms
-#define CADENCE_NUMBERS_VALIDPULSE2START 1    // numbers of valid pulses that needed to start
-#define CADENCE_LF_RECORDTIME_MS         500  // time of Recording pulses per cycle, ms
-#define CADENCE_LF_MINFRE                25   // Min frequency of human foot in Low frequency method, 0.01Hz
-#define CADENCE_HF_MAXTIME_MS            ((800*12)/CADENCE_NUMBERS_PULSES)  // 3000             //Min time of valid pulses, ms
-#define CADENCE_ERROR_RESETTIME_MS       5000 // TIMER PERIOD,ms
-#define CADENCE_TIM_TIMERUNIT_US         ((SLONG)1000000/FTBS_HZ)   //25   // TIMER PERIOD,ms    us
-#define CADENCE_LPF_GAIN                 80   //%
-#define CADENCE_MAX_FREQUENCY            5    // Hz, human foot
-//#endif
-
-
-
-#define CADENCE_COF_DEFAULT       \
-    {                             \
-        0, 0, 0, 0, 0, 0, 0, 0, 0 \
-    }
-#define CADENCE_OUT_DEFAULT                                               \
-    {                                                                     \
-        0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, CADENCE_DIR_IDLE, CADENCE_IDLE \
-    } // Default value of CADENCE_OUT
-
-/***************************************
- *
- *          Type  Definations
- *
- ***************************************/
-
-/**
- * @brief Cadence FSM
- *
- */
-typedef enum
-{
-    CADENCE_IDLE = 0,
-    CADENCE_LFreWork = 1,
-    CADENCE_HFreWork = 2,
-    CADENCE_BACKWOR = 3,
-    CADENCE_ERROR = 4
-} CADENCE_FSM;
-
-/**
- * @brief Cadence Direction
- *
- */
-typedef enum
-{
-    CADENCE_DIR_FORWARD = 0,
-    CADENCE_DIR_BACKWARD = 1,
-    CADENCE_DIR_IDLE = 2,
-    CADENCE_DIR_ERROR = 3
-} CADENCE_DIR;
-
-/**
- * @brief Cadence coefficient
- *
- */
-typedef struct
-{
-    UWORD uwNumbersPulses;          //公共使用脉冲数
-    UWORD uwTorque_NumbersPulses;  // numbers of Torque pulses per cycles
-    UWORD uwCad_NumbersPulses;      //numbers of cad pulses per cycles
-    UWORD uwSartIntervalTimeCnt;     // interveal time of detect valid pulses, ms
-    UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
-    UWORD uwLfRecordTimeCnt;         // time of Recording pulses per cycle, ms
-    UWORD uwLfMinFrePu;              // Min frequency of human foot in Low frequency method, 0.01Hz
-    UWORD uwHfMaxTimeCnt;            // Min time of valid pulses, ms
-    UWORD uwErrorResetCnt;           // Min time of ERROR reset, ms
-    UWORD uwTimerUnit;               // TIMER PERIOD, ms
-    UWORD uwCadenceLPFgain;          // Hz,LPF bandwidth
-    UWORD uwMaxCadenceFre;
-} CADENCE_COF;
-
-/**
- * @brief Cadence output
- *
- */
-typedef struct
-{                                        // Output of " cadence_voFreGet "
-    ULONG       ulTimer2CntErr;
-    ULONG       ulCaputureCntErr;
-    UWORD       uwFrequencyPu;           // Q20, Real value of Cadence frequecy result (human foot)
-    UWORD       uwCntErrLast;           // Q20, Real value of Cadence frequecy result (human foot)
-    UWORD       uwFrequencyLastPu;       // Q20, Real value of Cadence frequecy result (human foot)
-    UWORD       uwLPFFrequencyPu;        // Q20, Real value of Cadence frequecy result (human foot)
-    SWORD       uwLPFFrequencyPuLast;    // Q20, Real value of Cadence frequecy result (human foot)
-    UWORD       uwCaputure1Cnt;          // The cnt of the first pulse
-    UWORD       uwCaputure2Cnt;          // The cnt of the second pulse
-    UWORD       uwCaputureNumCnt;        // The current sequece of the pulse
-    UWORD       uwCaputureErrorCnt;      // The current sequece of the pulse
-    UWORD       uwCaputureOverflowCnt;   // number of TIM4 CNT Overflow between two capture
-    BOOL        blCadenceSensorErrorFlg; // The falg of sensor error
-    BOOL        blCadenceCalStartState;  // TRUE = START   FALSE = STOP
-    CADENCE_DIR cadence_dir;             // Direction of cadence
-    CADENCE_FSM cadence_fsm;
-    UWORD       uwFreqPercent; // Q14;
-    UWORD       uwForwardCnt;  // Q14;
-    UWORD       uwTaPinPortSta;
-} CADENCE_OUT;
-
-typedef struct
-{
-    UWORD uwIqCurLimitMax;
-    UWORD uwIqCurLimitMin;
-    UWORD uwbikespeedCal;
-    UWORD uwBikeSpdThresHold1;
-    UWORD uwBikeSpdThresHold2;
-    UWORD uwLimitdSpeed_S[6];
-    UWORD uwAssistLimitSpdStart[6];
-    UWORD uwAssistLimitSpdStop[6];
-    UWORD uwLimitdSpeed_E[6];
-
-}CADPOWER_STRUCT;
-
-typedef struct
-{
-    UWORD  uwPortHightcnt;
-    UWORD  uwPortLowcnt;
-    UWORD  uwPortSta;
-
-
-}CADDIR_STRUCT;
-
-#define CAD_IS_MIN_AP    500           //
-
-/****************************************
- *
- *           Exported variable
- *
- ****************************************/
-extern CADENCE_OUT cadence_stFreGetOut;
-
-/***************************************
- *
- *          Function  Definations
- *
- ***************************************/
-void cadence_voCadenceInit(void);
-void cadence_voCadenceCof(void);
-void cadence_voCadenceCal(UWORD source);
-
-/************************************************************************/
-
-#endif
-/************************************************************************
- End of this File (EOF):
- Do not put anything after this part!
-*************************************************************************/

+ 0 - 156
3.BasicFunction/Include/bikespeed.h.bak

@@ -1,156 +0,0 @@
-/**
- * @file Bikespeed.h
- * @author Wang, Zhiyu(wangzy49@midea.com)
- * @brief Speed of ebike wheel
- * @version 0.1
- * @date 2021-10-09
- *
- * @copyright Copyright (c) 2021
- *
- */
-/************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
-*************************************************************************/
-#include "mathtool.h"
-#include "typedefine.h"
-typedef _Bool  BOOL;
-#ifndef BIKESPEED_H
-#define BIKESPEED_H
-/****************************************
- *
- *          Definitions & Macros
- *
- ****************************************/
-#define BIKESPEED_NUMBERS_PULSES           1  // numbers of pulses per cycles
-#define BIKESPEED_START_INTERVALTIME_MS       10000 // interveal time of detect valid pulses, ms
-#define BIKESPEED_NUMBERS_VALIDPULSE2START 1  // numbers of valid pulses that needed to start
-#define BIKESPEED_HF_MINTIME_MS               5000  // Min time of valid pulses, ms
-#define BIKESPEED_ERROR_RESETTIME_MS          5000  // TIMER PERIOD,ms
-#define BIKESPEED_TIM_TIMERUNIT_US            ((SLONG)1000000/FTBS_HZ)    // TIMER PERIOD,us
-#define BIKESPEED_LPF_GAIN                 80    //
-#define BIKESPEED_MAX_FREQUENCY            20    // Hz, ebike wheel
-
-#define BIKESPEED_POWER_ERROR_VOLTAGE_UP   60   // 0.1v
-#define BIKESPEED_POWER_ERROR_VOLTAGE_DOWN 40   // 0.1v
-#define BIKESPEED_POWER_ERROR_DETECT_MS       4000 // ms
-#define BIKESPEED_POWER_ERROR_RECOVER_MS      4000 // ms
-#define BIKESPEED_POWER_ERROR_TIMEUNIT_MS     200  // ms
-
-#define BIKESPEED_COF_DEFAULT  \
-    {                          \
-        0, 0, 0, 0, 0, 0, 0, 0 \
-    }
-#define BIKESPEED_OUT_DEFAULT                                          \
-    {                                                                  \
-        0, 0, 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, FALSE, BIKESPEED_IDLE \
-    } // Default value of BIKESPEED_OUT
-
-/***************************************
- *
- *          Type  Definations
- *
- ***************************************/
-
-/**
- * @brief Bikespeed FSM
- *
- */
-typedef enum
-{
-    BIKESPEED_IDLE = 0,
-    BIKESPEED_WORK = 1,
-    BIKESPEED_ERROR = 3
-} BIKESPEED_FSM;
-
-/**
- * @brief Bikespeed COF
- *
- */
-typedef struct
-{
-    UWORD uwNumbersPulses;           // numbers of pulses per cycles
-    UWORD uwSartIntervalTimeCnt;     // interveal time of detect valid pulses, ms
-    UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
-    UWORD uwHfMinTimeCnt;            // Min time of valid pulses, ms
-    UWORD uwErrorResetCnt;           // Min time of ERROR reset, ms
-    UWORD uwTimerUnit;               // Timer , ms
-    UWORD uwBikeSpeedLPFGain;        // Hz,LPF bandwidth
-    UWORD uwMaxBikeSpeedFre;         //
-
-    UWORD uwBikespeedPwrErrorCnt;           // Cnt of detect GPIO low voltage
-    UWORD uwBikespeedPwrRecoverCnt;         // Cnt of detect GPIO high voltage
-    UWORD uwBikespeedPwrErrorVoltagePuDown; // flag of light error
-    UWORD uwBikespeedPwrErrorVoltagePuUp;   // flag of light error
-
-    UWORD uwWheelPerimeter;   // the back wheel Diameter 0.1 cm
-    UWORD uwMinTriptoUpdate; // the minimum trip to update m
-} BIKESPEED_COF;
-
-/**
- * @brief Bikespeed OUT
- *
- */
-typedef struct
-{
-                                // Output of " cadence_voFreGet "
-    UWORD uwFrequencyPu;         // Q20, Real value of Bike speed frequecy result
-    ULONG ulCaputureCntErr;
-    UWORD uwFrequencyPuLast;
-    SWORD swBikeSpeedFreAcc;     // Q8
-    UWORD uwLPFFrequencyPu;      // Q20, Real value of Bike speed frequecy result
-    UWORD uwCaputure1Cnt;        // The cnt of the first pulse
-    UWORD uwCaputure2Cnt;        // The cnt of the second pulse
-    UWORD uwCaputureNumCnt;      // The current sequece of the pulse
-    UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
-    UWORD uwCaputureOverflowCntLast; // number of TIM4 CNT Overflow between two capture
-    UWORD uwCaputureErrorCnt;    // number of ERROR
-    UWORD uwFreTimesCnt;    // number of frequency 1.5 or 3.0 times
-
-    UWORD uwBikespeedPwrErrorCnt;   // Cnt of detect GPIO low voltage
-    UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
-
-    BOOL          blBikeSpeedSensorErrorFlg;    // The falg of sensor error
-    BOOL          blBikeSpeedSensorPwrErrorFlg; // The falg of sensor error
-    BOOL          blBikeSpeedCalStartState;     // TRUE = START   FALSE = STOP
-    BOOL          blBikeSpeedPortState;     //
-    BOOL          blBikeSpeedPort;   //speed IO
-    BIKESPEED_FSM bikespeed_fsm;
-    
-    UWORD uwCaputureOverflowMinCnt;
-    UWORD uwBikeForwardCnt;   // Count number to calculate trip
-    BOOL  blUpdateTripCntFlg; // Unit the same as BIKESPEED_COF.uwMinTriptoUpdate ��need clear after update trip.
-    UWORD DECvnt;
-    UWORD uwBikeSpeedStopFlag;
-
-} BIKESPEED_OUT;
-
-/****************************************
- *
- *           Exported variable
- *
- ****************************************/
-extern BIKESPEED_OUT bikespeed_stFreGetOut;
-extern BIKESPEED_COF bikespeed_stFreGetCof;
-
-/***************************************
- *
- *          Function  Definations
- *
- ***************************************/
-void bikespeed_voBikeSpeedInit(void); // interface function
-void bikespeed_voBikeSpeedCof(void);
-void bikespeed_voBikeSpeedCal(UWORD source);
-void bikespeed_voGetBikeSpeedPwrError(UWORD BikeSpeedPwrVolPu);
-void bikespeed_votempTripCal(void);
-/************************************************************************
- Flag Define (N/A)
-*************************************************************************/
-#endif
-/************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
- End of this File (EOF):
- Do not put anything after this part!
-*************************************************************************/

+ 0 - 126
3.BasicFunction/Include/power.h.bak

@@ -1,126 +0,0 @@
-/**
- * @file Power.h
- * @author Wang, Zhiyu(wangzy49@midea.com)
- * @brief Power Managemant 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:
-*************************************************************************/
-#ifndef POWER_H
-#define POWER_H
-#include "typedefine.h"
-typedef _Bool  BOOL;
-/****************************************
- *
- *          Definitions & Macros
- *
- ****************************************/
-
-#define POWERMINVOLT  (250<<14)/480  //25V min volt
-
-#define POWER_START_TOUCHING_TIME 600 // ms
-#define POWER_START_FULLYON_TIME  1000 // ms
-#define POWER_SHUT_TOUCHING_TIME  20   // ms
-#define POWER_SHUT_FULLYOFF_TIME  1000   // ms
-#define POWER_ON2OFF_TIME         500 // ms
-#define POWER_START_TIMERUNIT     1    // ms
-#define POWER_SHUT_TIMERUNIT      1    // ms
-#define POWER_SHUT_STOPDELAY_TIME  (2000/POWER_SHUT_TIMERUNIT)   // ms
-
-#define POWER_OUT_DEFAULT                  \
-    {                                      \
-        0, 0, 0, FALSE, FALSE, POWER_START \
-    } // Default value of BIKELIGHT_OUT
-#define POWER_COF_DEFAULT \
-    {                     \
-        0, 0, 0, 0, 0     \
-    }
-
-#define POWER_LOCK_PORT    GPIOB // PC1
-#define POWER_LOCK_PIN    GPIO_Pin_4 // PC1
-#define POWER_SWSTATE_PORT GPIOC // PC0
-#define POWER_SWSTATE_PIN    GPIO_Pin_12 // PC1
-
-
-#define High_KEYVOL             2730  //2.2V
-#define LOW_KEYVOL              1241// 1V
-
-#define NULL_KEYMAXVOL          2730  //2.2V
-#define NULL_KEYMINVOL          2110  // 1.7V
-/***************************************
- *
- *          Type  Definations
- *
- ***************************************/
-
-/**
- * @brief Cadence FSM
- *
- */
-typedef enum
-{
-    POWER_START = 0,
-    POWER_ON = 1,
-    POWER_ON_END = 2,
-    POWER_OFF = 3,
-    POWER_OFF_END = 4
-} POWER_STATE;
-
-/**
- * @brief Cadence FSM
- *
- */
-typedef struct
-{
-    UWORD       uwPowerStartupCnt;  // Cnt of Startup
-    UWORD       uwPowerShutdnCnt;   // Cnt of Shutdown
-    UWORD       uwPowerOn2OffCnt;   // On 2 off Cnt
-    UWORD       uwPOwerForceShutdnCnt;   // Cnt of Shutdown
-    UWORD       uwPowerKeySta;   // key sta
-    UWORD       uwPowerKeyMode;   //key high or low
-    BOOL        blPowerStartupFlg;  // Flg of Startup
-    BOOL        blPowerShutdownFlg; // Flg of Shutdown
-    POWER_STATE powerstate;
-} POWER_OUT;
-
-/**
- * @brief Cadence FSM
- *
- */
-typedef struct
-{
-    UWORD uwPowerStartTouchTimeCnt; // Cnt of Startup button touching
-    UWORD uwPowerShutTouchTimeCnt;  // Cnt of Shutdown button touching
-    UWORD uwPowerStartEndCnt;       // Cnt of transfering to fully Power On
-    UWORD uwPowerShutEndCnt;        // Cnt of transfering to fully Power Off
-    UWORD uwPowerOn2OffTimeCnt;     // Cnt On 2 off Cnt
-} POWER_COF;
-
-/****************************************
- *
- *           Exported variable
- *
- ****************************************/
-
-extern POWER_OUT power_stPowStateOut;
-/***************************************
- *
- *          Function  Definations
- *
- ***************************************/
-void power_voPowerInit(void);
-void power_voPowerManagement(BOOL ParaSaveEEFlg, BOOL PowerSleepFlg);
-
-/************************************************************************/
-
-#endif
-/************************************************************************
- End of this File (EOF):
- Do not put anything after this part!
-*************************************************************************/