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

183 lines
3.8 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"
volatile uint16_t AutoChange = 0;
volatile uint16_t PWM_out = 0;
//volatile uint16_t PWM_motor = PERIOD_2;
uint16_t Fault = 0, Fault_fix = 0, Ready = 0, Ready_Fix = 0;
uint16_t counter1s=0, Step = 0;
TMode Mode = OffMode;
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)
{
PWM_motor.UA = PERIOD_2 + (int16_t)(phaseA*PERIOD_2/100.0);
PWM_motor.UB = PERIOD_2 + (int16_t)(phaseB*PERIOD_2/100.0);
PWM_motor.UC = PERIOD_2 + (int16_t)(phaseC*PERIOD_2/100.0);
}
//
// 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;
TimerBaseTimeoutInc();
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)
{
Gpio20out(1);
// if(AutoChange) pwm_AutoChange(2);
// else
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;
// GpioDataRegs.GPADAT.bit.GPIO0 = 1;
Step++;
if(Mode == StepMode) vector_set_angle(Step);
vector_klark_park(0,0,0,0);
vector_inversion();
FMSTR_enable_set();
Step++;
//
// Clear INT flag for this timer
//
EPwm2Regs.ETCLR.bit.INT = 1;
Gpio20out(0);
//
// Acknowledge this interrupt to receive more interrupts from group 3
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
// GpioDataRegs.GPADAT.bit.GPIO0 = 0;
}
//
// epwm3_isr - EPWM3 ISR
//
__interrupt void epwm3_isr(void)
{
// if(AutoChange) pwm_AutoChange(3);
// else
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)
{
// if(AutoChange) pwm_AutoChange(4);
// else
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)
{
EPwm5Regs.CMPA.bit.CMPA = PERIOD_BRAKE;
PWM_out = 0;
if(Fault)Fault_fix = 1;
}
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;
}
__interrupt void epwm6_isr(void)
{
// if(AutoChange) pwm_AutoChange(6);
// else
EPwm6Regs.CMPA.bit.CMPA = PERIOD_BRAKE - 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;
}
//
// InitEPwm1Example - Initialize EPWM1 configuration
//