Cadence.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "typedefine.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif // __cplusplus
  21. /****************************************
  22. *
  23. * Definitions & Macros
  24. *
  25. ****************************************/
  26. #define CADENCE_NUMBERS_PULSES 64 //numbers of pulses per cycles
  27. #define CADENCE_START_INTERVALTIME 1000 //unit: ms, interveal time of detect valid pulses to start
  28. #define CADENCE_NUMBERS_VALIDPULSE2START 1 //numbers of valid pulses that needed to start
  29. #define CADENCE_LF_RECORDTIME 500 //unit: ms, time of Recording pulses per cycle
  30. #define CADENCE_LF_MINFRE 25 //unit: 0.01Hz, Min frequency of human foot in Low frequency method
  31. #define CADENCE_HF_MAXTIME 200 //unit: ms, Min time of valid pulses
  32. #define CADENCE_ERROR_RESETTIME 5000 //unit: ms
  33. #define CADENCE_TIM_TIMERUNIT 25 //unit: ms, TIMER PERIOD
  34. #define CADENCE_LPF_GAIN 80 //unit: %
  35. #define CADENCE_MAX_FREQUENCY 5 //unit: Hz, human foot
  36. #define CADENCE_COF_DEFAULT \
  37. { \
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  39. }
  40. #define CADENCE_OUT_DEFAULT \
  41. { \
  42. 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, CADENCE_DIR_IDLE, CADENCE_IDLE \
  43. } // Default value of CADENCE_OUT
  44. #define CADENCESPEED_KMPERH2FREQPU 299 // 200 ms per between two interupte
  45. /***************************************
  46. *
  47. * Type Definations
  48. *
  49. ***************************************/
  50. /**
  51. * @brief Cadence FSM
  52. *
  53. */
  54. typedef enum
  55. {
  56. CADENCE_IDLE = 0,
  57. CADENCE_LFreWork = 1,
  58. CADENCE_HFreWork = 2,
  59. CADENCE_BACKWOR = 3,
  60. CADENCE_ERROR = 4
  61. } CADENCE_FSM;
  62. /**
  63. * @brief Cadence Direction
  64. *
  65. */
  66. typedef enum
  67. {
  68. CADENCE_DIR_FORWARD = 0,
  69. CADENCE_DIR_BACKWARD = 1,
  70. CADENCE_DIR_IDLE = 2,
  71. CADENCE_DIR_ERROR = 3
  72. } CADENCE_DIR;
  73. /**
  74. * @brief Cadence coefficient
  75. *
  76. */
  77. typedef struct
  78. {
  79. UWORD uwNumbersPulses; // numbers of pulses per cycles
  80. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  81. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  82. UWORD uwLfRecordTimeCnt; // time of Recording pulses per cycle, ms
  83. UWORD uwLfMinFrePu; // Min frequency of human foot in Low frequency method, 0.01Hz
  84. UWORD uwHfMaxTimeCnt; // Min time of valid pulses, ms
  85. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  86. UWORD uwTimerUnit; // TIMER PERIOD, ms
  87. UWORD uwCadenceLPFgain; // Hz,LPF bandwidth
  88. UWORD uwMaxCadenceFre;
  89. } CADENCE_COF;
  90. /**
  91. * @brief Cadence output
  92. *
  93. */
  94. typedef struct
  95. { // Output of " cadence_voFreGet "
  96. UWORD uwFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  97. UWORD uwLPFFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  98. UWORD uwCaputure1Cnt; // The cnt of the first pulse
  99. UWORD uwCaputure2Cnt; // The cnt of the second pulse
  100. UWORD uwCaputureNumCnt; // The current sequece of the pulse
  101. UWORD uwCaputureErrorCnt; // The current sequece of the pulse
  102. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  103. UWORD uwCaputureOverflowCnt2;
  104. BOOL blCadenceSensorErrorFlg; // The falg of sensor error
  105. BOOL blCadenceCalStartState; // TRUE = START FALSE = STOP
  106. CADENCE_DIR cadence_dir; // Direction of cadence
  107. CADENCE_FSM cadence_fsm;
  108. UWORD uwFreqPercent; // Q14;
  109. UWORD uwForwardCnt; // Q14;
  110. UWORD uwOverflowfirst;
  111. } CADENCE_OUT;
  112. /****************************************
  113. *
  114. * Exported variable
  115. *
  116. ****************************************/
  117. extern CADENCE_OUT cadence_stFreGetOut;
  118. extern CADENCE_COF cadence_stFreGetCof;
  119. /***************************************
  120. *
  121. * Function Definations
  122. *
  123. ***************************************/
  124. void cadence_voCadenceInit(void);
  125. void cadence_voCadenceCof(void);
  126. void cadence_voCadenceCal(UWORD source);
  127. /************************************************************************/
  128. #ifdef __cplusplus
  129. }
  130. #endif // __cplusplus
  131. #endif
  132. /************************************************************************
  133. End of this File (EOF):
  134. Do not put anything after this part!
  135. *************************************************************************/