bikespeed.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 10000 //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 30000 //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_COF_DEFAULT \
  36. { \
  37. 0, 0, 0, 0, 0, 0, 0, 0 \
  38. }
  39. #define BIKESPEED_OUT_DEFAULT \
  40. { \
  41. 0, 0, 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, FALSE, BIKESPEED_IDLE \
  42. } // Default value of BIKESPEED_OUT
  43. /***************************************
  44. *
  45. * Type Definations
  46. *
  47. ***************************************/
  48. /**
  49. * @brief Bikespeed FSM
  50. *
  51. */
  52. typedef enum
  53. {
  54. BIKESPEED_IDLE = 0,
  55. BIKESPEED_WORK = 1,
  56. BIKESPEED_ERROR = 3
  57. } BIKESPEED_FSM;
  58. /**
  59. * @brief Bikespeed COF
  60. *
  61. */
  62. typedef struct
  63. {
  64. UWORD uwNumbersPulses; // numbers of pulses per cycles
  65. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  66. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  67. UWORD uwHfMinTimeCnt; // Min time of valid pulses, ms
  68. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  69. UWORD uwTimerUnit; // Timer , ms
  70. UWORD uwBikeSpeedLPFGain; // Hz,LPF bandwidth
  71. UWORD uwMaxBikeSpeedFre; //
  72. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  73. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  74. UWORD uwBikespeedPwrErrorVoltagePuDown; // flag of light error
  75. UWORD uwBikespeedPwrErrorVoltagePuUp; // flag of light error
  76. UWORD uwWheelDiameter; // the back wheel Diameter 0.1 cm
  77. UWORD uwMinTriptoUpdate; // the minimum trip to update m
  78. } BIKESPEED_COF;
  79. /**
  80. * @brief Bikespeed OUT
  81. *
  82. */
  83. typedef struct
  84. { // Output of " cadence_voFreGet "
  85. UWORD uwFrequencyPu; // Q20, Real value of Bike speed frequecy result
  86. UWORD uwLPFFrequencyPu; // Q20, Real value of Bike speed frequecy result
  87. UWORD uwCaputure1Cnt; // The cnt of the first pulse
  88. UWORD uwCaputure2Cnt; // The cnt of the second pulse
  89. UWORD uwCaputureNumCnt; // The current sequece of the pulse
  90. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  91. UWORD uwCaputureErrorCnt; // number of ERROR
  92. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  93. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  94. BOOL blBikeSpeedSensorErrorFlg; // The falg of sensor error
  95. BOOL blBikeSpeedSensorPwrErrorFlg; // The falg of sensor error
  96. BOOL blBikeSpeedCalStartState; // TRUE = START FALSE = STOP
  97. BIKESPEED_FSM bikespeed_fsm;
  98. UWORD uwCaputureOverflowMinCnt;
  99. UWORD uwBikeForwardCnt; // Count number to calculate trip
  100. BOOL blUpdateTripCntFlg; // Unit the same as BIKESPEED_COF.uwMinTriptoUpdate ��need clear after update trip.
  101. } BIKESPEED_OUT;
  102. typedef struct // Input of "BikeSpdREFPI"
  103. {
  104. SLONG slSpdRefPu; // bikeSpeed reference,Q0
  105. SLONG slSpdFdkPu; // bikeSpeed feedback,Q0
  106. SWORD swbikespdMax; // bikespeed output maximum limit
  107. SWORD swbikespdMin; // bikespeed output minimum limit
  108. } BIKESPDPI_IN;
  109. typedef struct
  110. {
  111. SLONG slErrorZ1;
  112. SLONG slMotorspeedref;
  113. SWORD swMotorSpeedRef;
  114. SWORD swSpdRefRpm;
  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. /***************************************
  129. *
  130. * Function Definations
  131. *
  132. ***************************************/
  133. void bikespeed_voBikeSpeedInit(void); // interface function
  134. void bikespeed_voBikeSpeedCof(void);
  135. void bikespeed_voBikeSpeedCal(UWORD source);
  136. void bikespeed_voGetBikeSpeedPwrError(UWORD BikeSpeedPwrVolPu);
  137. void bikespeed_votempTripCal(void);
  138. void bikespeed_voPIInit(void);
  139. void bikespeed_voPICoef(void);
  140. void bikespeed_voPuCal(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. *************************************************************************/