torquesensor.h 5.5 KB

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