/** * @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! *************************************************************************/