torquesensor.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 TORQUESENSOR_H
  16. #define TORQUESENSOR_H
  17. #include "typedefine.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif // __cplusplus
  21. /****************************************
  22. *
  23. * Definitions & Macros
  24. *
  25. ****************************************/
  26. #define TORSENSOR_USEEE 0
  27. #define TORSENSOR_USEDEFAULT 1
  28. #define TORSENSOR_USEMOL TORSENSOR_USEEE
  29. #define TORQUE_MAX_RANGE 850 // MAX TORQUE 0.1Nm
  30. #define TORQUE_MIN_RANGE 5 // MIN TOEQUE 0.1Nm
  31. #define TORQUE_VOLTAGE_MAX_RANGE 2930 // MAX voltage mV
  32. #define TORQUE_VOLTAGE_MIN_RANGE 483 // MIN voltage mV
  33. #define TORQUE_VOLTAGE_SEN2MCUGAIN 100 * 1 / 1 // gain of sensor output to Mcu ADC 0.01
  34. #define TORQUE_VOLTAGE_PER_NM 30 // 35mV/Nm
  35. #define TORQUE_SENSOR_LPF_FRQ 1 // Hz
  36. #define TORQUE_LPF_DISCRETEHZ 1000 // Hz T=1/f,T is used in discreting LPF s function
  37. #define TORQUE_90S_1MSCNT 90000L
  38. #define TORQUE_1S_1MSCNT 1000
  39. #define TORQ_OFFSET_NUM 7
  40. #define TORQUESENSOR_OUT_DEFAULT \
  41. { \
  42. 0, 0, 0, 0, 0, FALSE, FALSE \
  43. } // Default value of CADENCE_OUT
  44. #define TORQUESENSOR_COF_DEFAULT \
  45. { \
  46. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, 1,1,2,2,3,3,4,4,0,0,0,0,0,0,0,0,0,0 \
  47. } // Default value of CADENCE_OUT
  48. #define TORQUESENSITIVE_COF_DEFAULT \
  49. { \
  50. 2976, -6948, 6410, 6021 \
  51. } // Default value of CADENCE_OUT
  52. /***************************************
  53. *
  54. * Type Definations
  55. *
  56. ***************************************/
  57. /**
  58. * @brief torquesensor out
  59. *
  60. */
  61. typedef struct
  62. { // Output of " torquesensor "
  63. UWORD uwTorqueReg; // register data of torque
  64. UWORD uwTorquePu; // Q14 Torque Pu
  65. UWORD uwTorqueLPFPu; // Q14 Torque after LPF Pu
  66. UWORD uwTorqueErrorCnt; // Error Cnt
  67. UWORD uwTorquePercent; // Q14 Throttle voltage in output range %
  68. BOOL blTorqueCaliFlg; // Flg of wether finished Calibration or not
  69. BOOL blTorqueErrorFlg; // Flg of torque sensor error
  70. } TORQUESENSOR_OUT;
  71. /**
  72. * @brief torquesensor coef
  73. *
  74. */
  75. typedef struct
  76. {
  77. UWORD uwMaxSensorTorquePu; // 0.1Nm,the max torque of sensor output
  78. UWORD uwMinSensorTorquePu; // 0.1Nm,the min torque of sensor output
  79. UWORD uwMaxSensorVolOutputPu; // mV,the max voltage of sensor output
  80. UWORD uwMinSensorVolOutputPu; // mV,the min voltage of sensor output
  81. UWORD uwTorVolLPFDisFrq; // Hz,used in discreting LPF s function
  82. UWORD uwTorSensorLPFFrq; // Hz,LPF bandwidth
  83. UWORD uwTorqueOffsetPowerUp;
  84. UWORD uwTorqueOffsetOrign; //
  85. UWORD uwTorqueOffsetNow1;
  86. UWORD uwTorqueOffsetNow2;
  87. UWORD uwTorqueOffsetNow3;
  88. UWORD uwTorqueOffsetNow4;
  89. UWORD uwTorqueOffset; // offset of register
  90. BOOL uwTorqueOffsetConfirmFlg;
  91. BOOL uwTorqueNowAllHasValueFlg;
  92. UWORD uwBikeTorStep1RealNm;
  93. UWORD uwBikeTorStep1ADC;
  94. UWORD uwBikeTorStep2RealNm;
  95. UWORD uwBikeTorStep2ADC;
  96. UWORD uwBikeTorStep3RealNm;
  97. UWORD uwBikeTorStep3ADC;
  98. UWORD uwBikeTorStep4RealNm;
  99. UWORD uwBikeTorStep4ADC;
  100. UWORD uwBikeTorStep1NmPu;
  101. UWORD uwBikeTorStep2NmPu;
  102. UWORD uwBikeTorStep3NmPu;
  103. UWORD uwBikeTorStep4NmPu;
  104. UWORD uwSensorVolPerTorqDefault;
  105. ULONG ulTorqueReg2PuDefault;
  106. ULONG ulTorqueReg2Pu1; // Gain1 of register to Pu
  107. ULONG ulTorqueReg2Pu2; // Gain2 of register to Pu
  108. ULONG ulTorqueReg2Pu3; // Gain3 of register to Pu
  109. ULONG ulTorqueReg2Pu4; // Gain4 of register to Pu
  110. } TORQUESENSOR_COF;
  111. /****************************************
  112. *
  113. * Exported variable
  114. *
  115. ****************************************/
  116. extern TORQUESENSOR_OUT torsensor_stTorSensorOut;
  117. extern TORQUESENSOR_COF torsensor_stTorSensorCof;
  118. /***************************************
  119. *
  120. * Function Definations
  121. *
  122. ***************************************/
  123. void torsensor_voTorSensorCof(void);
  124. void torsensor_voTorSensorInit(void);
  125. void torsensor_voTorADC(void);
  126. //UWORD torsensor_uwTorqOffsetCal(SWORD Temp);
  127. //UWORD torsensor_uwTorqSencitiveCal(SWORD Temp, SWORD T0);
  128. //void torsensor_voCadenceCnt(void);
  129. //void torsensor_voDynamicOffset(void);
  130. void torsensor_voOffsetUpdate(void);
  131. /************************************************************************/
  132. #ifdef __cplusplus
  133. }
  134. #endif // __cplusplus
  135. #endif
  136. /************************************************************************
  137. End of this File (EOF):
  138. Do not put anything after this part!
  139. *************************************************************************/