bikethrottle.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file bikethrottle.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Throttle 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 BIKETHROTTLE_H
  16. #define BIKETHROTTLE_H
  17. /****************************************
  18. *
  19. * Definitions & Macros
  20. *
  21. ****************************************/
  22. #define BIKETHROTTLE_VOLTAGE_MAX_RANGE 5000 // MAX voltage of throttle sensor, mV
  23. #define BIKETHROTTLE_VOLTAGE_MIN_RANGE 0 // MIN voltage of throttle sensor, mV
  24. #define BIKETHROTTLE_VOLTAGE_SEN2MCUGAIN 100 * 3 / 5 // gain of sensor output to Mcu ADC 0.01
  25. #define BIKETHROTTLE_LPF_FRQ 10 // Hz bandwidth of LPF
  26. #define BIKETHROTTLE_LPF_DISCRETEHZ 200 // Hz T=1/f,T is used in discreting LPF s function
  27. #define BIKETHROTTLE_ERROR_TIME 2000 // ms
  28. #define BIKETHROTTLE_RECOVER_TIME 2000 // ms
  29. #define BIKETHROTTLE_ERROE_TIMEUNIT 5 // ms
  30. #define BIKETHROTTLE_OUT_DEFAULT \
  31. { \
  32. 0, 0, 0, 0, 0, FALSE, FALSE \
  33. } // Default value of CADENCE_OUT
  34. #define BIKETHROTTLE_COF_DEFAULT \
  35. { \
  36. 0, 0, 0, 0, 0, 0, 0 \
  37. } // Default value of CADENCE_OUT
  38. /***************************************
  39. *
  40. * Type Definations
  41. *
  42. ***************************************/
  43. /**
  44. * @brief Throttle out
  45. *
  46. */
  47. typedef struct
  48. { // Output of " Throttle "
  49. UWORD uwThrottleVolReg; // register data of Throttle voltage
  50. UWORD uwThrottleVolPu; // Q14 Throttle voltage Pu
  51. UWORD uwThrottleVolLPFPu; // Q14 Throttle voltage Pu
  52. UWORD uwThrottlePercent; // Throttle voltage in output range %
  53. UWORD uwThrottleErrorCnt;
  54. UWORD uwThrottleRecoverCnt;
  55. BOOL blThrottleErrorFlg; // Flg of Throttle sensor flg
  56. } BIKETHROTTLE_OUT;
  57. /**
  58. * @brief Throttle coef
  59. *
  60. */
  61. typedef struct
  62. {
  63. UWORD uwMaxThrottleVolOutputPu; // mV,the max voltage of Throttle sensor output
  64. UWORD uwMinThrottleVolOutputPu; // mV,the min voltage of Throttle sensor output
  65. UWORD uwThrottleVolLPFFrq; // Hz,LPF bandwidth
  66. UWORD uwThrottleVolLPFDisFrq; // Hz,used in discreting LPF s function
  67. UWORD uwThrottleVolSen2McuGain; // gain of sensor output to Mcu ADC
  68. UWORD uwThrottleVolReg2Pu; // Gain of register to Pu
  69. UWORD uwThrottleOffsetPu; // offset of register
  70. UWORD uwThrottleErrorCnt;
  71. UWORD uwThrottleRecoverCnt;
  72. } BIKETHROTTLE_COF;
  73. /****************************************
  74. *
  75. * Exported variable
  76. *
  77. ****************************************/
  78. extern UWORD Bikethrottle_uwDMAReg;
  79. extern BIKETHROTTLE_OUT bikethrottle_stBikeThrottleOut;
  80. /***************************************
  81. *
  82. * Function Definations
  83. *
  84. ***************************************/
  85. void bikethrottle_voBikeThrottleInit(void);
  86. void bikethrottle_voBikeThrottleCof(void);
  87. void bikethrottle_voBikeThrottleADC(void);
  88. /************************************************************************/
  89. #endif
  90. /************************************************************************
  91. End of this File (EOF):
  92. Do not put anything after this part!
  93. *************************************************************************/