torquesensor.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 TORSENSOR3NUM //三力矩标识
  31. #define TORQUE_MAX_RANGE 1000 // MAX TORQUE 0.1Nm
  32. #define TORQUE_MIN_RANGE 5 // MIN TOEQUE 0.1Nm
  33. #define TORQUE_VOLTAGE_MAX_RANGE 3000 // MAX voltage mV
  34. #define TORQUE_VOLTAGE_MIN_RANGE 1000 // MIN voltage mV
  35. #define TORQUE_VOLTAGE_SEN2MCUGAIN 100 * 1 / 1 // gain of sensor output to Mcu ADC 0.01
  36. #define TORQUE_VOLTAGE_PER_NM 5 // 5mV/Nm
  37. #define TORQUE_SENSOR_LPF_FRQ 100 // Hz
  38. #define TORQUE_LPF_DISCRETEHZ 1000 // Hz T=1/f,T is used in discreting LPF s function
  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,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. UWORD uwSensorVolPerTorq1; // mV/Nm,the output gain1
  106. UWORD uwSensorVolPerTorq2; // mV/Nm,the output gain2
  107. UWORD uwSensorVolPerTorq3; // mV/Nm,the output gain3
  108. UWORD uwSensorVolPerTorq4; // mV/Nm,the output gain4
  109. ULONG uwTorqueReg2PuDefault;
  110. ULONG uwTorqueReg2Pu1; // Gain1 of register to Pu
  111. ULONG uwTorqueReg2Pu2; // Gain2 of register to Pu
  112. ULONG uwTorqueReg2Pu3; // Gain3 of register to Pu
  113. ULONG uwTorqueReg2Pu4; // Gain4 of register to Pu
  114. } TORQUESENSOR_COF;
  115. typedef struct
  116. {
  117. SLONG SensorFltSum1;
  118. SLONG SensorFltSum2;
  119. SLONG SensorFltSum3;
  120. UWORD SensorFlt1;
  121. UWORD SensorFlt2;
  122. UWORD SensorFlt3;
  123. UWORD SensorPer1;
  124. UWORD SensorPer2;
  125. UWORD SensorPer3;
  126. } TORQUESENSOR_REG_FLT;
  127. /****************************************
  128. *
  129. * Exported variable
  130. *
  131. ****************************************/
  132. extern TORQUESENSOR_OUT torsensor_stTorSensorOut;
  133. extern TORQUESENSOR_COF torsensor_stTorSensorCof;
  134. extern TORQUESENSOR_REG_FLT TorqueSensorRegFlt;
  135. /***************************************
  136. *
  137. * Function Definations
  138. *
  139. ***************************************/
  140. void torsensor_voTorSensorCof(void);
  141. void torsensor_voTorSensorInit(void);
  142. void torsensor_voTorADC(void);
  143. UWORD torsensor_uwTorqOffsetCal(SWORD Temp);
  144. UWORD torsensor_uwTorqSencitiveCal(SWORD Temp, SWORD T0);
  145. void TorqueSensorRegFltCal(void);
  146. void TorqueSensorOffSetAuto(void);
  147. #endif
  148. /************************************************************************
  149. End of this File (EOF):
  150. Do not put anything after this part!
  151. *************************************************************************/