123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /**
- * @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:
- *************************************************************************/
- #ifndef BIKESPEED_H
- #define BIKESPEED_H
- #include "typedefine.h"
- #include "mathtool.h"
- #ifdef __cplusplus
- extern "C" {
- #endif // __cplusplus
- /****************************************
- *
- * Definitions & Macros
- *
- ****************************************/
- #define BIKESPEED_NUMBERS_PULSES 1 // numbers of pulses per cycles
- #define BIKESPEED_START_INTERVALTIME 8000 //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 8000 //4000 //3000 // Min time of valid pulses, ms
- #define BIKESPEED_ERROR_RESETTIME 5000 // TIMER PERIOD,ms
- #define BIKESPEED_TIM_TIMERUNIT 25 // TIMER PERIOD,ms
- #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 4000 // ms
- #define BIKESPEED_POWER_ERROR_RECOVER 4000 // ms
- #define BIKESPEED_POWER_ERROR_TIMEUNIT 200 // ms
- #define BIKESPEED_KMPERH2FREQPU 190 // 1km/h to FreqPu : 1/(FBASE * ass_stParaCong.uwWheelPerimeter * 36 /1000 >> 20)
-
- #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
- 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 uwCaputureErrorCnt; // number of ERROR
- 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
- BIKESPEED_FSM bikespeed_fsm;
-
- UWORD uwCaputureOverflowMinCnt;
- UWORD uwCaputureOverflowMinCntTest;
- UWORD uwBikeForwardCnt; // Count number to calculate trip
- BOOL blUpdateTripCntFlg; // Unit the same as BIKESPEED_COF.uwMinTriptoUpdate ��need clear after update trip.
- UWORD uwOverflowfirst;
- } BIKESPEED_OUT;
- typedef struct // Input of "BikeSpdREFPI"
- {
- SLONG slSpdRefPu; // bikeSpeed reference,Q0
- SLONG slSpdFdkPu; // bikeSpeed feedback,Q0
- SWORD swIqMaxPu;
- SWORD swIqMinPu;
- } BIKESPDPI_IN;
- typedef struct
- {
- SLONG slErrorZ1;
- SLONG slIqRefPu;
- SWORD swIqRefPu;
- } BIKESPDPI_OUT;
- typedef struct
- {
- UWORD uwKpPu;
- UWORD uwKiPu;
- }BIKESPDPI_COF;
- /****************************************
- *
- * Exported variable
- *
- ****************************************/
- extern BIKESPEED_COF bikespeed_stFreGetCof;
- extern BIKESPDPI_OUT bikespeed_stPIOut;
- extern BIKESPDPI_IN bikespeed_stPIIn;
- extern BIKESPEED_OUT bikespeed_stFreGetOut;
- extern LPF_OUT bike_pvt_stCurLpf;
- /***************************************
- *
- * 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);
- void bikespeed_voPIInit(void);
- void bikespeed_voPICoef(void);
- void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out);
- /************************************************************************
- Flag Define (N/A)
- *************************************************************************/
- #ifdef __cplusplus
- }
- #endif // __cplusplus
- #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!
- *************************************************************************/
|