var.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * var.c
  3. *
  4. * Created on: 2023Äê5ÔÂ17ÈÕ
  5. * Author: wangd
  6. */
  7. #include "var.h" // DSP2803x Examples Include File
  8. #ifndef TRUE
  9. #define FALSE 0
  10. #define TRUE 1
  11. #endif
  12. union FAULTFLAG_UNI FaultFlag;
  13. Uint16 DCbus_voltage=0;
  14. Uint32 IsrTime = 0;
  15. _iq test =0;
  16. int16 test2 =0;
  17. int16 Tmotor = 0;
  18. PI_CONTROLLER pid1_idc = PI_CONTROLLER_DEFAULTS;
  19. PI_CONTROLLER pid1_spd = PI_CONTROLLER_DEFAULTS;
  20. RMPCNTL rc1 = RMPCNTL_DEFAULTS;
  21. int32 pwmlimit = 32768;
  22. _iq SpeedRef=_IQ(0.0);//³õʼËÙ¶È
  23. int16 Direction = 1;
  24. _iq BemfA=0;
  25. _iq BemfB=0;
  26. _iq BemfC=0;
  27. _iq Iphase=0;
  28. _iq DC_current_real = 0;
  29. _iq DC_current_filer = 0;
  30. int32 DC_current_avr = 0;
  31. int32 DC_current_filter_avr = 0;
  32. int16 Tvot = 0;
  33. _iq CurrentSet = _IQ(0.0);
  34. Uint16 Fault_clear = 0;
  35. int32 XintTime = 60000000;
  36. volatile Uint16 EnableFlag = FALSE;
  37. void InitVar(void){
  38. FaultFlag.all = 0;
  39. // Initialize the PI module for dc-bus current
  40. pid1_idc.Kp = _IQ(0.05);
  41. pid1_idc.Ki = _IQ(0.0002);
  42. pid1_idc.Umax = _IQ((float)pwmlimit/32767);
  43. pid1_idc.Umin = _IQ((float)(-pwmlimit)/32767);
  44. // Initialize the PI module for speed
  45. pid1_spd.Kp = _IQ(1.0);
  46. pid1_spd.Ki = 360;//_IQ(0.0002);
  47. pid1_spd.Umax = _IQ(1.0);
  48. pid1_spd.Umin = _IQ(0.0);
  49. // Initialize RMPCNTL module
  50. rc1.RampDelayMax = 5;
  51. rc1.RampLowLimit = _IQ(-1.0);
  52. rc1.RampHighLimit = _IQ(1.0);
  53. }
  54. void FaultTreat(void){
  55. OverVoltage();
  56. OverMotorRpm();
  57. OverMotCtrTemp();
  58. }
  59. void OverVoltage(void)
  60. {
  61. static int16 i = 0;
  62. static int16 j = 0;
  63. if (DCbus_voltage >= 360)
  64. {
  65. i = 20000;
  66. FaultFlag.bit.OverVolFlag = 1;
  67. }
  68. else if (DCbus_voltage <= 200) //80
  69. {
  70. j = 10000;
  71. FaultFlag.bit.LowVolFlag = 1;
  72. }
  73. else
  74. {
  75. if (FaultFlag.bit.OverVolFlag == 1)
  76. {
  77. i--;
  78. if (i <= 0)
  79. {
  80. i = 0;
  81. FaultFlag.bit.OverVolFlag = 0;
  82. }
  83. }
  84. else
  85. {
  86. i = 0;
  87. }
  88. if (FaultFlag.bit.LowVolFlag == 1)
  89. {
  90. j--;
  91. if (j <= 0)
  92. {
  93. j = 0;
  94. FaultFlag.bit.LowVolFlag = 0;
  95. }
  96. }
  97. else
  98. {
  99. j = 0;
  100. }
  101. }
  102. }
  103. void OverMotorRpm(void)
  104. {
  105. if (speed1.BaseRpm >= 3800)
  106. {
  107. FaultFlag.bit.OverRpmFlag = 1;
  108. }
  109. else if (speed1.BaseRpm < 100)
  110. {
  111. FaultFlag.bit.OverRpmFlag = 0;
  112. }
  113. }
  114. void OverMotCtrTemp(void)
  115. {
  116. if (Tmotor >= 85)
  117. {
  118. FaultFlag.bit.OverMotTempFlag = 1;
  119. }
  120. else if (Tmotor < 50)
  121. {
  122. FaultFlag.bit.OverMotTempFlag = 0;
  123. }
  124. if (Tvot >= 85)
  125. {
  126. FaultFlag.bit.IgbtTempFaultFlag = 1;
  127. }
  128. else if (Tvot < 50)
  129. {
  130. FaultFlag.bit.IgbtTempFaultFlag = 0;
  131. }
  132. }