MotorControlModuleSDFM_TMS3.../Projects/epwm_test/src/Peripherals/pwm_interrupts.c

275 lines
5.7 KiB
C
Raw Normal View History

/*
* interrupts.c
*
* Created on: 21 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
* Author: seklyuts
*/
#include <pwm_init.h>
#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"
#include "adc_init.h"
#include <pwm_init.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;
extern volatile struct EPWM_REGS * EPwmRegs[17];
typedef struct
{
int16_t UA;
int16_t UB;
int16_t UC;
}strPWMABC;
volatile strPWMABC PWM_motor = {PERIOD_2, PERIOD_2, PERIOD_2};
2023-12-27 16:36:19 +03:00
int16_t A_proc,B_proc,C_proc;
uint16_t PWM_Vent = PERIOD_MOTOR;
uint16_t PWM_Chop = 0;
void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc)
{
2023-12-27 16:36:19 +03:00
2023-12-27 16:36:19 +03:00
A_proc = (int16_t)((phaseA/Udc)*PERIOD_2);
B_proc = (int16_t)((phaseB/Udc)*PERIOD_2);
C_proc = (int16_t)((phaseC/Udc)*PERIOD_2);
2023-12-27 16:36:19 +03:00
if(A_proc > 0) A_proc+= EPWM_DB/2;
else if(A_proc < 0) A_proc-= EPWM_DB/2;
if(B_proc > 0) B_proc+= EPWM_DB/2;
else if(B_proc < 0) B_proc-= EPWM_DB/2;
if(C_proc > 0) C_proc+= EPWM_DB/2;
else if(C_proc < 0) C_proc-= EPWM_DB/2;
2023-12-27 16:36:19 +03:00
PWM_motor.UA = PERIOD_2 + A_proc;
PWM_motor.UB = PERIOD_2 + B_proc;
PWM_motor.UC = PERIOD_2 - C_proc;
FaultABC = 0;//(FaultPWM);
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();
}
EPwmRegs[PWM_A]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UA;
EPwmRegs[PWM_B]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UB;
EPwmRegs[PWM_C]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UC;
EPwmRegs[3]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_Vent;
EPwmRegs[3]->CMPB.bit.CMPB = PERIOD_MOTOR - PWM_Chop;
}
//
// 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
//
uint32_t Test_ADC_PWM_Synch1=0, Test_ADC_PWM_Synch2=0;
uint16_t TestStopSync = 0;
__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) /// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
PwmFlagStartADC = 0;
FMSTREnableSet();
AdcStartSet();
PWM_ABC_StopAllClose();
PWM_motor.UA = PERIOD_2;
PWM_motor.UB = PERIOD_2;
PWM_motor.UC = PERIOD_2;
vectorFault();
EPwmRegs[3]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_Vent;
EPwmRegs[3]->CMPB.bit.CMPB = PERIOD_MOTOR - PWM_Chop;
Test_ADC_PWM_Synch1++;
if(TestStopSync == 2) TestStopSync = 3;
}
else Test_ADC_PWM_Synch2++;
//
// Acknowledge this interrupt to receive more interrupts from group 3
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
// Gpio4out(1);
// 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 epwm8_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
// {
EPwm8Regs.CMPA.bit.CMPA = PERIOD_BRAKE - PWM_out;
// }
//
// Clear INT flag for this timer
//
EPwm8Regs.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)
{
EPwm11Regs.CMPA.bit.CMPA = PWM_test;
EPwm11Regs.CMPB.bit.CMPB = PWM_test;
EPwm11Regs.CMPC = PWM_test;
EPwm11Regs.CMPD = PWM_test;
2023-10-13 09:31:30 +03:00
if(TestStopSync != 3) sdfm_start_conversion_current();
2023-10-13 09:31:30 +03:00
PwmFlagStartADC = 1;
EPwm11Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
// Gpio4out(0);
}
void pwm_clr_PwmFlagStartADC(void)
{
PwmFlagStartADC = 0;
}
//
// InitEPwm1Example - Initialize EPWM1 configuration
//