| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /********************************************************************************
- **** Copyright (C), 2018, Fortior Technology Co., Ltd. ****
- ********************************************************************************
- File Name : Interrupt.c
- Author : Bruce HW&RD
- Date : 2018-12-27
- Description : .C file function description
- Version : 1.0
- Function List :
- Record :
- 1.Date : 2018-12-27
- Author : Bruce HW&RD
- Modification: Created file
- ********************************************************************************/
- #include "FU68xx_5.h"
- #include <Myproject.h>
- void LVW_TSD_INT(void) interrupt 0 //LVW & TSD interrupt
- {
- if (ReadBit(LVSR, LVWIF))
- {
- if (ReadBit(LVSR, LVWF))
- {
- FaultProcess();
- ClrBit(LVSR, LVWF);
- }
-
- ClrBit(LVSR, LVWIF);
- }
-
- if (TSDIF)
- {
- TSDIF = 0;
- }
- }
- /* -------------------------------------------------------------------------------------------------
- Function Name : void FO_INT(void)
- Description : FO_INT interrupt,硬件FO过流保护,关断输出,中断优先级最高
- Input : 无
- Output : 无
- -------------------------------------------------------------------------------------------------*/
- void FO_INT(void) interrupt 1 // 硬件FO过流中断,关闭输出
- {
- if (IF0)
- {
- FaultProcess(); // 关闭输出
- mcFaultSource = FaultHardOVCurrent; // 硬件过流保护
- IF0 = 0; // clear P00 interrupt flag
- }
- }
- /* -------------------------------------------------------------------------------------------------
- Function Name : EXTERN_INT1
- Description : interrupt1
- Input : 无
- Output : 无
- -------------------------------------------------------------------------------------------------*/
- void EXTERN_INT1(void) interrupt 2
- {
- if (ReadBit(P1_IF, P12))
- {
- ClrBit(P1_IF, P12);
- }
- }
- /* -------------------------------------------------------------------------------------------------
- Function Name : void CMP3_INT(void)
- Description : CMP3:硬件比较器过流保护,关断输出,中断优先级最高
- Input : 无
- Output : 无
- -------------------------------------------------------------------------------------------------*/
- void CMP3_INT(void) interrupt 12
- {
- if (ReadBit(CMP_SR, CMP3IF))
- {
- FaultProcess(); // 关闭输出
- mcFaultSource = FaultHardOVCurrent; // 硬件过流保护
- ClrBit(CMP_SR, CMP3IF);
- }
- }
- /*---------------------------------------------------------------------------*/
- /* Name : void DRV_ISR(void) interrupt 3
- /* Input : NO
- /* Output : NO
- /* Description: FOC中断(Drv中断),每个载波周期执行一次,用于处理响应较高的程序,中断优先级第二。DCEN开了就会产生中断。
- /*---------------------------------------------------------------------------*/
- void DRV_ISR(void) interrupt 3
- {
- if (ReadBit(DRV_SR, DCIF)) // 比较中断
- {
- SetBit(ADC_CR, ADCBSY); // 使能ADC的DCBUS采样
- dog_Status |= 0x01;
- Fault_Overcurrent(); //软件过流保护
- // UdcMax_Min(); //udc最大值最小值获取
- #if (FiledWeakenCompEnable)
- {
- FiledWeakenControl(FOC__UD, FOC__UQ, udc.WeakenUsRef, mcFocCtrl.IsRef);
-
- if (mcFieldWeaken.mcIdref < ID_Limit)
- {mcFieldWeaken.mcIdref = ID_Limit;}
-
- mcFocCtrl.IdRef = mcFieldWeaken.mcIdref;
- mcFocCtrl.IqRef = mcFieldWeaken.mcIqref;
- }
- #else
- {
- mcFocCtrl.IqRef = mcFocCtrl.IsRef;
- mcFocCtrl.IdRef = 0;
- }
- #endif
- ID_IQ_Control(); //dq轴电流赋值
- #if (VoltageCompensationEn==1)
- VoltageCompensation();//电压补偿
- #endif
- #if (Debugg==1)
- {
- Trace_Select_read();
- PC_MONITOR_PWM(); //工具
- }
- #else
- {
- trace1();
- }
- #endif
- DRV_SR = (DRV_SR | SYSTIF) & (~DCIF);
- }
- }
- /*---------------------------------------------------------------------------*/
- /* Name : void TIM4S_INT(void) interrupt 10
- /* Input : NO
- /* Output : NO
- /* Description: 1ms定时器中断(SYS TICK中断),用于处理附加功能,如控制环路响应、各种保护等。中断优先级低于FO中断和FOC中断。
- /*---------------------------------------------------------------------------*/
- void SYStick_INT(void) interrupt 10
- {
- if (ReadBit(DRV_SR, SYSTIF)) // SYS TICK中断
- {
- dog_Status |= 0x02;
- flag_1ms_main = 1;
-
- /****速度滤波、反电动势滤波*****/
- if ( (mcState == mcStart) || (mcState == mcRun) || (mcState == mcStop))
- {
- mcFocCtrl.SpeedFlt = LPF_realize(FOC__EOME, mcFocCtrl.SpeedFlt, LPF_K(71.0)); //LPF_K(30.0)
- mcFocCtrl.UDFlt = LPF_realize(FOC__UD, mcFocCtrl.UDFlt, LPF_K(30.0)); //LPF_K(30.0)
- mcFocCtrl.UQFlt = LPF_realize(FOC__UQ, mcFocCtrl.UQFlt, LPF_K(30.0)); //LPF_K(30.0)
- }
- else
- {
- mcFocCtrl.SpeedFlt = 0;
- }
-
- Speed_response(); //压机环路响应,速度环
- Fault_Detection(); //故障保护函数功能
- // PFC_timer1ms(); //pfc控制1ms中断
- User_Dri_timer1ms(); //user控制1ms中断
- IsLimit_Over_tect(); //限流处理
- LED_Display(); //LED灯故障显示
- #if (Debugg==1)
- {
- PC_MONITOR_1MS(); //工具
- CMDMONI_WT_SENDCMD();
- }
- #endif
-
- /*串口相关*/
- if (Uart.ResponseFlag == 1)
- {
- Uart.send_delay_time++;
- }
-
- if (mcFocCtrl.mcAcbustime < 30000)
- {
- mcFocCtrl.mcAcbustime++;
- }
-
- if (Uart.time_cnt < 20000)
- {
- Uart.time_cnt++;
- }
-
- if (Uart.time_shuju < 30000)
- {
- Uart.time_shuju++;
- }
-
- if (mcFocCtrl.State_Count > 0)
- {
- mcFocCtrl.State_Count--;
- }
-
- if (Time.PowerOnCnt < 60000)
- {
- Time.PowerOnCnt++;
- }
-
- if (mcFaultDect.commu_time < 60000)
- {
- mcFaultDect.commu_time++;
- }
-
- if (Uartwatch.uarttimejishu <= 250)
- {
- Uartwatch.uarttimejishu++;
- }
-
- StarRampDealwith();/*****电机启动爬坡函数处理*****/
- DRV_SR = (DRV_SR | DCIF) & (~SYSTIF);// 清零标志位
- }
- }
- /*---------------------------------------------------------------------------*/
- /* Name : void USART_INT(void) interrupt 12
- /* Input : NO
- /* Output : NO
- /* Description: 串口中断,中断优先级最低,用于接收调速信号,无中断插入时8us
- /*---------------------------------------------------------------------------*/
- void USART_INT(void) interrupt 14
- {
- // 睡眠模式下,再次接收到串口通讯信号,从待机模式中唤醒
- if (UT2RI == 1)
- {
- UT2RI = 0;
- Uart.uarttimejishu = 0;
-
- if (Uart.Recive_Flag == 0)
- {
- UartRecive1();
- }
- }
-
- if (UT2TI == 1)
- {
- UT2TI = 0;
- UartSend1();
- }
- }
- /*工具串口*/
- uint8 fasong = 0;
- extern uint8 txbuff;
- void USART_INT1(void) interrupt 13
- {
- #if (Debugg==1)
- {
- if (TI == 1)
- {
- TI = 0;
- fasong = 0;
- }
- }
- #endif
-
- if (RI == 1)
- {
- RI = 0;
- #if (Debugg==1)
- {
- PC_MONITOR_INTR();
- }
- #else
- {
- UART1RCE();
- }
- #endif
- }
- }
|