This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28377D: Trip zone protection for over current protection

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

hello,

 i want to configure trip zone for over current protection. below is my trip zone code for PWM1 but when i run this code there is no duty cycle i followed all right steps but i can not figure it out where is problem.

__interrupt void epwm1_tzint_isr(void);

void main(void)
{

InitSysCtrl();
InitFlash();

 CpuSysRegs.PCLKCR2.bit.EPWM1=1;

InitEPwm1Gpio();

 EALLOW;

GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0; // Enable pullup on GPIO12
GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3; // asynch input
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1; // GPIO12 = TZ1
EDIS;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

 EALLOW; 

PieVectTable.TIMER1_INT = &cpu_timer1_isr;
PieVectTable.ADCA1_INT = &adca1_isr;
PieVectTable.EPWM1_TZ_INT = &epwm1_tzint_isr;

EDIS;

EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =0;

EDIS;
InitEPwm1Example();
ConfigureADC();
SetupADCEpwm();

EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;
EDIS;
IER |= M_INT2;
IER |= M_INT3; // Enable CPU INT3 which is connected to EPWM1-3 INT EPWM4-6 INT:


PieCtrlRegs.PIEIER2.bit.INTx1 = 1;

InitCpuTimers();
ConfigCpuTimer(&CpuTimer1, 200, 20);//
CpuTimer1Regs.TCR.all = 0x4000;

PieCtrlRegs.PIEIER1.bit.INTx1 = 1;

PID_GRANDO_F_init(&V_Controller);
V_Controller.param.Kp = KP_V;
V_Controller.param.Ki = KI_V;
V_Controller.param.Kd = KD_V;
V_Controller.param.Umax = UMAX_V;
V_Controller.param.Umin = UMIN_V;

PID_GRANDO_F_init(&I_Controller);
I_Controller.param.Kp = KP_I;
I_Controller.param.Ki = KI_I;
I_Controller.param.Kd = KD_I;
I_Controller.param.Umax = UMAX_I;
I_Controller.param.Umin = UMIN_I;

AdcaRegs.ADCPPB1CONFIG.bit.CONFIG = 0; // Setup the post-processing` block to be associated with SOC0

IER |= M_INT1;
IER |= M_INT13;

for(;;)
{
asm(" NOP");
}

}

