bikespeed.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #include "mathtool.h"
  16. #include "typedefine.h"
  17. typedef _Bool BOOL;
  18. #ifndef BIKESPEED_H
  19. #define BIKESPEED_H
  20. /****************************************
  21. *
  22. * Definitions & Macros
  23. *
  24. ****************************************/
  25. #define BIKESPEED_NUMBERS_PULSES 1 // numbers of pulses per cycles
  26. #define BIKESPEED_START_INTERVALTIME_MS 10000 // interveal time of detect valid pulses, ms
  27. #define BIKESPEED_NUMBERS_VALIDPULSE2START 1 // numbers of valid pulses that needed to start
  28. #define BIKESPEED_HF_MINTIME_MS 5000 // Min time of valid pulses, ms
  29. #define BIKESPEED_ERROR_RESETTIME_MS 5000 // TIMER PERIOD,ms
  30. #define BIKESPEED_TIM_TIMERUNIT_US ((SLONG)1000000/FTBS_HZ) // TIMER PERIOD,us
  31. #define BIKESPEED_LPF_GAIN 80 //
  32. #define BIKESPEED_MAX_FREQUENCY 20 // Hz, ebike wheel
  33. #define BIKESPEED_POWER_ERROR_VOLTAGE_UP 60 // 0.1v
  34. #define BIKESPEED_POWER_ERROR_VOLTAGE_DOWN 40 // 0.1v
  35. #define BIKESPEED_POWER_ERROR_DETECT_MS 4000 // ms
  36. #define BIKESPEED_POWER_ERROR_RECOVER_MS 4000 // ms
  37. #define BIKESPEED_POWER_ERROR_TIMEUNIT_MS 200 // ms
  38. #define BIKESPEED_COF_DEFAULT \
  39. { \
  40. 0, 0, 0, 0, 0, 0, 0, 0 \
  41. }
  42. #define BIKESPEED_OUT_DEFAULT \
  43. { \
  44. 0, 0, 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, FALSE, BIKESPEED_IDLE \
  45. } // Default value of BIKESPEED_OUT
  46. /***************************************
  47. *
  48. * Type Definations
  49. *
  50. ***************************************/
  51. /**
  52. * @brief Bikespeed FSM
  53. *
  54. */
  55. typedef enum
  56. {
  57. BIKESPEED_IDLE = 0,
  58. BIKESPEED_WORK = 1,
  59. BIKESPEED_ERROR = 3
  60. } BIKESPEED_FSM;
  61. /**
  62. * @brief Bikespeed COF
  63. *
  64. */
  65. typedef struct
  66. {
  67. UWORD uwNumbersPulses; // numbers of pulses per cycles
  68. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  69. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  70. UWORD uwHfMinTimeCnt; // Min time of valid pulses, ms
  71. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  72. UWORD uwTimerUnit; // Timer , ms
  73. UWORD uwBikeSpeedLPFGain; // Hz,LPF bandwidth
  74. UWORD uwMaxBikeSpeedFre; //
  75. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  76. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  77. UWORD uwBikespeedPwrErrorVoltagePuDown; // flag of light error
  78. UWORD uwBikespeedPwrErrorVoltagePuUp; // flag of light error
  79. UWORD uwWheelPerimeter; // the back wheel Diameter 0.1 cm
  80. UWORD uwMinTriptoUpdate; // the minimum trip to update m
  81. } BIKESPEED_COF;
  82. /**
  83. * @brief Bikespeed OUT
  84. *
  85. */
  86. typedef struct
  87. {
  88. // Output of " cadence_voFreGet "
  89. UWORD uwFrequencyPu; // Q20, Real value of Bike speed frequecy result
  90. ULONG ulCaputureCntErr;
  91. UWORD uwFrequencyPuLast;
  92. SWORD swBikeSpeedFreAcc; // Q8
  93. UWORD uwLPFFrequencyPu; // Q20, Real value of Bike speed frequecy result
  94. UWORD uwCaputure1Cnt; // The cnt of the first pulse
  95. UWORD uwCaputure2Cnt; // The cnt of the second pulse
  96. UWORD uwCaputureNumCnt; // The current sequece of the pulse
  97. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  98. UWORD uwCaputureOverflowCntLast; // number of TIM4 CNT Overflow between two capture
  99. UWORD uwCaputureErrorCnt; // number of ERROR
  100. UWORD uwFreTimesCnt; // number of frequency 1.5 or 3.0 times
  101. UWORD uwBikespeedPwrErrorCnt; // Cnt of detect GPIO low voltage
  102. UWORD uwBikespeedPwrRecoverCnt; // Cnt of detect GPIO high voltage
  103. BOOL blBikeSpeedSensorErrorFlg; // The falg of sensor error
  104. BOOL blBikeSpeedSensorPwrErrorFlg; // The falg of sensor error
  105. BOOL blBikeSpeedCalStartState; // TRUE = START FALSE = STOP
  106. BOOL blBikeSpeedPortState; //
  107. BOOL blBikeSpeedPort; //speed IO
  108. BIKESPEED_FSM bikespeed_fsm;
  109. UWORD uwCaputureOverflowMinCnt;
  110. UWORD uwBikeForwardCnt; // Count number to calculate trip
  111. BOOL blUpdateTripCntFlg; // Unit the same as BIKESPEED_COF.uwMinTriptoUpdate ��need clear after update trip.
  112. UWORD DECvnt;
  113. UWORD uwBikeSpeedStopFlag;
  114. } BIKESPEED_OUT;
  115. /****************************************
  116. *
  117. * Exported variable
  118. *
  119. ****************************************/
  120. extern BIKESPEED_OUT bikespeed_stFreGetOut;
  121. extern BIKESPEED_COF bikespeed_stFreGetCof;
  122. /***************************************
  123. *
  124. * Function Definations
  125. *
  126. ***************************************/
  127. void bikespeed_voBikeSpeedInit(void); // interface function
  128. void bikespeed_voBikeSpeedCof(void);
  129. void bikespeed_voBikeSpeedCal(UWORD source);
  130. void bikespeed_voGetBikeSpeedPwrError(UWORD BikeSpeedPwrVolPu);
  131. void bikespeed_votempTripCal(void);
  132. /************************************************************************
  133. Flag Define (N/A)
  134. *************************************************************************/
  135. #endif
  136. /************************************************************************
  137. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  138. All rights reserved.
  139. *************************************************************************
  140. End of this File (EOF):
  141. Do not put anything after this part!
  142. *************************************************************************/