torquesensor.h 5.3 KB

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