bikethrottle.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_RESETTRUNSPEEDPU 190//190-1km/h
  33. #define BIKETHROTTLE_OUT_DEFAULT \
  34. { \
  35. 0, 0, 0, 0, 0, 0, FALSE \
  36. } // Default value of CADENCE_OUT
  37. #define BIKETHROTTLE_COF_DEFAULT \
  38. { \
  39. 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  40. } // Default value of CADENCE_OUT
  41. /***************************************
  42. *
  43. * Type Definations
  44. *
  45. ***************************************/
  46. /**
  47. * @brief Throttle out
  48. *
  49. */
  50. typedef struct
  51. { // Output of " Throttle "
  52. UWORD uwThrottleVolReg; // register data of Throttle voltage
  53. UWORD uwThrottleVolPu; // Q14 Throttle voltage Pu
  54. UWORD uwThrottleVolLPFPu; // Q14 Throttle voltage Pu
  55. UWORD uwThrottlePercent; // Throttle voltage in output range %
  56. UWORD uwThrottleErrorCnt;
  57. UWORD uwThrottleRecoverCnt;
  58. BOOL blThrottleErrorFlg; // Flg of Throttle sensor flg
  59. } BIKETHROTTLE_OUT;
  60. /**
  61. * @brief Throttle coef
  62. *
  63. */
  64. typedef struct
  65. {
  66. UWORD uwMaxThrottleVolOutputPu; // mV,the max voltage of Throttle sensor output
  67. UWORD uwMinThrottleVolOutputPu; // mV,the min voltage of Throttle sensor output
  68. UWORD uwThrottleVoFaultlPu;
  69. UWORD uwThrottleVolLPFFrq; // Hz,LPF bandwidth
  70. UWORD uwThrottleVolLPFDisFrq; // Hz,used in discreting LPF s function
  71. UWORD uwThrottleVolSen2McuGain; // gain of sensor output to Mcu ADC
  72. UWORD uwThrottleVolReg2Pu; // Gain of register to Pu
  73. UWORD uwThrottleOffsetPu; // offset of register
  74. UWORD uwThrottleErrorCnt;
  75. UWORD uwThrottleRecoverCnt;
  76. } BIKETHROTTLE_COF;
  77. /**
  78. * @brief Throttlecruise
  79. *
  80. */
  81. #define BIKECRUISE_OUT_DEFAULT \
  82. { \
  83. 0, 0, 0, 0 \
  84. } // Default value
  85. #define CRUISESETINGTIME 8000
  86. typedef struct
  87. {
  88. UWORD ThrottlekeepVault ;
  89. UWORD CruiseMode;
  90. ULONG KeepInTime;
  91. UWORD CruisePercent ;
  92. UWORD ThrottleResetCruiseFlag ;
  93. } BIKECRUISE_COF;
  94. /****************************************
  95. *
  96. * Exported variable
  97. *
  98. ****************************************/
  99. extern BIKETHROTTLE_OUT bikethrottle_stBikeThrottleOut;
  100. /***************************************
  101. *
  102. * Function Definations
  103. *
  104. ***************************************/
  105. void bikethrottle_voBikeThrottleInit(void);
  106. void bikethrottle_voBikeThrottleCof(void);
  107. void bikethrottle_voBikeThrottleADC(void);
  108. void bikethrottle_voThrottlecruise(void);
  109. void bikethrottle_voStartAllow(void);
  110. /************************************************************************/
  111. #endif
  112. /************************************************************************
  113. End of this File (EOF):
  114. Do not put anything after this part!
  115. *************************************************************************/