bikespeed.h 6.3 KB

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