Parameter.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**************************** (C) COPYRIGHT 2018 Fortiortech shenzhen *****************************
  2. * File Name : Parameter.h
  3. * Author : Bruce,Fortiortech RD
  4. * Version : V1.0
  5. * Date : 2017-12-20
  6. * Description : This file contains all FOC debug parameter.
  7. ***************************************************************************************************
  8. * All Rights Reserved
  9. **************************************************************************************************/
  10. /* Define to prevent recursive inclusion --------------------------------------------------------*/
  11. #ifndef __Parameter_H_
  12. #define __Parameter_H_
  13. #include <Myproject.h>
  14. /* Define to prevent recursive inclusion -------------------------------------*/
  15. /* Q format define ---------------------------------------------------------------------------------*/
  16. #define _Q7(A) (int8) ((A) * 0x7f) ///< Q7 format 128*1 = 128
  17. #define _Q8(A) (int16)((A) * 0xff) ///< Q8 format 128*2 = 256
  18. #define _Q9(A) (int16)((A) * 0x1ff) ///< Q9 format 128*4 = 512
  19. #define _Q10(A) (int16)((A) * 0x3ff) ///< Q10 format 128*8 = 1024
  20. #define _Q11(A) (int16)((A) * 0x07ff) ///< Q11 format 128*16 = 2048
  21. #define _Q12(A) (int16)((A) * 0x0fff) ///< Q12 format 128*32 = 4096
  22. #define _Q13(A) (int16)((A) * 0x1fff) ///< Q13 format 128*64 = 8192
  23. #define _Q14(A) (int16)((A) * 0x3fff) ///< Q14 format 128*128= 18383
  24. #define _Q15(A) (int16)((A) * 0x7fff) ///< Q15 format 128*256= 32767
  25. #define _Q16 (65535.0) // Q16 format value
  26. #define _2PI (3.1415926 * 2)
  27. /*芯片参数值------------------------------------------------------------------*/
  28. /*CPU and PWM Parameter*/
  29. #define PWM_CYCLE (1000.0 / PWM_FREQUENCY) // 周期us
  30. #define SAMP_FREQ (PWM_FREQUENCY * 1000) // 采样频率(HZ)
  31. #define TPWM_VALUE (1.0 / SAMP_FREQ) // 载波周期(S)
  32. #define PWM_VALUE_LOAD (uint16)(MCU_CLOCK * 1000 *2 / PWM_FREQUENCY) // PWM 定时器重载值 20190514修改
  33. /*double resistor sample Parameter*/
  34. #define DLL_TIME (1.3) // 双电阻最小脉宽设置(us),建议值为死区时间值+0.2us以上
  35. /*three resistor overmodule Parameter*/
  36. #define OVERMOD_TIME (2.0) // 三电阻过调制时间(us),建议值2.0
  37. /*deadtime compensation*/
  38. #define DT_TIME (1.0) // 死区补偿时间(us)适用于双电阻和三电阻,建议值是1/2死区时间
  39. /*min pulse*/
  40. #define GLI_TIME (0.5) // 桥臂窄脉宽消除(us),建议值0.5
  41. /*deadtime Parameter*/
  42. #define PWM_LOAD_DEADTIME (PWM_DEADTIME * MCU_CLOCK) // 死区设置值
  43. #define PWM_OVERMODULE_TIME (OVERMOD_TIME * MCU_CLOCK / 2) // 过调制时间
  44. #define PWM_DLOWL_TIME (DLL_TIME * MCU_CLOCK / 2) //下桥臂最小时间
  45. /*single resistor sample Parameter*/
  46. #define PWM_TS_LOAD (uint16)(_Q16 / PWM_CYCLE * MIN_WIND_TIME / 16) // 单电阻采样设置值
  47. #define PWM_DT_LOAD (uint16)(_Q16 / PWM_CYCLE * DT_TIME / 16) // 死区补偿值
  48. #define PWM_TGLI_LOAD (uint16)(_Q16 / PWM_CYCLE * (GLI_TIME + PWM_DEADTIME) / 16) // 最小脉冲
  49. #define LPF_K(K) _Q15(_2PI / 1000 * K)
  50. /*硬件板子参数设置值------------------------------------------------------------------*/
  51. /*hardware current sample Parameter*/
  52. /*电流基准的电路参数*/
  53. #define HW_BOARD_CURR_MAX (HW_ADC_REF / 2 / HW_AMPGAIN / HW_RSHUNT) // 最大采样电流,2.702A
  54. #define HW_BOARD_CURR_MIN (-HW_BOARD_CURR_MAX) // 最小采样电流,-2.702A
  55. #define HW_BOARD_CURR_BASE (HW_BOARD_CURR_MAX * 2) // 电流基准//5.4A
  56. /*hardware voltage sample Parameter*/
  57. /*母线电压采样分压电路参数*/
  58. #define HW_BOARD_VOLTAGE_BASE (HW_BOARD_VOLT_MAX / 1.732) // 电压基准
  59. #define HW_BOARD_VOLTAGE_VC ((RV1 + RV2 + RV3 * VC1) / (RV3 * VC1))
  60. #define HW_BOARD_VOLTAGE_BASE_Start (HW_ADC_REF * HW_BOARD_VOLTAGE_VC / 1.732)// 电压基准
  61. /*功率参数*/
  62. #define P_Power(POWER) _Q15(POWER*2/HW_BOARD_CURR_BASE/HW_BOARD_VOLTAGE_BASE/1.5)
  63. #define P_PowerReal (3*((uint32)mcFocCtrl.Powerlpf*HW_BOARD_CURR_BASE*HW_BOARD_VOLTAGE_BASE))/4/32767
  64. #define I_IReal_10 (uint32)(10*HW_BOARD_CURR_BASE*mcFocCtrl.IDQFlt/1.414/1.35)/32767
  65. /*硬件过流保护DAC值*/
  66. #define DAC_OvercurrentValue (_Q8(I_ValueX(OverHardcurrentValue ))+0x7F)
  67. /*转矩补偿时硬件过流保护DAC值*/
  68. #define TorDAC_OvercurrentValue (_Q8(I_ValueX(TorOverHardcurrentValue ))+0x7F)
  69. #define BASE_FREQ ((MOTOR_SPEED_BASE / 60) * Pole_Pairs) // 基准频率
  70. #define I_ValuePFCIAC(Curr_Value) _Q15(Curr_Value * PFC_RSHUNT * PFC_AMPGAIN / HW_ADC_REF)
  71. #define DAC_PFCOvercurrentValue _Q8(PFCOverCurrentValue * PFC_RSHUNT * PFC_AMPGAIN / HW_ADC_REF)+0x3F
  72. /*保护参数值------------------------------------------------------------------*/
  73. /* protect value */
  74. #define OVER_PROTECT_VALUE _Q15(Over_Protect_Voltage / HW_BOARD_VOLT_MAX)
  75. #define UNDER_PROTECT_VALUE _Q15(Under_Protect_Voltage / HW_BOARD_VOLT_MAX)
  76. #define OVER_RECOVER_VALUE _Q15(Over_Recover_Vlotage / HW_BOARD_VOLT_MAX)
  77. #define UNDER_RECOVER_VALUE _Q15(Under_Recover_Vlotage / HW_BOARD_VOLT_MAX)
  78. /* motor speed set value */
  79. #define Motor_Open_Ramp_ACC _Q15(MOTOR_OPEN_ACC / MOTOR_SPEED_BASE)
  80. #define Motor_Open_Ramp_Min _Q15(MOTOR_OPEN_ACC_MIN / MOTOR_SPEED_BASE)
  81. #define Motor_Omega_Ramp_Min _Q15(MOTOR_OMEGA_ACC_MIN / MOTOR_SPEED_BASE)
  82. #define Motor_Omega_Ramp_End _Q15(MOTOR_OMEGA_ACC_END / MOTOR_SPEED_BASE)
  83. #define Motor_Loop_Speed _Q15(MOTOR_LOOP_RPM / MOTOR_SPEED_BASE)
  84. #define Motor_Max_Speed _Q15(MOTOR_SPEED_MAX_RPM / MOTOR_SPEED_BASE)
  85. #define Motor_Min_Speed _Q15(MOTOR_SPEED_MIN_RPM / MOTOR_SPEED_BASE)
  86. #define Motor_Stop_Speed _Q15(MOTOR_SPEED_STOP_RPM / MOTOR_SPEED_BASE)
  87. #define Motor_Stall_Min_Speed _Q15(MOTOR_SPEED_STAL_MIN_RPM / MOTOR_SPEED_BASE)
  88. #define Motor_Stall_Max_Speed _Q15(MOTOR_SPEED_STAL_MAX_RPM / MOTOR_SPEED_BASE)
  89. #define S_Value(SpeedValue) _Q15(SpeedValue/MOTOR_SPEED_BASE)
  90. #define S_Value2 ((((uint32)(mcFocCtrl.SpeedFlt*MOTOR_SPEED_BASE)/32767)+30)/60) //RPS Hz
  91. /* obsever parameter set value */
  92. #define MAX_BEMF_VOLTAGE ((MOTOR_SPEED_BASE*Ke)/(1000.0))
  93. #define MAX_OMEG_RAD_SEC ((float)(_2PI*BASE_FREQ))
  94. #if (EstimateAlgorithm==AO)
  95. #define OBS_K1T _Q11((3.0/(125.0*1.0))*(LQ/TPWM_VALUE)*(HW_BOARD_CURR_BASE/HW_BOARD_VOLTAGE_BASE))
  96. #define OBS_K2T _Q11(RS*HW_BOARD_CURR_BASE/HW_BOARD_VOLTAGE_BASE)
  97. #define OBS_K2T_Actual _Q11(RS*HW_BOARD_CURR_BASE/HW_BOARD_VOLTAGE_BASE)
  98. #define OBS_K3T _Q8(2.5)
  99. #define OBS_K4T _Q15(((LD-LQ)*TPWM_VALUE*MAX_OMEG_RAD_SEC)/(LD+RS*TPWM_VALUE))
  100. #else
  101. #define OBS_K1T _Q15(LD/(LD+RS*TPWM_VALUE))
  102. #define OBS_K2T _Q13((TPWM_VALUE/(LD+RS*TPWM_VALUE))*(HW_BOARD_VOLTAGE_BASE_Start/HW_BOARD_CURR_BASE))
  103. #define OBS_K2T_Actual _Q13((TPWM_VALUE/(LD+RS*TPWM_VALUE))*(HW_BOARD_VOLTAGE_BASE/HW_BOARD_CURR_BASE))
  104. #define OBS_K3T _Q15((TPWM_VALUE/(LD+RS*TPWM_VALUE))*(MAX_BEMF_VOLTAGE/HW_BOARD_CURR_BASE))
  105. #define OBS_K4T _Q15(((LD-LQ)*TPWM_VALUE*MAX_OMEG_RAD_SEC)/(LD+RS*TPWM_VALUE))
  106. #endif
  107. #define OBSW_KP_GAIN _Q12(2*_2PI*ATT_COEF*ATO_BW/BASE_FREQ)
  108. #define OBSW_KI_GAIN _Q15(_2PI*ATO_BW*ATO_BW*TPWM_VALUE/BASE_FREQ)
  109. #define OBSW_KP_GAIN_RUN _Q12(2*_2PI*ATT_COEF*ATO_BW_RUN/BASE_FREQ)
  110. #define OBSW_KI_GAIN_RUN _Q15(_2PI*ATO_BW_RUN*ATO_BW_RUN*TPWM_VALUE/BASE_FREQ)
  111. #define OBSW_KP_GAIN_RUN1 _Q12(2*_2PI*ATT_COEF*ATO_BW_RUN1/BASE_FREQ)
  112. #define OBSW_KI_GAIN_RUN1 _Q15(_2PI*ATO_BW_RUN1*ATO_BW_RUN1*TPWM_VALUE/BASE_FREQ)
  113. #define OBSW_KP_GAIN_RUN2 _Q12(2*_2PI*ATT_COEF*ATO_BW_RUN2/BASE_FREQ)
  114. #define OBSW_KI_GAIN_RUN2 _Q15(_2PI*ATO_BW_RUN2*ATO_BW_RUN2*TPWM_VALUE/BASE_FREQ)
  115. #define OBSW_KP_GAIN_RUN3 _Q12(2*_2PI*ATT_COEF*ATO_BW_RUN3/BASE_FREQ)
  116. #define OBSW_KI_GAIN_RUN3 _Q15(_2PI*ATO_BW_RUN3*ATO_BW_RUN3*TPWM_VALUE/BASE_FREQ)
  117. #define OBSW_KP_GAIN_RUN4 _Q12(2*_2PI*ATT_COEF*ATO_BW_RUN4/BASE_FREQ)
  118. #define OBSW_KI_GAIN_RUN4 _Q15(_2PI*ATO_BW_RUN4*ATO_BW_RUN4*TPWM_VALUE/BASE_FREQ)
  119. #define OBS_FBASE _Q15(BASE_FREQ*TPWM_VALUE) // Fbase*Tpwm*32768
  120. #define OBS_KLPF _Q15(_2PI*BASE_FREQ*TPWM_VALUE) // 2PI*Fbase*Tpwm
  121. #define SPEED_KLPF _Q15(_2PI*SPD_BW*TPWM_VALUE) // 2PI*SPD_BW*Tpwm
  122. #define OBS_EA_KS _Q15((2*MOTOR_SPEED_SMOMIN_RPM*_2PI*BASE_FREQ*TPWM_VALUE)/MOTOR_SPEED_BASE) // SMO的最小速度
  123. #define OBSE_PLLKP_GAIN1 _Q11(((2*ATT_COEF*_2PI*E_BW1*LD - RS)*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  124. #define OBSE_PLLKI_GAIN1 _Q11((_2PI*E_BW1*_2PI*E_BW1*LD*TPWM_VALUE*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  125. #define OBSE_PLLKP_GAIN2 _Q11(((2*ATT_COEF*_2PI*E_BW2*LD - RS)*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  126. #define OBSE_PLLKI_GAIN2 _Q11((_2PI*E_BW2*_2PI*E_BW2*LD*TPWM_VALUE*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  127. #define OBSE_PLLKP_GAIN3 _Q11(((2*ATT_COEF*_2PI*E_BW3*LD - RS)*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  128. #define OBSE_PLLKI_GAIN3 _Q11((_2PI*E_BW3*_2PI*E_BW3*LD*TPWM_VALUE*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  129. #define OBSE_PLLKP_GAIN4 _Q11(((2*ATT_COEF*_2PI*E_BW4*LD - RS)*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  130. #define OBSE_PLLKI_GAIN4 _Q11((_2PI*E_BW4*_2PI*E_BW4*LD*TPWM_VALUE*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  131. #define OBSE_PLLKP_GAIN5 _Q11(((2*ATT_COEF*_2PI*E_BW5*LD - RS)*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  132. #define OBSE_PLLKI_GAIN5 _Q11((_2PI*E_BW5*_2PI*E_BW5*LD*TPWM_VALUE*HW_BOARD_CURR_BASE)/HW_BOARD_VOLTAGE_BASE)
  133. /* 运放模式选择 */
  134. #define AMP_NOMAL (0) ///< 外部放大
  135. #define AMP_PGA_DUAL (1) ///< 内部PGA 双端差分输入
  136. /* 内部PGA放大倍数选择 */
  137. #define AMP2x (2)
  138. #define AMP4x (4)
  139. #define AMP8x (8)
  140. #define AMP16x (16)
  141. /*Current Calib:enable or disable*/
  142. #define Disable (0) //
  143. #define Enable (1) //
  144. #define CalibENDIS (Enable)
  145. #define CW (0)
  146. #define CCW (1)
  147. /*SVPWM mode*/
  148. #define SVPWM_5_Segment (0) // 五段式SVPWM
  149. #define SVPWM_7_Segment (1) // 七段式SVPWM
  150. #define SVPMW_Mode (SVPWM_7_Segment)
  151. /*double resistor sample mode*/
  152. #define DouRes_1_Cycle (0) // 1 周期采样完 ia, ib
  153. #define DouRes_2_Cycle (1) // 交替采用ia, ib, 2周期采样完成
  154. #define DouRes_Sample_Mode (DouRes_1_Cycle)
  155. #define VREF3_0 (0xA0)
  156. #define VREF4_0 (0xB0)
  157. #define VREF4_5 (0xC0)
  158. #define VREF5_0 (0xD0)
  159. #define High_Level (0) // 驱动高电平有效
  160. #define Low_Level (1) // 驱动低电平有效
  161. #define UP_H_DOWN_L (2) // 上桥臂高电平有效,下桥臂低电平有效
  162. #define UP_L_DOWN_H (3) // 上桥臂低电平有效,下桥臂高电平有效
  163. #endif