123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /**
- * @file bikethrottle.h
- * @author Wang, Zhiyu(wangzy49@midea.com)
- * @brief Throttle of ebike
- * @version 0.1
- * @date 2021-09-29
- *
- * @copyright Copyright (c) 2021
- *
- */
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #ifndef TORQUESENSOR_H
- #define TORQUESENSOR_H
- //#include "user.h"
- #include "typedefine.h"
- #include "mathtool.h"
- typedef _Bool BOOL;
- /****************************************
- *
- * Definitions & Macros
- *
- ****************************************/
- #define TORSENSOR_USEEE 0
- #define TORSENSOR_USEDEFAULT 1
- #define TORSENSOR_USEMOL TORSENSOR_USEEE
- #define TORQUE_MAX_RANGE 1000 // MAX TORQUE 0.1Nm
- #define TORQUE_MIN_RANGE 5 // MIN TOEQUE 0.1Nm
- #define TORQUE_VOLTAGE_MAX_RANGE 2500 // MAX voltage mV
- #define TORQUE_VOLTAGE_MIN_RANGE 700 // MIN voltage mV
- #define TORQUE_VOLTAGE_SEN2MCUGAIN 100 * 1 / 1 // gain of sensor output to Mcu ADC 0.01
- #define TORQUE_VOLTAGE_PER_NM 18 // 18mV/Nm
- #define TORQUE_SENSOR_LPF_FRQ 2 // Hz
- #define TORQUE_LPF_DISCRETEHZ 1000 // Hz T=1/f,T is used in discreting LPF s function
- #define TORQ_OFFSET_NUM 7
- #define TORQUESENSOR_OUT_DEFAULT \
- { \
- 0, 0, 0, 0, 0, FALSE, FALSE \
- } // Default value of CADENCE_OUT
- #define TORQUESENSOR_COF_DEFAULT \
- { \
- 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 \
- } // Default value of CADENCE_OUT
- #define TORQUESENSITIVE_COF_DEFAULT \
- { \
- 2976, -6948, 6410, 6021 \
- } // Default value of CADENCE_OUT
- /***************************************
- *
- * Type Definations
- *
- ***************************************/
- /**
- * @brief torquesensor out
- *
- */
- typedef struct
- { // Output of " torquesensor "
- UWORD uwTorqueReg; // register data of torque
- UWORD uwTorquePu; // Q14 Torque Pu
- UWORD uwTorqueLPFPu; // Q14 Torque after LPF Pu
- UWORD uwTorqueErrorCnt; // Error Cnt
- UWORD uwTorquePercent; // Q14 Throttle voltage in output range %
- BOOL blTorqueCaliFlg; // Flg of wether finished Calibration or not
- BOOL blTorqueErrorFlg; // Flg of torque sensor error
- } TORQUESENSOR_OUT;
- /**
- * @brief torquesensor coef
- *
- */
- typedef struct
- {
- UWORD uwMaxSensorTorquePu; // 0.1Nm,the max torque of sensor output
- UWORD uwMinSensorTorquePu; // 0.1Nm,the min torque of sensor output
- UWORD uwMaxSensorVolOutputPu; // mV,the max voltage of sensor output
- UWORD uwMinSensorVolOutputPu; // mV,the min voltage of sensor output
- UWORD uwTorVolLPFDisFrq; // Hz,used in discreting LPF s function
- UWORD uwTorSensorLPFFrq; // Hz,LPF bandwidth
- UWORD uwTorqueOffsetPowerUp;
- UWORD uwTorqueOffsetOrign; //
- UWORD uwTorqueOffsetNow1;
- UWORD uwTorqueOffsetNow2;
- UWORD uwTorqueOffsetNow3;
- UWORD uwTorqueOffsetNow4;
- UWORD uwTorqueOffset; // offset of register
- BOOL uwTorqueOffsetConfirmFlg;
- BOOL uwTorqueNowAllHasValueFlg;
- UWORD uwBikeTorStep1RealNm;
- UWORD uwBikeTorStep1ADC;
- UWORD uwBikeTorStep2RealNm;
- UWORD uwBikeTorStep2ADC;
- UWORD uwBikeTorStep3RealNm;
- UWORD uwBikeTorStep3ADC;
- UWORD uwBikeTorStep4RealNm;
- UWORD uwBikeTorStep4ADC;
-
- UWORD uwBikeTorStep1NmPu;
- UWORD uwBikeTorStep2NmPu;
- UWORD uwBikeTorStep3NmPu;
- UWORD uwBikeTorStep4NmPu;
- UWORD uwSensorVolPerTorqDefault;
- UWORD uwSensorVolPerTorq1; // mV/Nm,the output gain1
- UWORD uwSensorVolPerTorq2; // mV/Nm,the output gain2
- UWORD uwSensorVolPerTorq3; // mV/Nm,the output gain3
- UWORD uwSensorVolPerTorq4; // mV/Nm,the output gain4
- ULONG uwTorqueReg2PuDefault;
- ULONG uwTorqueReg2Pu1; // Gain1 of register to Pu
- ULONG uwTorqueReg2Pu2; // Gain2 of register to Pu
- ULONG uwTorqueReg2Pu3; // Gain3 of register to Pu
- ULONG uwTorqueReg2Pu4; // Gain4 of register to Pu
-
- } TORQUESENSOR_COF;
- /****************************************
- *
- * Exported variable
- *
- ****************************************/
- //extern TORQUESENSOR_OUT torsensor_stTorSensorOut;
- //extern TORQUESENSOR_COF torsensor_stTorSensorCof;
- /***************************************
- *
- * Function Definations
- *
- ***************************************/
- void torsensor_voTorSensorCof(void);
- void torsensor_voTorSensorInit(void);
- void torsensor_voTorADC(void);
- UWORD torsensor_uwTorqOffsetCal(SWORD Temp);
- UWORD torsensor_uwTorqSencitiveCal(SWORD Temp, SWORD T0);
- //////test/////
- //extern LPF_OUT torsensor_test_Lpf;
- /************************************************************************/
- #endif
- /************************************************************************
- End of this File (EOF):
- Do not put anything after this part!
- *************************************************************************/
|