interrupt void adca1_isr(void)
{
if (k>=1000)
{
k=0;
}
else
k++;

//Samlped voltage and current

i1=((float)(AdcaResultRegs.ADCRESULT1)-2238)*0.012;
v1=((float)(AdcaResultRegs.ADCRESULT3)-2238)*0.035;

ia[0]=ia[1];
ia[1]=ia[2];
ia[2]=(ia[0]+ia[1]+i1)/3;


vo[0]=vo[1];
vo[1]=vo[2];
vo[2]=(vo[0]+vo[1]+v1)/3;

V_Controller.term.Ref = Vpeak_Ref*sintheta;
V_Controller.term.Fbk =vo[2];
V_Controller.term.c1 = 0;
V_Controller.term.c2 = 0;
PID_GRANDO_F_FUNC(&V_Controller);

I_Controller.term.Ref = V_Controller.term.Out;
I_Controller.term.Fbk = ia[2];
I_Controller.term.c1 = 0;
I_Controller.term.c2 = 0;
PID_GRANDO_F_FUNC(&I_Controller);

d= (V_Controller.term.Out)*0.6;

CMP = PERIOD*((1+d)/2);
EPwm1Regs.CMPA.bit.CMPA = CMP;

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

interrupt void epwm1_tzint_isr(void)
{
// Leave these flags set so we only take this
// interrupt once
//
EALLOW;
EPwm1Regs.TZCLR.bit.OST = 1;
EPwm1Regs.TZCLR.bit.INT = 1;
EDIS;

// Acknowledge this interrupt to receive more interrupts from group 2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;

}

void InitEPwm1Example()
{

EALLOW;

EPwm1Regs.TZSEL.bit.OSHT1 = 1;
EPwm1Regs.TZSEL.bit.OSHT2 = 1;
// What do we want the TZ1 to do?
EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
// Enable TZ interrupt
EPwm1Regs.TZEINT.bit.OST = 0;
EDIS;


//
// Setup TBCLK
//
EPwm1Regs.TBPRD = PERIOD ; // Set timer period
EPwm1Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter

//
// Setup counter mode
//
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync output is equal to zero

//
// Setup shadowing
//
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

//
// Setup compare
//
EPwm1Regs.CMPA.bit.CMPA = 0; //
// EPwm1Regs.CMPB.bit.CMPB = 0;
//
// Set actions


EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; // EPW1A
EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; // EPW1A

EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; // EPW1B
// EPW1B


//
// Interrupt where we will change the Compare Values
//
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event INTSEL= interrupt selection
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

//Start Conversion of ADC
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 2;
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

}

  • Hi,

    There is already one example included as part of C2000Ware which showcases how to configure trip zone submodule. Please refer to that 

    C2000Ware_2_00_00_02\driverlib\f2837xd\examples\cpu1\epwm\epwm_ex1_trip_zone.c

     

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

     

  • hello,

     I have configured ePWM1 for trip zone as described in example. ePWM1 has TZ1 as one shot trip source.Upon a fault condition or over current , outputs EPWMxA and EPWMxB can be forced to Low.but in starting when i run code ePWM1 is already Low without i connect GPIO12 to ground. i mean whenever i connect GPIO12 to ground for realization of fault or over current duty should be low otherwise duty should remain same. 

    __interrupt void epwm1_tzint_isr(void);

    void InitEPwmGpio_TZ(void);

    void main(void)
    {

    CpuSysRegs.PCLKCR2.bit.EPWM1=1;

    InitEPwmGpio_TZ();
    InitTzGpio();

     DINT;

    IER = 0x0000;
    IFR = 0x0000;

     InitPieVectTable();

    EALLOW; // This is needed to write to EALLOW protected registers
    PieVectTable.EPWM1_TZ_INT = &epwm1_tzint_isr;
    EDIS;

    EALLOW;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =0;
    EDIS;

    InitEPwm1Example();

    EALLOW;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;
    EDIS;

    IER |= M_INT2;

    PieCtrlRegs.PIEIER2.bit.INTx1 = 1;

    __interrupt void epwm1_tzint_isr(void)
    {
    EPwm1TZIntCount++;

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
    }

    void InitEPwm1Example()
    {
    // Enable TZ1 as one shot trip sources
    EALLOW;
    EPwm1Regs.TZSEL.bit.OSHT1 = 1;

    // What do we want the TZ1 to do?
    EPwm1Regs.TZCTL.bit.TZA = 2;

    EPwm1Regs.TZCTL.bit.TZB = 2;

    // Enable TZ interrupt
    EPwm1Regs.TZEINT.bit.OST = 1;
    EDIS;

    EPwm1Regs.TBPRD = 12000; // Set timer period
    EPwm1Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0
    EPwm1Regs.TBCTR = 0x0000; // Clear counter

    // Setup TBCLK
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; // Clock ratio to SYSCLKOUT
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV4;

    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;

    // Setup compare
    EPwm1Regs.CMPA.bit.CMPA = 6000;

    // Set actions
    EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on CAU
    EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM1A on CAD
    }

    void InitTzGpio(void)
    {

    GpioCtrlRegs.GPCPUD.bit.GPIO12 = 0; // Enable pull-up on GPIO12 (TZ1)

    GpioCtrlRegs.GPCQSEL1.bit.GPIO12 = 3; // Asynch input GPIO12 (TZ1)

    }

  • Hi,

    I believe that if you do not connect any signal to GPIO 12 pin then the input is floating and hence could be possibly treated as low by the device and as its a one-shot mode so if the signal is tripped once , it remains to be tripped even if the external trigger goes away. So I would advice you to try configuring GPIO12 in PULL UP mode which will make sure that even if you do not connect any input signal, the device will see HIGH instead of float.

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • i have used the following code for GPIO pull up mode as you suggested me but still there is same problem 

    EALLOW;
    GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;   // Enable pullup on GPIO12 
    GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // asynch input
    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;   // GPIO48 = output
    GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;   // GPIO12 = TZ1
    EDIS;

  • Hi,

    There is a similar thread related to the same issue : https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/837338/3096508

    Kindly refer to this, and let us know if that resolves your issue,

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu