1
0

Interrupt.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <MyProject.h>
  2. extern uint8 data g_1mTick; ///< 1ms滴答信号,每隔1ms在SYSTICK定时器被置1,需在大循环使用处清零
  3. int16 idata Power_Currt;
  4. /**
  5. @brief 低于预警中断与过温中断
  6. @brief 开启低压检测中断后,MCU会对输入电压进行监测,当输入电压低于设定值,则会触发中断
  7. @brief 开启过温保护中断后,MCU会对内部结温进行监测,当内部结温高于设定值,则会触发中断
  8. @date 2022-07-14
  9. */
  10. void LVW_TSD_INT(void) interrupt 0
  11. {
  12. if (ReadBit(LVSR, LVWIF))
  13. {
  14. if (ReadBit(LVSR, LVWF))
  15. {
  16. mcFaultSource = FaultUnderVoltageDC;
  17. ClrBit(LVSR, LVWF);
  18. }
  19. ClrBit(LVSR, LVWIF);
  20. }
  21. if (TSDIF)
  22. {
  23. if (ReadBit(LVSR, TSDF))
  24. {
  25. ClrBit(LVSR, TSDF);
  26. }
  27. TSDIF = 0;
  28. }
  29. }
  30. /**
  31. @brief 外部中断0
  32. @brief 一般用于响应IPM的FO过流信号
  33. @date 2022-07-14
  34. */
  35. void EXTERN0_INT(void) interrupt 1 // 外部中断0
  36. {
  37. if (IF0)
  38. {
  39. IF0 = 0; // clear P00 interrupt flag
  40. }
  41. }
  42. /**
  43. @brief FOC中断(Drv中断),每个载波周期执行一次,用于处理响应较高的程序,中断优先级第二
  44. @date 2022-07-14
  45. */
  46. void DRV_ISR(void) interrupt 3
  47. {
  48. if (ReadBit(DRV_SR, DCIF)) // 比较中断
  49. {
  50. SetReg(DRV_SR, 0xFF, SYSTIE | FGIF | DCIM1 | SYSTIF);
  51. }
  52. }
  53. /**
  54. @brief 定时器3中断服务函数
  55. @note 本例程中用于PWM调速信号捕获
  56. @date 2022-07-14
  57. */
  58. void TIM3_INT(void) interrupt 9
  59. {
  60. if (ReadBit(TIM3_CR1, T3IR))
  61. {
  62. ClrBit(TIM3_CR1, T3IR);
  63. }
  64. if (ReadBit(TIM3_CR1, T3IP))//周期中断
  65. {
  66. ClrBit(TIM3_CR1, T3IP);
  67. }
  68. if (ReadBit(TIM3_CR1, T3IF))
  69. {
  70. ClrBit(TIM3_CR1, T3IF);
  71. }
  72. }
  73. /**
  74. @brief 滴答定时器,默认用于产生1ms定时间隔
  75. @date 2022-07-14
  76. */
  77. void SYStick_INT(void) interrupt 10
  78. {
  79. if (ReadBit(DRV_SR, SYSTIF)) // SYS TICK中断
  80. {
  81. g_1mTick = 1;
  82. if (mcFocCtrl.State_Count > 0)
  83. { mcFocCtrl.State_Count--; }
  84. SetReg(DRV_SR, 0xFF, SYSTIE | FGIF | DCIF | DCIM1);
  85. }
  86. }
  87. /**
  88. @brief 比较器硬件过流保护,该中断仅提供 故障码 赋值,用于状态机的切换。
  89. 需要开启比较器CMP3 发生过流 自动清除MOE功能
  90. @date 2022-07-14
  91. */
  92. void CMP3_INT(void) interrupt 12
  93. {
  94. if (ReadBit(CMP_SR, CMP3IF))
  95. {
  96. if (mcState != mcPosiCheck)
  97. {
  98. mcFaultSource = FaultHardOVCurrent; // 硬件过流保护
  99. }
  100. ClrBit(CMP_SR, CMP3IF);
  101. }
  102. }
  103. void UART2_INT(void) interrupt 14
  104. {
  105. }