bikethrottle.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "typedefine.h"
  18. typedef _Bool BOOL;
  19. /****************************************
  20. *
  21. * Definitions & Macros
  22. *
  23. ****************************************/
  24. #define BIKETHROTTLE_VOLTAGE_MAX_RANGE 5000 // MAX voltage of throttle sensor, mV
  25. #define BIKETHROTTLE_VOLTAGE_MIN_RANGE 0 // MIN voltage of throttle sensor, mV
  26. #define BIKETHROTTLE_VOLTAGE_FAULT_RANGE 1200 // MIN voltage of throttle sensor, mV
  27. #define BIKETHROTTLE_VOLTAGE_SEN2MCUGAIN (100 * 100 / 151) // gain of sensor output to Mcu ADC 0.01
  28. #define BIKETHROTTLE_LPF_FRQ 20 // Hz bandwidth of LPF
  29. #define BIKETHROTTLE_LPF_DISCRETEHZ 200 // Hz T=1/f,T is used in discreting LPF s function
  30. #define BIKETHROTTLE_ERROR_TIME 2000 // ms
  31. #define BIKETHROTTLE_RECOVER_TIME 1 // ms
  32. #define BIKETHROTTLE_ERROE_TIMEUNIT 5 // ms
  33. #define BIKETHROTTLE_OUT_DEFAULT \
  34. { \
  35. 0, 0, 0, 0, 0, FALSE, FALSE \
  36. } // Default value of CADENCE_OUT
  37. #define BIKETHROTTLE_COF_DEFAULT \
  38. { \
  39. 0, 0, 0, 0, 0, 0, 0 \
  40. } // Default value of CADENCE_OUT
  41. #define STARTRUNSPEED 30//285-3km/h
  42. #define RESETTRUNSPEED 95//95-1km/h
  43. /***************************************
  44. *
  45. * Type Definations
  46. *
  47. ***************************************/
  48. /**
  49. * @brief Throttle out
  50. *
  51. */
  52. typedef struct
  53. { // Output of " Throttle "
  54. UWORD uwThrottleVolReg; // register data of Throttle voltage
  55. UWORD uwThrottleVolPu; // Q14 Throttle voltage Pu
  56. UWORD uwThrottleVolLPFPu; // Q14 Throttle voltage Pu
  57. UWORD uwThrottlePercent; // Throttle voltage in output range %
  58. UWORD uwThrottleErrorCnt;
  59. UWORD uwThrottleRecoverCnt;
  60. UWORD uwThrottleGear;
  61. UWORD uwThrottleActPer; // Throttle voltage in output range %
  62. UWORD uwThrottleBack;
  63. BOOL blThrottleErrorFlg; // Flg of Throttle sensor flg
  64. } BIKETHROTTLE_OUT;
  65. /**
  66. * @brief Throttle coef
  67. *
  68. */
  69. typedef struct
  70. {
  71. UWORD uwMaxThrottleVolOutputPu; // mV,the max voltage of Throttle sensor output
  72. UWORD uwMinThrottleVolOutputPu; // mV,the min voltage of Throttle sensor output
  73. UWORD uwThrottleVoFaultlPu;
  74. UWORD uwThrottleVolLPFFrq; // Hz,LPF bandwidth
  75. UWORD uwThrottleVolLPFDisFrq; // Hz,used in discreting LPF s function
  76. UWORD uwThrottleVolSen2McuGain; // gain of sensor output to Mcu ADC
  77. UWORD uwThrottleVolReg2Pu; // Gain of register to Pu
  78. SWORD uwThrottleOffsetPu; // offset of register
  79. UWORD uwThrottleErrorCnt;
  80. UWORD uwThrottleRecoverCnt;
  81. } BIKETHROTTLE_COF;
  82. /**
  83. * @brief Throttlecruise
  84. *
  85. */
  86. #define BIKECRUISE_OUT_DEFAULT \
  87. { \
  88. 0, 0, 0, 0 \
  89. } // Default value
  90. #define CRUISESETINGTIME 80
  91. typedef struct
  92. {
  93. UWORD ThrottlekeepVault ;
  94. UWORD CruiseMode;
  95. UWORD KeepInCnt;
  96. UWORD CruisePercent ;
  97. UWORD ThrottleResetCruiseFlag ;
  98. } BIKECRUISE_COF;
  99. /****************************************
  100. *
  101. * Exported variable
  102. *
  103. ****************************************/
  104. extern UWORD Bikethrottle_uwDMAReg;
  105. extern BIKETHROTTLE_OUT bikethrottle_stBikeThrottleOut;
  106. extern BIKECRUISE_COF bikeCruise ;
  107. /***************************************
  108. *
  109. * Function Definations
  110. *
  111. ***************************************/
  112. void bikethrottle_voBikeThrottleInit(void);
  113. void bikethrottle_voBikeThrottleCof(void);
  114. void bikethrottle_voBikeThrottleADC(void);
  115. void Throttlecruise(void);
  116. /************************************************************************/
  117. #endif
  118. /************************************************************************
  119. End of this File (EOF):
  120. Do not put anything after this part!
  121. *************************************************************************/