mc_config.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. ******************************************************************************
  3. * @file mc_config.c
  4. * @author Motor Control SDK Team, ST Microelectronics
  5. * @brief Motor Control Subsystem components configuration and handler structures.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. #include "main.h"
  20. #include "mc_type.h"
  21. #include "parameters_conversion.h"
  22. #include "mc_parameters.h"
  23. #include "mc_config.h"
  24. /* USER CODE BEGIN Additional include */
  25. /* USER CODE END Additional include */
  26. #define FREQ_RATIO 1 /* Dummy value for single drive */
  27. #define FREQ_RELATION HIGHEST_FREQ /* Dummy value for single drive */
  28. #define OFFCALIBRWAIT_MS 0
  29. #define OFFCALIBRWAIT_MS2 0
  30. #include "pqd_motor_power_measurement.h"
  31. /* USER CODE BEGIN Additional define */
  32. /* USER CODE END Additional define */
  33. PQD_MotorPowMeas_Handle_t PQD_MotorPowMeasM1 =
  34. {
  35. .wConvFact = PQD_CONVERSION_FACTOR
  36. };
  37. PQD_MotorPowMeas_Handle_t *pPQD_MotorPowMeasM1 = &PQD_MotorPowMeasM1;
  38. /**
  39. * @brief PI / PID Speed loop parameters Motor 1
  40. */
  41. PID_Handle_t PIDSpeedHandle_M1 =
  42. {
  43. .hDefKpGain = (int16_t)PID_SPEED_KP_DEFAULT,
  44. .hDefKiGain = (int16_t)PID_SPEED_KI_DEFAULT,
  45. .wUpperIntegralLimit = (int32_t)IQMAX * (int32_t)SP_KIDIV,
  46. .wLowerIntegralLimit = -(int32_t)IQMAX * (int32_t)SP_KIDIV,
  47. .hUpperOutputLimit = (int16_t)IQMAX,
  48. .hLowerOutputLimit = -(int16_t)IQMAX,
  49. .hKpDivisor = (uint16_t)SP_KPDIV,
  50. .hKiDivisor = (uint16_t)SP_KIDIV,
  51. .hKpDivisorPOW2 = (uint16_t)SP_KPDIV_LOG,
  52. .hKiDivisorPOW2 = (uint16_t)SP_KIDIV_LOG,
  53. .hDefKdGain = 0x0000U,
  54. .hKdDivisor = 0x0000U,
  55. .hKdDivisorPOW2 = 0x0000U,
  56. };
  57. /**
  58. * @brief PI / PID Iq loop parameters Motor 1
  59. */
  60. PID_Handle_t PIDIqHandle_M1 =
  61. {
  62. .hDefKpGain = (int16_t)PID_TORQUE_KP_DEFAULT,
  63. .hDefKiGain = (int16_t)PID_TORQUE_KI_DEFAULT,
  64. .wUpperIntegralLimit = (int32_t)INT16_MAX * TF_KIDIV,
  65. .wLowerIntegralLimit = (int32_t)-INT16_MAX * TF_KIDIV,
  66. .hUpperOutputLimit = INT16_MAX,
  67. .hLowerOutputLimit = -INT16_MAX,
  68. .hKpDivisor = (uint16_t)TF_KPDIV,
  69. .hKiDivisor = (uint16_t)TF_KIDIV,
  70. .hKpDivisorPOW2 = (uint16_t)TF_KPDIV_LOG,
  71. .hKiDivisorPOW2 = (uint16_t)TF_KIDIV_LOG,
  72. .hDefKdGain = 0x0000U,
  73. .hKdDivisor = 0x0000U,
  74. .hKdDivisorPOW2 = 0x0000U,
  75. };
  76. /**
  77. * @brief PI / PID Id loop parameters Motor 1
  78. */
  79. PID_Handle_t PIDIdHandle_M1 =
  80. {
  81. .hDefKpGain = (int16_t)PID_FLUX_KP_DEFAULT,
  82. .hDefKiGain = (int16_t)PID_FLUX_KI_DEFAULT,
  83. .wUpperIntegralLimit = (int32_t)INT16_MAX * TF_KIDIV,
  84. .wLowerIntegralLimit = (int32_t)-INT16_MAX * TF_KIDIV,
  85. .hUpperOutputLimit = INT16_MAX,
  86. .hLowerOutputLimit = -INT16_MAX,
  87. .hKpDivisor = (uint16_t)TF_KPDIV,
  88. .hKiDivisor = (uint16_t)TF_KIDIV,
  89. .hKpDivisorPOW2 = (uint16_t)TF_KPDIV_LOG,
  90. .hKiDivisorPOW2 = (uint16_t)TF_KIDIV_LOG,
  91. .hDefKdGain = 0x0000U,
  92. .hKdDivisor = 0x0000U,
  93. .hKdDivisorPOW2 = 0x0000U,
  94. };
  95. /**
  96. * @brief SpeednTorque Controller parameters Motor 1
  97. */
  98. SpeednTorqCtrl_Handle_t SpeednTorqCtrlM1 =
  99. {
  100. .STCFrequencyHz = MEDIUM_FREQUENCY_TASK_RATE,
  101. .MaxAppPositiveMecSpeedUnit = (uint16_t)(MAX_APPLICATION_SPEED_UNIT),
  102. .MinAppPositiveMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
  103. .MaxAppNegativeMecSpeedUnit = (int16_t)(-MIN_APPLICATION_SPEED_UNIT),
  104. .MinAppNegativeMecSpeedUnit = (int16_t)(-MAX_APPLICATION_SPEED_UNIT),
  105. .MaxPositiveTorque = (int16_t)NOMINAL_CURRENT,
  106. .MinNegativeTorque = -(int16_t)NOMINAL_CURRENT,
  107. .ModeDefault = DEFAULT_CONTROL_MODE,
  108. .MecSpeedRefUnitDefault = (int16_t)(DEFAULT_TARGET_SPEED_UNIT),
  109. .TorqueRefDefault = (int16_t)DEFAULT_TORQUE_COMPONENT,
  110. .IdrefDefault = (int16_t)DEFAULT_FLUX_COMPONENT,
  111. };
  112. PWMC_R3_2_Handle_t PWM_Handle_M1 =
  113. {
  114. {
  115. .pFctGetPhaseCurrents = &R3_2_GetPhaseCurrents,
  116. .pFctSwitchOffPwm = &R3_2_SwitchOffPWM,
  117. .pFctSwitchOnPwm = &R3_2_SwitchOnPWM,
  118. .pFctCurrReadingCalib = &R3_2_CurrentReadingPolarization,
  119. .pFctTurnOnLowSides = &R3_2_TurnOnLowSides,
  120. .pFctSetADCSampPointSectX = &R3_2_SetADCSampPointSectX,
  121. .pFctIsOverCurrentOccurred = &R3_2_IsOverCurrentOccurred,
  122. .pFctOCPSetReferenceVoltage = MC_NULL,
  123. .pFctRLDetectionModeEnable = MC_NULL,
  124. .pFctRLDetectionModeDisable = MC_NULL,
  125. .pFctRLDetectionModeSetDuty = MC_NULL,
  126. .hT_Sqrt3 = (PWM_PERIOD_CYCLES*SQRT3FACTOR)/16384u,
  127. .Sector = 0,
  128. .CntPhA = 0,
  129. .CntPhB = 0,
  130. .CntPhC = 0,
  131. .SWerror = 0,
  132. .TurnOnLowSidesAction = false,
  133. .OffCalibrWaitTimeCounter = 0,
  134. .Motor = M1,
  135. .RLDetectionMode = false,
  136. .Ia = 0,
  137. .Ib = 0,
  138. .Ic = 0,
  139. .DTTest = 0,
  140. .DTCompCnt = DTCOMPCNT,
  141. .PWMperiod = PWM_PERIOD_CYCLES,
  142. .OffCalibrWaitTicks = (uint16_t)((SYS_TICK_FREQUENCY * OFFCALIBRWAIT_MS)/ 1000),
  143. .Ton = TON,
  144. .Toff = TOFF
  145. },
  146. .Half_PWMPeriod = PWM_PERIOD_CYCLES/2u,
  147. .PhaseAOffset = 0,
  148. .PhaseBOffset = 0,
  149. .PhaseCOffset = 0,
  150. .pParams_str = &R3_2_ParamsM1
  151. };
  152. /**
  153. * @brief SpeedNPosition sensor parameters Motor 1 - HALL
  154. */
  155. HALL_Handle_t HALL_M1 =
  156. {
  157. ._Super = {
  158. .bElToMecRatio = POLE_PAIR_NUM,
  159. .hMaxReliableMecSpeedUnit = (uint16_t)(1.15*MAX_APPLICATION_SPEED_UNIT),
  160. .hMinReliableMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
  161. .bMaximumSpeedErrorsNumber = MEAS_ERRORS_BEFORE_FAULTS,
  162. .hMaxReliableMecAccelUnitP = 65535,
  163. .hMeasurementFrequency = TF_REGULATION_RATE_SCALED,
  164. .DPPConvFactor = DPP_CONV_FACTOR,
  165. },
  166. .SensorPlacement = HALL_SENSORS_PLACEMENT,
  167. .PhaseShift = (int16_t)(HALL_PHASE_SHIFT * 65536/360),
  168. .SpeedSamplingFreqHz = MEDIUM_FREQUENCY_TASK_RATE,
  169. .SpeedBufferSize = HALL_AVERAGING_FIFO_DEPTH,
  170. .TIMClockFreq = HALL_TIM_CLK,
  171. .TIMx = TIM2,
  172. .ICx_Filter = M1_HALL_IC_FILTER,
  173. .PWMFreqScaling = PWM_FREQ_SCALING,
  174. .HallMtpa = HALL_MTPA,
  175. .H1Port = M1_HALL_H1_GPIO_Port,
  176. .H1Pin = M1_HALL_H1_Pin<<8,
  177. .H2Port = M1_HALL_H2_GPIO_Port,
  178. .H2Pin = M1_HALL_H2_Pin<<8,
  179. .H3Port = M1_HALL_H3_GPIO_Port,
  180. .H3Pin = M1_HALL_H3_Pin<<8,
  181. };
  182. /**
  183. * Virtual temperature sensor parameters Motor 1
  184. */
  185. NTC_Handle_t TempSensorParamsM1 =
  186. {
  187. .bSensorType = VIRTUAL_SENSOR,
  188. .hExpectedTemp_d = 555,
  189. .hExpectedTemp_C = M1_VIRTUAL_HEAT_SINK_TEMPERATURE_VALUE,
  190. };
  191. /* Bus voltage sensor value filter buffer */
  192. uint16_t RealBusVoltageSensorFilterBufferM1[M1_VBUS_SW_FILTER_BW_FACTOR];
  193. /**
  194. * Bus voltage sensor parameters Motor 1
  195. */
  196. RDivider_Handle_t RealBusVoltageSensorParamsM1 =
  197. {
  198. ._Super =
  199. {
  200. .SensorType = REAL_SENSOR,
  201. .ConversionFactor = (uint16_t)(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR),
  202. },
  203. .VbusRegConv =
  204. {
  205. .regADC = ADC1,
  206. .channel = MC_ADC_CHANNEL_3,
  207. .samplingTime = M1_VBUS_SAMPLING_TIME,
  208. },
  209. .LowPassFilterBW = M1_VBUS_SW_FILTER_BW_FACTOR,
  210. .OverVoltageThreshold = OVERVOLTAGE_THRESHOLD_d,
  211. .UnderVoltageThreshold = UNDERVOLTAGE_THRESHOLD_d,
  212. .aBuffer = RealBusVoltageSensorFilterBufferM1,
  213. };
  214. UI_Handle_t UI_Params =
  215. {
  216. .bDriveNum = 0,
  217. };
  218. /** RAMP for Motor1.
  219. *
  220. */
  221. RampExtMngr_Handle_t RampExtMngrHFParamsM1 =
  222. {
  223. .FrequencyHz = TF_REGULATION_RATE
  224. };
  225. /**
  226. * @brief CircleLimitation Component parameters Motor 1 - Base Component
  227. */
  228. CircleLimitation_Handle_t CircleLimitationM1 =
  229. {
  230. .MaxModule = MAX_MODULE,
  231. .MaxVd = (uint16_t)(MAX_MODULE * 950 / 1000),
  232. .Circle_limit_table = MMITABLE,
  233. .Start_index = START_INDEX,
  234. };
  235. UFCP_Handle_t pUSART =
  236. {
  237. ._Super.RxTimeout = 0,
  238. .USARTx = USART1,
  239. };
  240. /* USER CODE BEGIN Additional configuration */
  241. /* USER CODE END Additional configuration */
  242. /******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/