Cadence.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #define CADENCESPEED_KMPERH2FREQPU 299 // 200 ms per between two interupte
  41. /***************************************
  42. *
  43. * Type Definations
  44. *
  45. ***************************************/
  46. /**
  47. * @brief Cadence FSM
  48. *
  49. */
  50. typedef enum
  51. {
  52. CADENCE_IDLE = 0,
  53. CADENCE_LFreWork = 1,
  54. CADENCE_HFreWork = 2,
  55. CADENCE_BACKWOR = 3,
  56. CADENCE_ERROR = 4
  57. } CADENCE_FSM;
  58. /**
  59. * @brief Cadence Direction
  60. *
  61. */
  62. typedef enum
  63. {
  64. CADENCE_DIR_FORWARD = 0,
  65. CADENCE_DIR_BACKWARD = 1,
  66. CADENCE_DIR_IDLE = 2,
  67. CADENCE_DIR_ERROR = 3
  68. } CADENCE_DIR;
  69. /**
  70. * @brief Cadence coefficient
  71. *
  72. */
  73. typedef struct
  74. {
  75. UWORD uwNumbersPulses; // numbers of pulses per cycles
  76. UWORD uwSartIntervalTimeCnt; // interveal time of detect valid pulses, ms
  77. UWORD uwNumbersValidPulse2Start; // numbers of valid pulses that needed to start
  78. UWORD uwLfRecordTimeCnt; // time of Recording pulses per cycle, ms
  79. UWORD uwLfMinFrePu; // Min frequency of human foot in Low frequency method, 0.01Hz
  80. UWORD uwHfMaxTimeCnt; // Min time of valid pulses, ms
  81. UWORD uwErrorResetCnt; // Min time of ERROR reset, ms
  82. UWORD uwTimerUnit; // TIMER PERIOD, ms
  83. UWORD uwCadenceLPFgain; // Hz,LPF bandwidth
  84. UWORD uwMaxCadenceFre;
  85. } CADENCE_COF;
  86. /**
  87. * @brief Cadence output
  88. *
  89. */
  90. typedef struct
  91. { // Output of " cadence_voFreGet "
  92. UWORD uwFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  93. UWORD uwLPFFrequencyPu; // Q20, Real value of Cadence frequecy result (human foot)
  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 uwCaputureErrorCnt; // The current sequece of the pulse
  98. UWORD uwCaputureOverflowCnt; // number of TIM4 CNT Overflow between two capture
  99. BOOL blCadenceSensorErrorFlg; // The falg of sensor error
  100. BOOL blCadenceCalStartState; // TRUE = START FALSE = STOP
  101. CADENCE_DIR cadence_dir; // Direction of cadence
  102. CADENCE_FSM cadence_fsm;
  103. UWORD uwFreqPercent; // Q14;
  104. UWORD uwForwardCnt; // Q14;
  105. UWORD uwOverflowfirst;
  106. } CADENCE_OUT;
  107. /****************************************
  108. *
  109. * Exported variable
  110. *
  111. ****************************************/
  112. // extern CADENCE_OUT cadence_stFreGetOut;
  113. /***************************************
  114. *
  115. * Function Definations
  116. *
  117. ***************************************/
  118. void cadence_voCadenceInit(void);
  119. void cadence_voCadenceCof(void);
  120. void cadence_voCadenceCal(UWORD source);
  121. /************************************************************************/
  122. #endif
  123. /************************************************************************
  124. End of this File (EOF):
  125. Do not put anything after this part!
  126. *************************************************************************/