bikethrottle.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file bikethrottle.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Throttle of ebike
  5. * @version 0.1
  6. * @date 2021-09-29
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef BIKETHROTTLE_H
  16. #define BIKETHROTTLE_H
  17. /****************************************
  18. *
  19. * Definitions & Macros
  20. *
  21. ****************************************/
  22. #define BIKETHROTTLE_VOLTAGE_MAX_RANGE 4500 // MAX voltage of throttle sensor, mV
  23. #define BIKETHROTTLE_VOLTAGE_MIN_RANGE 0 //100 // MIN voltage of throttle sensor, mV
  24. #define BIKETHROTTLE_VOLTAGE_FAULT_RANGE 1200 // MIN voltage of throttle sensor, mV
  25. #define BIKETHROTTLE_VOLTAGE_SEN2MCUGAIN (100 * 3 / 5) // gain of sensor output to Mcu ADC 0.01
  26. #define BIKETHROTTLE_LPF_FRQ 10 // Hz bandwidth of LPF
  27. #define BIKETHROTTLE_LPF_DISCRETEHZ 100 // Hz T=1/f,T is used in discreting LPF s function
  28. #define BIKETHROTTLE_ERROR_TIME 2000 // ms
  29. #define BIKETHROTTLE_RECOVER_TIME 2000 // ms
  30. #define BIKETHROTTLE_ERROE_TIMEUNIT 5 // ms
  31. #define BIKETHROTTLE_STARTRUNSPEED 60//6km/h
  32. #define BIKETHROTTLE_OUT_DEFAULT \
  33. { \
  34. 0, 0, 0, 0, 0, 0, FALSE \
  35. } // Default value of CADENCE_OUT
  36. #define BIKETHROTTLE_COF_DEFAULT \
  37. { \
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  39. } // Default value of CADENCE_OUT
  40. /***************************************
  41. *
  42. * Type Definations
  43. *
  44. ***************************************/
  45. /**
  46. * @brief Throttle out
  47. *
  48. */
  49. typedef struct
  50. { // Output of " Throttle "
  51. UWORD uwThrottleVolReg; // register data of Throttle voltage
  52. UWORD uwThrottleVolPu; // Q14 Throttle voltage Pu
  53. UWORD uwThrottleVolLPFPu; // Q14 Throttle voltage Pu
  54. UWORD uwThrottlePercent; // Throttle voltage in output range %
  55. UWORD uwThrottleErrorCnt;
  56. UWORD uwThrottleRecoverCnt;
  57. BOOL blThrottleErrorFlg; // Flg of Throttle sensor flg
  58. } BIKETHROTTLE_OUT;
  59. /**
  60. * @brief Throttle coef
  61. *
  62. */
  63. typedef struct
  64. {
  65. UWORD uwMaxThrottleVolOutputPu; // mV,the max voltage of Throttle sensor output
  66. UWORD uwMinThrottleVolOutputPu; // mV,the min voltage of Throttle sensor output
  67. UWORD uwThrottleVoFaultlPu;
  68. UWORD uwThrottleVolLPFFrq; // Hz,LPF bandwidth
  69. UWORD uwThrottleVolLPFDisFrq; // Hz,used in discreting LPF s function
  70. UWORD uwThrottleVolSen2McuGain; // gain of sensor output to Mcu ADC
  71. UWORD uwThrottleVolReg2Pu; // Gain of register to Pu
  72. UWORD uwThrottleOffsetPu; // offset of register
  73. UWORD uwThrottleErrorCnt;
  74. UWORD uwThrottleRecoverCnt;
  75. } BIKETHROTTLE_COF;
  76. /**
  77. * @brief Throttlecruise
  78. *
  79. */
  80. #define BIKECRUISE_OUT_DEFAULT \
  81. { \
  82. 0, 0, 0, 0 \
  83. } // Default value
  84. #define CRUISESETINGTIME 8000
  85. typedef struct
  86. {
  87. UWORD ThrottlekeepVault ;
  88. UWORD CruiseMode;
  89. ULONG KeepInTime;
  90. UWORD CruisePercent ;
  91. UWORD ThrottleResetCruiseFlag ;
  92. } BIKECRUISE_COF;
  93. /****************************************
  94. *
  95. * Exported variable
  96. *
  97. ****************************************/
  98. extern BIKETHROTTLE_OUT bikethrottle_stBikeThrottleOut;
  99. /***************************************
  100. *
  101. * Function Definations
  102. *
  103. ***************************************/
  104. void bikethrottle_voBikeThrottleInit(void);
  105. void bikethrottle_voBikeThrottleCof(void);
  106. void bikethrottle_voBikeThrottleADC(void);
  107. void bikethrottle_voThrottlecruise(void);
  108. void bikethrottle_voStartAllow(void);
  109. /************************************************************************/
  110. #endif
  111. /************************************************************************
  112. End of this File (EOF):
  113. Do not put anything after this part!
  114. *************************************************************************/