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