/** * @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 /**************************************** * * Definitions & Macros * ****************************************/ #define CADENCE_NUMBERS_PULSES 64 //numbers of pulses per cycles #define CADENCE_START_INTERVALTIME 1000 //unit: ms, interveal time of detect valid pulses to start #define CADENCE_NUMBERS_VALIDPULSE2START 1 //numbers of valid pulses that needed to start #define CADENCE_LF_RECORDTIME 500 //unit: ms, time of Recording pulses per cycle #define CADENCE_LF_MINFRE 25 //unit: 0.01Hz, Min frequency of human foot in Low frequency method #define CADENCE_HF_MAXTIME 200 //unit: ms, Min time of valid pulses #define CADENCE_ERROR_RESETTIME 5000 //unit: ms #define CADENCE_TIM_TIMERUNIT 25 //unit: ms, TIMER PERIOD #define CADENCE_LPF_GAIN 80 //unit: % #define CADENCE_MAX_FREQUENCY 5 //unit: Hz, human foot #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 #define CADENCESPEED_KMPERH2FREQPU 299 // 200 ms per between two interupte /*************************************** * * 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; // 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 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 " UWORD uwFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot) UWORD uwLPFFrequencyPu; // 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 uwOverflowfirst; } CADENCE_OUT; /**************************************** * * 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! *************************************************************************/