bikespeed.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. * @file Bikespeed.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Speed of ebike wheel
  5. * @version 0.1
  6. * @date 2021-10-09
  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 BIKESPEED_H
  16. #define BIKESPEED_H
  17. #include "typedefine.h"
  18. #include "mathtool.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif // __cplusplus
  22. /****************************************
  23. *
  24. * Definitions & Macros
  25. *
  26. ****************************************/
  27. #define BIKESPEED_NUMBERS_PULSES 1 // numbers of pulses per cycles
  28. #define BIKESPEED_START_INTERVALTIME 8000 //10000 // interveal time of detect valid pulses, ms
  29. #define BIKESPEED_NUMBERS_VALIDPULSE2START 1 // numbers of valid pulses that needed to start
  30. #define BIKESPEED_HF_MINTIME 8000 //4000 //3000 // Min time of valid pulses, ms
  31. #define BIKESPEED_ERROR_RESETTIME 5000 // TIMER PERIOD,ms
  32. #define BIKESPEED_TIM_TIMERUNIT 25 // TIMER PERIOD,ms
  33. #define BIKESPEED_LPF_GAIN 80 //%
  34. #define BIKESPEED_MAX_FREQUENCY 20 // Hz, ebike wheel
  35. #define BIKESPEED_POWER_ERROR_VOLTAGE_UP 60 // 0.1v
  36. #define BIKESPEED_POWER_ERROR_VOLTAGE_DOWN 40 // 0.1v
  37. #define BIKESPEED_POWER_ERROR_DETECT 4000 // ms
  38. #define BIKESPEED_POWER_ERROR_RECOVER 4000 // ms
  39. #define BIKESPEED_POWER_ERROR_TIMEUNIT 200 // ms
  40. #define BIKESPEED_KMPERH2FREQPU 190 // 1km/h to FreqPu : 1/(FBASE * ass_stParaCong.uwWheelPerimeter * 36 /1000 >> 20)
  41. #define BIKESPEED_COF_DEFAULT \
  42. { \
  43. 0, 0, 0, 0, 0, 0, 0, 0 \
  44. }
  45. #define BIKESPEED_OUT_DEFAULT \
  46. { \
  47. 0, 0, 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, FALSE, BIKESPEED_IDLE \
  48. } // Default value of BIKESPEED_OUT
  49. /***************************************
  50. *
  51. * Type Definations
  52. *
  53. ***************************************/
  54. /**
  55. * @brief Bikespeed FSM
  56. *
  57. */
  58. typedef enum
  59. {
  60. BIKESPEED_IDLE = 0,
  61. BIKESPEED_WORK = 1,
  62. BIKESPEED_ERROR = 3
  63. } BIKESPEED_FSM;
  64. /**
  65. * @brief Bikespeed COF
  66. *
  67. */
  68. typedef struct
  69. {
  70. UWORD uwNumbersPulses; // numbers of pulses per cycles
  71. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  72. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  73. UWORD uwHfMinTimeCnt; // Min time of valid pulses, ms
  74. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  75. UWORD uwTimerUnit; // Timer , ms
  76. UWORD uwBikeSpeedLPFGain; // Hz,LPF bandwidth
  77. UWORD uwMaxBikeSpeedFre; //
  78. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  79. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  80. UWORD uwBikespeedPwrErrorVoltagePuDown; // flag of light error
  81. UWORD uwBikespeedPwrErrorVoltagePuUp; // flag of light error
  82. UWORD uwWheelPerimeter; // the back wheel Diameter 0.1 cm
  83. UWORD uwMinTriptoUpdate; // the minimum trip to update m
  84. } BIKESPEED_COF;
  85. /**
  86. * @brief Bikespeed OUT
  87. *
  88. */
  89. typedef struct
  90. { // Output of " cadence_voFreGet "
  91. UWORD uwFrequencyPu; // Q20, Real value of Bike speed frequecy result
  92. UWORD uwLPFFrequencyPu; // Q20, Real value of Bike speed frequecy result
  93. UWORD uwCaputure1Cnt; // The cnt of the first pulse
  94. UWORD uwCaputure2Cnt; // The cnt of the second pulse
  95. UWORD uwCaputureNumCnt; // The current sequece of the pulse
  96. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  97. UWORD uwCaputureErrorCnt; // number of ERROR
  98. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  99. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  100. BOOL blBikeSpeedSensorErrorFlg; // The falg of sensor error
  101. BOOL blBikeSpeedSensorPwrErrorFlg; // The falg of sensor error
  102. BOOL blBikeSpeedCalStartState; // TRUE = START FALSE = STOP
  103. BIKESPEED_FSM bikespeed_fsm;
  104. UWORD uwCaputureOverflowMinCnt;
  105. UWORD uwCaputureOverflowMinCntTest;
  106. UWORD uwBikeForwardCnt; // Count number to calculate trip
  107. BOOL blUpdateTripCntFlg; // Unit the same as BIKESPEED_COF.uwMinTriptoUpdate ��need clear after update trip.
  108. UWORD uwOverflowfirst;
  109. } BIKESPEED_OUT;
  110. typedef struct // Input of "BikeSpdREFPI"
  111. {
  112. SLONG slSpdRefPu; // bikeSpeed reference,Q0
  113. SLONG slSpdFdkPu; // bikeSpeed feedback,Q0
  114. SWORD swIqMaxPu;
  115. SWORD swIqMinPu;
  116. } BIKESPDPI_IN;
  117. typedef struct
  118. {
  119. SLONG slErrorZ1;
  120. SLONG slIqRefPu;
  121. SWORD swIqRefPu;
  122. } BIKESPDPI_OUT;
  123. typedef struct
  124. {
  125. UWORD uwKpPu;
  126. UWORD uwKiPu;
  127. }BIKESPDPI_COF;
  128. /****************************************
  129. *
  130. * Exported variable
  131. *
  132. ****************************************/
  133. extern BIKESPEED_COF bikespeed_stFreGetCof;
  134. extern BIKESPDPI_OUT bikespeed_stPIOut;
  135. extern BIKESPDPI_IN bikespeed_stPIIn;
  136. extern BIKESPEED_OUT bikespeed_stFreGetOut;
  137. extern LPF_OUT bike_pvt_stCurLpf;
  138. /***************************************
  139. *
  140. * Function Definations
  141. *
  142. ***************************************/
  143. void bikespeed_voBikeSpeedInit(void); // interface function
  144. void bikespeed_voBikeSpeedCof(void);
  145. void bikespeed_voBikeSpeedCal(UWORD source);
  146. void bikespeed_voGetBikeSpeedPwrError(UWORD BikeSpeedPwrVolPu);
  147. void bikespeed_votempTripCal(void);
  148. void bikespeed_voPIInit(void);
  149. void bikespeed_voPICoef(void);
  150. void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out);
  151. /************************************************************************
  152. Flag Define (N/A)
  153. *************************************************************************/
  154. #ifdef __cplusplus
  155. }
  156. #endif // __cplusplus
  157. #endif
  158. /************************************************************************
  159. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  160. All rights reserved.
  161. *************************************************************************
  162. End of this File (EOF):
  163. Do not put anything after this part!
  164. *************************************************************************/