torquesensor.h 5.1 KB

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