protect_def.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. @copyright None
  3. @file protect_def.h
  4. @author Comment Vivre
  5. @date 2025-12-29
  6. @brief None
  7. */
  8. #ifndef __PROTECT_DEF_H_
  9. #define __PROTECT_DEF_H_
  10. #include <FU65_72.h>
  11. // 单相缺相计数更新宏:保持原有判定逻辑不变
  12. #define UPDATE_PHASE_LOSS_CNT(max_self, max_o1, max_o2, cnt) \
  13. do { \
  14. if ((((max_self) > ((max_o1) << 1)) || ((max_self) > ((max_o2) << 1))) &&\
  15. ((max_self) > PHASE_NOLOAD_CURR)) \
  16. { cnt++; } \
  17. else if (cnt) \
  18. { cnt--; } \
  19. } while (0)
  20. /**
  21. @brief 故障恢复延时计数宏
  22. @param cnt 对应故障的延时计数器变量
  23. @note 用于故障恢复逻辑,当检测条件已恢复正常后,
  24. 不会立刻清除故障,而是等待计数超过
  25. PROTECT_RECOVER_TIME 后才解除故障,
  26. 以避免抖动恢复。
  27. */
  28. #define RECOVER_DELAY(cnt) \
  29. do { \
  30. cnt++; \
  31. if (cnt > PROTECT_RECOVER_TIME) { \
  32. cnt = 0; \
  33. FaultSource = SYS_NO_FAULT; \
  34. } \
  35. } while(0)
  36. /**
  37. @brief 通用的故障计数检测宏
  38. @param cnt 计数器变量
  39. @param cond 检测条件 (true 表示异常)
  40. @param threshold 连续超过阈值次数才判定故障
  41. @param faultCode 触发的故障源代码
  42. */
  43. #define FAULT_COUNT_UPDOWN(cnt, cond, threshold, faultCode) \
  44. do { \
  45. if (cond) { \
  46. if (++(cnt) > (threshold)) { \
  47. cnt = 0; \
  48. FaultSource = (faultCode); \
  49. } \
  50. } else if (cnt) { \
  51. cnt--; \
  52. } \
  53. } while (0)
  54. typedef enum
  55. {
  56. SYS_NO_FAULT = 0x00,
  57. // 过流类
  58. HARD_OVER_CURR = 0x11,
  59. SOFT_OVER_CURR = 0x12,
  60. FAN_OVER_CURR = 0x13,
  61. // 自检类
  62. FCT_BUS_OFFSET = 0x21,
  63. FCT_LOSS_PHASE = 0x22,
  64. FCT_SHORT_UP_BRIDGE = 0x23,
  65. FCT_SHORT_DOWN_BRIDGE = 0x24,
  66. FCT_SHORT_PHASE = 0x25,
  67. // 运行类
  68. MOTOR_STALL = 0x31,
  69. OVER_POWER = 0x32,
  70. // 过欠压类
  71. VDC_OVER = 0x41,
  72. VDC_UNDER = 0x42,
  73. MCU_LVM = 0x43,
  74. // 温度类
  75. TEMPER_NTC = 0x51,
  76. TEMPER_MOTOR = 0x52,
  77. TEMPER_IPM = 0x53,
  78. TEMPER_TSD = 0x54,
  79. // 通讯类
  80. LOSS_UART = 0x61,
  81. LOSS_PWM = 0x62
  82. } Fault_Type_e;
  83. extern Fault_Type_e xdata FaultSource;
  84. typedef struct
  85. {
  86. // 检测数据
  87. uint16_t BackEMF; // 反电动势
  88. int16_t ActualSpeed; // 实际速度
  89. uint16_t BusVoltage; // 母线电压
  90. uint16_t NTCTemper; // NTC温度
  91. int16_t BusCurr; // 估算母线电流
  92. uint16_t Power; // 估算功率
  93. // 三相电流极值
  94. uint16_t MaxIa;
  95. uint16_t MaxIb;
  96. uint16_t MaxIc;
  97. // 保护检测计数
  98. struct
  99. {
  100. uint16_t DelayPhase;
  101. uint16_t LossPhase;
  102. uint16_t PhaseA;
  103. uint16_t PhaseB;
  104. uint16_t PhaseC;
  105. uint16_t CloseLoop;
  106. uint16_t DelayStall;
  107. uint16_t EsValue;
  108. uint16_t StallSpeed;
  109. uint16_t OverVolt;
  110. uint16_t UnderVolt;
  111. uint8_t OverCurr;
  112. uint16_t OverTemper;
  113. uint16_t OverPower;
  114. uint16_t PwmLoss;
  115. uint16_t UartLoss;
  116. } CheckCnt;
  117. // 恢复计数
  118. struct
  119. {
  120. uint16_t Stall;
  121. uint16_t OverVolt;
  122. uint16_t UnderVolt;
  123. uint16_t OverCurr;
  124. uint16_t OverTemper;
  125. uint16_t OverPower;
  126. uint16_t PhaseLoss;
  127. uint16_t PWMLoss;
  128. uint16_t UartLoss;
  129. } RecoverCnt;
  130. } Fault_Check_t;
  131. extern Fault_Check_t xdata faultCheck;
  132. #endif