/* * interrupts.c * * Created on: 21 авг. 2023 г. * Author: seklyuts */ #include #include "f28x_project.h" #include "frm_uart.h" #include "gpio_init.h" #include "i2c_init.h" #include "timer_base.h" #include "vector.h" #include "pwm_interrupts.h" #include "sdfm.h" volatile uint16_t AutoChange = 0; volatile uint16_t PWM_out = 2500; //volatile uint16_t PWM_motor = PERIOD_2; uint16_t Fault = 0, Fault_fix = 0, Ready = 0, Ready_Fix = 0; uint16_t counter1s=0; uint16_t FaultABC = 0, FaultABCFix = 0; uint16_t PwmFlagStartADC = 0; typedef struct { int16_t UA; int16_t UB; int16_t UC; }strPWMABC; volatile strPWMABC PWM_motor = {PERIOD_2, PERIOD_2, PERIOD_2}; void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC) { int16_t A,B,C; A = (int16_t)(phaseA*(PERIOD_2/100.0)); B = (int16_t)(phaseB*(PERIOD_2/100.0)); C = (int16_t)(phaseC*(PERIOD_2/100.0)); if(A > 0) A+= EPWM_DB/2; else if(A < 0) A-= EPWM_DB/2; if(B > 0) B+= EPWM_DB/2; else if(B < 0) B-= EPWM_DB/2; if(C > 0) C+= EPWM_DB/2; else if(C < 0) C-= EPWM_DB/2; PWM_motor.UA = PERIOD_2 + A; PWM_motor.UB = PERIOD_2 + B; PWM_motor.UC = PERIOD_2 + C; FaultABC = (FaultAL + (FaultAH<<1) + (FaultBL<<2) + (FaultBH<<3) + (FaultCL<<4) + (FaultCH<<5) ); if(FaultABC) FaultABCFix = FaultABC; if((FaultABC)||(FaultABCFix)) { PWM_ABC_StopAllClose(); PWM_motor.UA = PERIOD_2; PWM_motor.UB = PERIOD_2; PWM_motor.UC = PERIOD_2; vectorFault(); } EPwm2Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UA; EPwm3Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UB; EPwm4Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UC; } // // epwm1_isr - EPWM1 ISR // __interrupt void epwm1_isr(void) { // if(AutoChange) pwm_AutoChange(1); // else EPwm1Regs.CMPA.bit.CMPA = PWM_out; // // Clear INT flag for this timer // EPwm1Regs.ETCLR.bit.INT = 1; MainTimerBaseTimeoutInc(); // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; } // // epwm2_isr - EPWM2 ISR // __interrupt void epwm2_isr(void) { Gpio57out(1); // EALLOW; // Sdfm1Regs.SDDFPARM4.bit.FEN = 1; // EDIS; // GpioDataRegs.GPADAT.bit.GPIO0 = 1; // // Clear INT flag for this timer // EPwm2Regs.ETCLR.bit.INT = 1; TimerBaseTimeoutInc(); if(PwmFlagStartADC) /// ацп не запустился, ток не был измерен { PwmFlagStartADC = 0; FMSTR_enable_set(); } // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; // GpioDataRegs.GPADAT.bit.GPIO0 = 0; Gpio57out(0); } // // epwm3_isr - EPWM3 ISR // __interrupt void epwm3_isr(void) { EPwm3Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UB; // // Clear INT flag for this timer // EPwm3Regs.ETCLR.bit.INT = 1; // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; } __interrupt void epwm4_isr(void) { EPwm4Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UC; // // Clear INT flag for this timer // EPwm4Regs.ETCLR.bit.INT = 1; // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; } __interrupt void epwm5_isr(void) { // Ready = GpioDataRegs.GPADAT.bit.GPIO19; // if(Ready == 0) // { // Ready_Fix = 0; // } // Fault = !GpioDataRegs.GPADAT.bit.GPIO18; // if(Fault) Fault_fix = 1; // if(Fault_fix) // { // EPwm5Regs.CMPA.bit.CMPA = PERIOD_BRAKE; // PWM_out = 0; // } // else // { EPwm5Regs.CMPA.bit.CMPA = PERIOD_BRAKE - PWM_out; // } // // Clear INT flag for this timer // EPwm5Regs.ETCLR.bit.INT = 1; // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; } float Volt=0; __interrupt void epwm6_isr(void) { EPwm6Regs.CMPA.bit.CMPA = PERIOD_MOTOR - PWM_out; // // Clear INT flag for this timer // EPwm6Regs.ETCLR.bit.INT = 1; // // Acknowledge this interrupt to receive more interrupts from group 3 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; } uint16_t PWM_test = SDFM_DELAY; __interrupt void epwm11_isr(void) { // Gpio55out(1); EPwm11Regs.CMPA.bit.CMPA = PWM_test; EPwm11Regs.CMPB.bit.CMPB = PWM_test; EPwm11Regs.CMPC = PWM_test; EPwm11Regs.CMPD = PWM_test; sdfm_start_conversion_current(); PwmFlagStartADC = 1; EPwm11Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; // Gpio55out(0); } void pwm_clr_PwmFlagStartADC(void) { PwmFlagStartADC = 0; } // // InitEPwm1Example - Initialize EPWM1 configuration //