glbcof.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: glbcof.c
  4. Partner Filename: glbcof.h
  5. Description: The global coefficients
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  7. CPU TYPE : GD32F3x0
  8. *************************************************************************
  9. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives:
  18. *************************************************************************/
  19. #ifndef _GLBCOF_C_
  20. #define _GLBCOF_C_
  21. #endif
  22. /************************************************************************
  23. Included File
  24. *************************************************************************/
  25. #include "syspar.h"
  26. #include "user.h"
  27. /************************************************************************
  28. Constant Table (N/A)
  29. *************************************************************************/
  30. /*************************************************************************
  31. Exported Functions (N/A)
  32. *************************************************************************/
  33. /***************************************************************
  34. Function: cof_voSysInit;
  35. Description: global power on initialization
  36. Call by:
  37. Input Variables: N/A
  38. Output/Return Variables: N/A
  39. Subroutine Call: N/A;
  40. Reference: N/A
  41. ****************************************************************/
  42. void cof_voSysInit(void)
  43. {
  44. /*=======================================================================
  45. Base value
  46. =======================================================================*/
  47. cof_uwUbVt = VBASE; /* unit: 0.1V, Voltage base */
  48. cof_uwIbAp = IBASE; /* unit: 0.01A, Current base */
  49. cof_uwFbHz = FBASE; /* unit: Hz, Frequency base */
  50. cof_uwTorqNm = TORQUEBASE; /* unit:0.1Nm, torque base */
  51. cof_uwPairs = cp_stMotorPara.swMotrPolePairs; /* Pole pairs base */
  52. cof_uwWebRadps =(ULONG) 2 * 31416 * cof_uwFbHz / 1000; /* unit: 0.1rad/s, Electrical radian frequency base */
  53. cof_uwTbUs = 100000000 / cof_uwWebRadps; /* unit: 0.1us, Time base */
  54. cof_uwRbOm = (ULONG)cof_uwUbVt * 100000 / cof_uwIbAp; /* unit: 0.1mOhm, Resistance base */
  55. cof_uwLbHm = (ULONG)cof_uwRbOm * 100000 / cof_uwWebRadps; /* unit: 0.01uH, Inductance base */
  56. cof_uwFluxbWb = (ULONG)cof_uwUbVt * 1000000 / cof_uwWebRadps; /* unit: 0.001mWb, Flux linkage base */
  57. cof_uwPbWt = (ULONG)3 * cof_uwUbVt * cof_uwIbAp / 100 >> 1; /* unit: 0.1w, Power base */
  58. cof_uwWmb = (ULONG)cof_uwWebRadps / cof_uwPairs; /* unit: 0.1rad/s, Mechanical radian frequency base */
  59. cof_uwTbNm = (ULONG)cof_uwPbWt * 1000 / cof_uwWmb; /* unit: mNm, Torque base */
  60. cof_uwJb = (ULONG)cof_uwTbNm * cof_uwTbUs * 10 / cof_uwWmb; /* unit: 10^-10*kg*m2, Rotational inertia base */
  61. cof_uwVbRpm = (ULONG)cof_uwFbHz * 60 / cof_uwPairs; /* unit: rpm, Velocity base */
  62. /*=======================================================================
  63. Pu value
  64. =======================================================================*/
  65. cof_uwTCurCtrPu = 2 * 102944 * cof_uwFbHz / FTBC_HZ; /* Q15, Current control period Pu, pi(Q15)=102944 */
  66. cof_uwTSpdCtrPu = 2 * 12868 * cof_uwFbHz / FTBS_HZ; /* Q12, Speed control period Pu, pi(Q12)=12868 */
  67. cof_uwRsPu = ((ULONG)cp_stMotorPara.swRsOhm << 15) / cof_uwRbOm; /* Q15, Phase resistance */
  68. cof_uwLdPu = ((ULONG)cp_stMotorPara.uwLdmH << 10) / cof_uwLbHm; /* Q10, D axis inductance */
  69. cof_uwLqPu = ((ULONG)cp_stMotorPara.uwLqmH << 10) / cof_uwLbHm; /* Q10, Q axis inductance */
  70. cof_uwFluxPu = ((ULONG)cp_stMotorPara.swFluxWb << 12) / cof_uwFluxbWb; /* Q12, Flux linkage */
  71. cof_uwJmPu = ((ULONG)cp_stMotorPara.swJD * 1000) / cof_uwJb; /* Q0, Rotational inertia */
  72. cof_swIdMinPu = ((SLONG)cp_stMotorPara.swIdMinA << 14) / cof_uwIbAp; /* Q14, Min d axis current (Charactoristic current) */
  73. cof_swIdMaxPu = ((SLONG)cp_stMotorPara.swIdMaxA << 14) / cof_uwIbAp; /* Q14, Max d axis current */
  74. cof_uwCurMaxPu = ((ULONG)cp_stMotorPara.swIpeakMaxA << 14) / cof_uwIbAp; /* Q14, Max phase current (peak value) */
  75. cof_uwPwrMaxPu = ((ULONG)M_POWER_MAX_WT << 14) * 10 / cof_uwPbWt; /* Q14, Max power of motor input */
  76. cof_uwLdMinPu = ((ULONG)M_LD_MIN_MH << 10) / cof_uwLbHm; /* Q10, D axis inductance */
  77. cof_uwLqMinPu = ((ULONG)M_LQ_MIN_MH << 10) / cof_uwLbHm; /* Q10, Q axis inductance */
  78. /*=======================================================================
  79. Time value
  80. =======================================================================*/
  81. cof_ulTbc10MsCt = TBC_MS2CT(10); /* ms to count in TBC */
  82. cof_ulTbc20MsCt = TBC_MS2CT(20); /* ms to count in TBC */
  83. cof_ulTbc50MsCt = TBC_MS2CT(50); /* ms to count in TBC */
  84. cof_ulTbc60MsCt = TBC_MS2CT(60); /* ms to count in TBC */
  85. cof_ulTbc100MsCt = TBC_MS2CT(100); /* ms to count in TBC */
  86. cof_ulTbc200MsCt = TBC_MS2CT(200); /* ms to count in TBC */
  87. cof_ulTbc250MsCt = TBC_MS2CT(250); /* ms to count in TBC */
  88. cof_ulTbc300MsCt = TBC_MS2CT(300); /* ms to count in TBC */
  89. cof_ulTbc400MsCt = TBC_MS2CT(400); /* ms to count in TBC */
  90. cof_ulTbc450MsCt = TBC_MS2CT(450); /* ms to count in TBC */
  91. cof_ulTbc500MsCt = TBC_MS2CT(500); /* ms to count in TBC */
  92. cof_ulTbc1SCt = TBC_S2CT(1); /* s to count in TBC */
  93. cof_ulTbc2SCt = TBC_S2CT(2); /* s to count in TBC */
  94. /*=======================================================================
  95. Angle value
  96. =======================================================================*/
  97. cof_sl0DegreePu = ANG_DEG2PU(0);
  98. cof_sl30DegreePu = ANG_DEG2PU(30);
  99. cof_sl60DegreePu = ANG_DEG2PU(60);
  100. cof_sl90DegreePu = ANG_DEG2PU(90);
  101. cof_sl120DegreePu = ANG_DEG2PU(120);
  102. cof_sl150DegreePu = ANG_DEG2PU(150);
  103. cof_sl180DegreePu = ANG_DEG2PU(180);
  104. cof_sl210DegreePu = ANG_DEG2PU(210);
  105. cof_sl240DegreePu = ANG_DEG2PU(240);
  106. cof_sl270DegreePu = ANG_DEG2PU(270);
  107. cof_sl300DegreePu = ANG_DEG2PU(300);
  108. cof_sl330DegreePu = ANG_DEG2PU(330);
  109. cof_sl360DegreePu = ANG_DEG2PU(360);
  110. cof_sl720DegreePu = ANG_DEG2PU(720);
  111. /*=======================================================================
  112. Speed value
  113. =======================================================================*/
  114. cof_uw80RpmPu = SPD_RPM2PU(80);
  115. cof_uw100RpmPu = SPD_RPM2PU(100);
  116. cof_uw200RpmPu = SPD_RPM2PU(200);
  117. cof_uw250RpmPu = SPD_RPM2PU(250);
  118. cof_uw300RpmPu = SPD_RPM2PU(300);
  119. cof_uw330RpmPu = SPD_RPM2PU(330);
  120. cof_uw600RpmPu = SPD_RPM2PU(600);
  121. cof_uw1000RpmPu = SPD_RPM2PU(1000);
  122. cof_uw1500RpmPu = SPD_RPM2PU(1500);
  123. cof_uw2800RpmPu = SPD_RPM2PU(2800);
  124. cof_uw3000RpmPu = SPD_RPM2PU(3000);
  125. }
  126. /*************************************************************************
  127. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  128. All rights reserved.
  129. *************************************************************************/
  130. #ifdef _GLBCOF_C_
  131. #undef _GLBCOF_C_
  132. #endif
  133. /*************************************************************************
  134. End of this File (EOF)!
  135. Do not put anything after this part!
  136. *************************************************************************/