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