pwm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: pwm.h
  4. Partner Filename: pwm.c
  5. Description: The header file of pwm.c
  6. Complier: IAR Embedded Workbench for ARM 7.80.4
  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 PWM_H
  20. #define PWM_H
  21. /************************************************************************
  22. Compiler Directives (N/A)
  23. ************************************************************************/
  24. #ifdef _PWM_C_
  25. #define PWM_EXT
  26. #else
  27. #define PWM_EXT extern
  28. #endif
  29. #include "typedefine.h"
  30. /************************************************************************
  31. Definitions & Macros (#define ...)
  32. ************************************************************************/
  33. #define PWM_GEN_COF_DEFAULT \
  34. { \
  35. 15400, 13762, 2, 5250, 2625, 1313, 400, 2436 \
  36. } // Default value of PWM_CALC_COF
  37. #define PWM_GEN_OUT_DEFAULT \
  38. { \
  39. 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, IgnoreNone, SampleNone, 108, 0, FALSE, FALSE \
  40. } // Default value of PWM_GEN_OUT
  41. #define PWM_SQRT3 28378 // Q14, sqrt(3)
  42. #define PWM_1DIV3 5461 // Q14, 1/3
  43. #define PWM_SQRT3_INV 9459 // Q14, 1/sqrt(3)
  44. /************************************************************************
  45. TypeDefs & Structure defines for " XXX "
  46. ************************************************************************/
  47. typedef enum
  48. {
  49. IgnoreNone = 0,
  50. IgnoreA = 1,
  51. IgnoreB = 2,
  52. IgnoreC = 3,
  53. IgnoreAB = 4,
  54. IgnoreBC = 5,
  55. IgnoreAC = 6
  56. } RDSON_SAMPLE_AREA;
  57. typedef enum
  58. {
  59. SampleNone = 0,
  60. SampleA = 1,
  61. SampleB = 2,
  62. SampleC = 3,
  63. } SINGELR_SAMPLE_AREA;
  64. typedef struct
  65. {
  66. SWORD swUalphaPu; // Q14
  67. SWORD swUbetaPu; // Q14
  68. SWORD swUalphaCompPu; // Q14, Deadband compensation of Ualpha
  69. SWORD swUbetaCompPu; // Q14, Deadband compensation of Ubeta
  70. UWORD uwVdcPu; // Q14
  71. } PWM_GEN_IN;
  72. typedef struct // Input of " pwm_voGenCoef "
  73. {
  74. UWORD uwPWMDutyMax; // Real Value, Unit:%, Max duty ratio in svpwm
  75. UWORD uwPWM7To5Duty; // Real Value, Unit:%, Switch duty ratio from 7 to 5 svpwm
  76. UWORD uwPWMMinSample1Pu; // Q14, unit:Pu two zero vector
  77. UWORD uwPWMMinSample2Pu; // Q14, unit:Pu (one zero vector + sample time)*2
  78. UWORD uwPWMMinSample3Pu; // Q14, unit:Pu (one zero vector + sample time)*2
  79. UWORD uwOvmNo; // Real Value, Unit:1, Number of over modulation type
  80. UWORD uwPWMPd; // Real Value, Unit:1, PWM period
  81. UWORD uwSampleSteadyPu; //
  82. UWORD uwSingelResisSamplePu; //
  83. } PWM_COF_IN;
  84. typedef struct // Output of " pwm_voGenCoef "
  85. {
  86. UWORD swPWMDutyMaxPu; // Q14, unit:Pu, Max duty ratio in svpwm
  87. UWORD swPWM7To5DutyPu; // Q14, unit:Pu, Switch duty ratio from 7 to 5 svpwm
  88. UWORD swPWMMinSample1Pu; // Q14, unit:Pu two zero vector
  89. UWORD swPWMMinSample2Pu; // Q14, unit:Pu (one zero vector + sample time)*2
  90. UWORD swPWMMinSample3Pu; // Q14, unit:Pu (SignalResisToSteadyTime + sample time)*2
  91. UWORD swPWMPu; // Q14, unit:Pu (SignalResisToSteadyTime + sample time)*2
  92. UWORD uwOvmNo; // Q0, Number of over modulation type
  93. UWORD uwPWMPd; // Q0, PWM period
  94. UWORD uwHPWMPd; // Q0, half PWM period
  95. UWORD uwHHPWMPd; // Q0, half of half PWM period
  96. ULONG ulPWMPerInv; // Q21, unit:Pu, 1/PWM period
  97. UWORD uwMaxCmpCt; // Q14, unit:Pu, Max compare value in svpwm
  98. UWORD uwSampleSteadyCt;
  99. UWORD uwSingelResisSampleCt; // Q14, unit:Pu,
  100. } PWM_CALC_COF;
  101. typedef struct
  102. {
  103. SWORD swUalphaPu; // Q14
  104. SWORD swUbetaPu; // Q14
  105. UWORD uwFirstTrigCOMPR;
  106. UWORD uwSecondTrigCOMPR;
  107. UWORD uwNewTIM1COMPR[6];
  108. UWORD uwNewSectorNum;
  109. UWORD uwOldTrig;
  110. UWORD uwNewTrig;
  111. UWORD uwPWMNewSectorNum;
  112. RDSON_SAMPLE_AREA uwSampleArea;
  113. SINGELR_SAMPLE_AREA uwSingelRSampleArea;
  114. UWORD uwRDSONTrig;
  115. UWORD uwSigRTrig;
  116. BOOL blOvmFlag;
  117. BOOL blSampleCalibFlag;
  118. } PWM_GEN_OUT;
  119. /************************************************************************
  120. Exported Variables:
  121. ************************************************************************/
  122. #ifdef _PWM_C_
  123. PWM_EXT PWM_CALC_COF pwm_stGenCoef = PWM_GEN_COF_DEFAULT;
  124. PWM_EXT PWM_GEN_OUT pwm_stGenOut = PWM_GEN_OUT_DEFAULT;
  125. #else
  126. PWM_EXT PWM_CALC_COF pwm_stGenCoef;
  127. PWM_EXT PWM_GEN_OUT pwm_stGenOut;
  128. #endif
  129. /************************************************************************
  130. RAM ALLOCATION:
  131. ************************************************************************/
  132. #define pwm_stGenCoefIn (*(PWM_COF_IN *)MN_BUFFER)
  133. #define pwm_stGenIn (*(PWM_GEN_IN *)TBC_BUFFER)
  134. /************************************************************************
  135. Exported Function Call Prototypes (N/A)
  136. ************************************************************************/
  137. #ifdef _PWM_C_
  138. PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out);
  139. PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef);
  140. PWM_EXT void pwm_voInit(void);
  141. #else
  142. PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out);
  143. PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef);
  144. PWM_EXT void pwm_voInit(void);
  145. #endif
  146. /************************************************************************
  147. Local Function Call Prototypes (N/A)
  148. ************************************************************************/
  149. /************************************************************************
  150. Flag Define (N/A)
  151. ************************************************************************/
  152. /***********************************************************************/
  153. #endif
  154. /************************************************************************
  155. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  156. All rights reserved.
  157. *************************************************************************
  158. End of this File (EOF):
  159. Do not put anything after this part!
  160. ************************************************************************/