Cadence.h 4.7 KB

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