/** * @file bikethrottle.h * @author Wang, Zhiyu(wangzy49@midea.com) * @brief Throttle 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 BIKETHROTTLE_H #define BIKETHROTTLE_H #include "typedefine.h" typedef _Bool BOOL; /**************************************** * * Definitions & Macros * ****************************************/ #define BIKETHROTTLE_VOLTAGE_MAX_RANGE 5000 // MAX voltage of throttle sensor, mV #define BIKETHROTTLE_VOLTAGE_MIN_RANGE 0 // MIN voltage of throttle sensor, mV #define BIKETHROTTLE_VOLTAGE_FAULT_RANGE 1200 // MIN voltage of throttle sensor, mV #define BIKETHROTTLE_VOLTAGE_SEN2MCUGAIN (100 * 75 / 126) // gain of sensor output to Mcu ADC 0.01 #define BIKETHROTTLE_LPF_FRQ 20 // Hz bandwidth of LPF #define BIKETHROTTLE_LPF_DISCRETEHZ 200 // Hz T=1/f,T is used in discreting LPF s function #define BIKETHROTTLE_ERROR_TIME 2000 // ms #define BIKETHROTTLE_RECOVER_TIME 1 // ms #define BIKETHROTTLE_ERROE_TIMEUNIT 5 // ms #define BIKETHROTTLE_OUT_DEFAULT \ { \ 0, 0, 0, 0, 0, FALSE, FALSE \ } // Default value of CADENCE_OUT #define BIKETHROTTLE_COF_DEFAULT \ { \ 0, 0, 0, 0, 0, 0, 0 \ } // Default value of CADENCE_OUT #define STARTRUNSPEED 30//285-3km/h #define RESETTRUNSPEED 95//95-1km/h /*************************************** * * Type Definations * ***************************************/ /** * @brief Throttle out * */ typedef struct { // Output of " Throttle " UWORD uwThrottleVolReg; // register data of Throttle voltage UWORD uwThrottleVolPu; // Q14 Throttle voltage Pu UWORD uwThrottleVolLPFPu; // Q14 Throttle voltage Pu UWORD uwThrottlePercent; // Throttle voltage in output range % UWORD uwThrottleErrorCnt; UWORD uwThrottleRecoverCnt; UWORD uwThrottleGear; UWORD uwThrottleActPer; // Throttle voltage in output range % UWORD uwThrottleBack; BOOL blThrottleErrorFlg; // Flg of Throttle sensor flg } BIKETHROTTLE_OUT; /** * @brief Throttle coef * */ typedef struct { UWORD uwMaxThrottleVolOutputPu; // mV,the max voltage of Throttle sensor output UWORD uwMinThrottleVolOutputPu; // mV,the min voltage of Throttle sensor output UWORD uwThrottleVoFaultlPu; UWORD uwThrottleVolLPFFrq; // Hz,LPF bandwidth UWORD uwThrottleVolLPFDisFrq; // Hz,used in discreting LPF s function UWORD uwThrottleVolSen2McuGain; // gain of sensor output to Mcu ADC UWORD uwThrottleVolReg2Pu; // Gain of register to Pu SWORD uwThrottleOffsetPu; // offset of register UWORD uwThrottleErrorCnt; UWORD uwThrottleRecoverCnt; } BIKETHROTTLE_COF; /** * @brief Throttlecruise * */ #define BIKECRUISE_OUT_DEFAULT \ { \ 0, 0, 0, 0 \ } // Default value #define CRUISESETINGTIME 80 typedef struct { UWORD ThrottlekeepVault ; UWORD CruiseMode; UWORD KeepInCnt; UWORD CruisePercent ; UWORD ThrottleResetCruiseFlag ; } BIKECRUISE_COF; /**************************************** * * Exported variable * ****************************************/ extern UWORD Bikethrottle_uwDMAReg; extern BIKETHROTTLE_OUT bikethrottle_stBikeThrottleOut; extern BIKECRUISE_COF bikeCruise ; /*************************************** * * Function Definations * ***************************************/ void bikethrottle_voBikeThrottleInit(void); void bikethrottle_voBikeThrottleCof(void); void bikethrottle_voBikeThrottleADC(void); void Throttlecruise(void); /************************************************************************/ #endif /************************************************************************ End of this File (EOF): Do not put anything after this part! *************************************************************************/