bikespeed.h 6.0 KB

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