Cadence.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * @file Cadence.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Cadence of ebike
  5. * @version 0.1
  6. * @date 2021-09-29
  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 CADENCE_H
  16. #define CADENCE_H
  17. #include "user.h"
  18. #include "typedefine.h"
  19. /****************************************
  20. *
  21. * Definitions & Macros
  22. *
  23. ****************************************/
  24. //#if (ASSIST_MODE == TORQUE_ASSIST)
  25. //力矩相关参数
  26. #define TORQUE_NUMBERS_PULSES 60 //24 //24 48 64(350W-bike) //numbers of pulses per cycles
  27. #define TORQUE_START_INTERVALTIME_MS 1000 // 250 //interveal time of detect valid pulses to start, ms
  28. #define TORQUE_NUMBERS_VALIDPULSE2START 1 // numbers of valid pulses that needed to start
  29. #define TORQUE_LF_RECORDTIME_MS 500 // time of Recording pulses per cycle, ms
  30. #define TORQUE_LF_MINFRE 25 // Min frequency of human foot in Low frequency method, 0.01Hz
  31. #define TORQUE_HF_MAXTIME_MS 150 // 3000 //Min time of valid pulses, ms
  32. #define TORQUE_ERROR_RESETTIME_MS 5000 // TIMER PERIOD,ms
  33. #define TORQUE_TIM_TIMERUNIT_US ((SLONG)100000/FTBS_HZ) //25 // TIMER PERIOD,ms us
  34. #define TORQUE_LPF_GAIN 80 //%
  35. #define TORQUE_MAX_FREQUENCY 5 // Hz, human foot
  36. //#elif (ASSIST_MODE == CADENCE_ASSIST)
  37. //踏频相关参数
  38. #define CADENCE_NUMBERS_PULSES 60 //24 48 64(350W-bike) //numbers of pulses per cycles
  39. #define CADENCE_START_INTERVALTIME_MS 5000 // 250 //interveal time of detect valid pulses to start, ms
  40. #define CADENCE_NUMBERS_VALIDPULSE2START 1 // numbers of valid pulses that needed to start
  41. #define CADENCE_LF_RECORDTIME_MS 500 // time of Recording pulses per cycle, ms
  42. #define CADENCE_LF_MINFRE 25 // Min frequency of human foot in Low frequency method, 0.01Hz
  43. #define CADENCE_HF_MAXTIME_MS ((800*12)/CADENCE_NUMBERS_PULSES) // 3000 //Min time of valid pulses, ms
  44. #define CADENCE_ERROR_RESETTIME_MS 5000 // TIMER PERIOD,ms
  45. #define CADENCE_TIM_TIMERUNIT_US ((SLONG)100000/FTBS_HZ) //25 // TIMER PERIOD,ms us
  46. #define CADENCE_LPF_GAIN 80 //%
  47. #define CADENCE_MAX_FREQUENCY 5 // Hz, human foot
  48. //#endif
  49. #define CADENCE_COF_DEFAULT \
  50. { \
  51. 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  52. }
  53. #define CADENCE_OUT_DEFAULT \
  54. { \
  55. 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, CADENCE_DIR_IDLE, CADENCE_IDLE \
  56. } // Default value of CADENCE_OUT
  57. /***************************************
  58. *
  59. * Type Definations
  60. *
  61. ***************************************/
  62. /**
  63. * @brief Cadence FSM
  64. *
  65. */
  66. typedef enum
  67. {
  68. CADENCE_IDLE = 0,
  69. CADENCE_LFreWork = 1,
  70. CADENCE_HFreWork = 2,
  71. CADENCE_BACKWOR = 3,
  72. CADENCE_ERROR = 4
  73. } CADENCE_FSM;
  74. /**
  75. * @brief Cadence Direction
  76. *
  77. */
  78. typedef enum
  79. {
  80. CADENCE_DIR_FORWARD = 0,
  81. CADENCE_DIR_BACKWARD = 1,
  82. CADENCE_DIR_IDLE = 2,
  83. CADENCE_DIR_ERROR = 3
  84. } CADENCE_DIR;
  85. /**
  86. * @brief Cadence coefficient
  87. *
  88. */
  89. typedef struct
  90. {
  91. UWORD uwNumbersPulses; //公共使用脉冲数
  92. UWORD uwTorque_NumbersPulses; // numbers of Torque pulses per cycles
  93. UWORD uwCad_NumbersPulses; //numbers of cad pulses per cycles
  94. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  95. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  96. UWORD uwLfRecordTimeCnt; // time of Recording pulses per cycle, ms
  97. UWORD uwLfMinFrePu; // Min frequency of human foot in Low frequency method, 0.01Hz
  98. UWORD uwHfMaxTimeCnt; // Min time of valid pulses, ms
  99. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  100. UWORD uwTimerUnit; // TIMER PERIOD, ms
  101. UWORD uwCadenceLPFgain; // Hz,LPF bandwidth
  102. UWORD uwMaxCadenceFre;
  103. } CADENCE_COF;
  104. /**
  105. * @brief Cadence output
  106. *
  107. */
  108. typedef struct
  109. { // Output of " cadence_voFreGet "
  110. ULONG ulTimer2CntErr;
  111. ULONG ulCaputureCntErr;
  112. UWORD uwFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  113. UWORD uwCntErrLast; // Q20, Real value of Cadence frequecy result (human foot)
  114. UWORD uwFrequencyLastPu; // Q20, Real value of Cadence frequecy result (human foot)
  115. UWORD uwLPFFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  116. SWORD uwLPFFrequencyPuLast; // Q20, Real value of Cadence frequecy result (human foot)
  117. UWORD uwCaputure1Cnt; // The cnt of the first pulse
  118. UWORD uwCaputure2Cnt; // The cnt of the second pulse
  119. UWORD uwCaputureNumCnt; // The current sequece of the pulse
  120. UWORD uwCaputureErrorCnt; // The current sequece of the pulse
  121. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  122. BOOL blCadenceSensorErrorFlg; // The falg of sensor error
  123. BOOL blCadenceCalStartState; // TRUE = START FALSE = STOP
  124. CADENCE_DIR cadence_dir; // Direction of cadence
  125. CADENCE_FSM cadence_fsm;
  126. UWORD uwFreqPercent; // Q14;
  127. UWORD uwForwardCnt; // Q14;
  128. UWORD uwTaPinPortSta;
  129. } CADENCE_OUT;
  130. typedef struct
  131. {
  132. UWORD uwIqCurLimitMax;
  133. UWORD uwIqCurLimitMin;
  134. UWORD uwbikespeedCal;
  135. UWORD uwBikeSpdThresHold1;
  136. UWORD uwBikeSpdThresHold2;
  137. UWORD uwLimitdSpeed_S[6];
  138. UWORD uwAssistLimitSpdStart[6];
  139. UWORD uwAssistLimitSpdStop[6];
  140. UWORD uwLimitdSpeed_E[6];
  141. }CADPOWER_STRUCT;
  142. typedef struct
  143. {
  144. UWORD uwPortHightcnt;
  145. UWORD uwPortLowcnt;
  146. UWORD uwPortSta;
  147. }CADDIR_STRUCT;
  148. #define CAD_IS_MIN_AP 500 //
  149. /****************************************
  150. *
  151. * Exported variable
  152. *
  153. ****************************************/
  154. extern CADENCE_OUT cadence_stFreGetOut;
  155. /***************************************
  156. *
  157. * Function Definations
  158. *
  159. ***************************************/
  160. void cadence_voCadenceInit(void);
  161. void cadence_voCadenceCof(void);
  162. void cadence_voCadenceCal(UWORD source);
  163. /************************************************************************/
  164. #endif
  165. /************************************************************************
  166. End of this File (EOF):
  167. Do not put anything after this part!
  168. *************************************************************************/