Tool/software: Code Composer Studio
We use EPwm7, EPwm9 and EPwm11 for a 3-phase motor.
I want to switch off the PWM with the output of the comparator modules (COMxPOUT).
The comparator outputs go to trip inputs 1, 2 and 3.
Together with other trip inputs 4, 7, 8, 9, 11 a DCAEVT1 event is generated,
the PWM is switched off and an interrupt is triggered.
In the interrupt I would like to query the COMPSTS bit
so that I know which of the 3 comparators has responded.
The query only works in the EPwm7 interrupt.
The query of the comparator status in the EPwm9 and EPwm11
interrupts does not work, although the comparator status is
the cause of the interrupt.
What is wrong?
Here is the code:
(EPwm9 and EPwm11 are initialized accordingly)
// Define an event (DCAEVT1) // TRM 737
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT1 = 1; // Map Trip input 1 comparator U to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT2 = 1; // Map Trip input 2 comparator V to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT3 = 1; // Map Trip input 3 comparator W to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT4 = 1; // Map Trip input 4 ERROR0 to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT7 = 1; // Map Trip input 7 ERROR1 to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT8 = 1; // Map Trip input 8 ERROR2 to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT9 = 1; // Map Trip input 9 ERROR3 to DCAH
EPwm7Regs.DCAHTRIPSEL.bit.TRIPINPUT11 = 1; // Map Trip input 11 ERROR5 to DCAH
EPwm7Regs.DCTRIPSEL.bit.DCAHCOMPSEL = 0xF; // DCAH = Trip combination input (all trip inputs selected by DCAHTRIPSEL register ORed together)
EPwm7Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI; // DCAEVT1 = DCAH high
EPwm7Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1; // DCAEVT1 = DCAEVT1 (not filtered)
EPwm7Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC; // Take async path
// Enable DCAEVT1 as one shot trip sources
// Note: DCxEVT1 events can be defined as one-shot.
// DCxEVT2 events can be defined as cycle-by-cycle.
EPwm7Regs.TZSEL.bit.DCAEVT1 = 1;
// Trip zone register for event switch off EPWM outputs A + B
EPwm7Regs.TZCTL.bit.DCAEVT1 = TZ_FORCE_LO; // Trip action set to force-low for output A
// Trip zone register for software switch off EPWM outputs A + B
EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // Trip action set to force-low for output A (TRM 725ff)
EPwm7Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // Trip action set to force-low for output B
// Register ISR for Trip Zone Interrupt EPWM7
PieVectTable.EPWM7_TZINT = &epwm7_tzint_isr;
// Enable CPU INT2 which is connected to EPWM1-8 INT:
IER |= M_INT2;
// Enable EPWM INTn in the PIE: Group 2 interrupt 7
PieCtrlRegs.PIEIER2.bit.INTx7 = 1;
// Enable TZ interrupt DCAEVT1
EPwm7Regs.TZEINT.bit.DCAEVT1 = 1;
//--------------------------------------------------
__interrupt void epwm7_tzint_isr(void)
{
if (Comp1Regs.COMPSTS.bit.COMPSTS == 1) /* Comparator U? */
ERR_U = 1;
// Acknowledge this interrupt to receive more interrupts from group 2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}
//--------------------------------------------------
// Initialize GPIO:
InitComp1Gpio(); // output GPIO193 --> input GPIO56
// TRM 977
Comp1Regs.COMPCTL.bit.COMPDACEN = 1; // Enable COMP1
Comp1Regs.COMPCTL.bit.COMPSOURCE = 0; // Use DAC1 as minus input to comparator
Comp1Regs.DACVAL.bit.DACVAL = ilim_val; // Set DAC1 to ILIM-Value, 0...5V = 0...1023
Comp1Regs.COMPCTL.bit.CMPINV = 0; // Do not invert comparator output: Output high if input A > input B
Comp1Regs.COMPCTL.bit.SYNCSEL = 1; // Synchronous output
Comp1Regs.COMPCTL.bit.QUALSEL = 2; // Filter 0...15 = 1...16 Takte @ 150MHz/4
// Comparator output is Comp1Regs.COMPSTS.bit.COMPSTS
// init trip inputs
EALLOW;
GpioG1TripRegs.GPTRIP1SEL.bit.GPTRIP1SEL = 56; // Select PJ0_GPIO56 as trip input 1 for U
EDIS;
