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.

TMS320F28069: Questions about register writing

Part Number: TMS320F28069


Hi, there. I'm currently using F28069 and using the interrupt of ECAP2 which serves in APWM mode. I have enabled the interrupt when CTR reaches CMP and here is my interrupt service function

__interrupt void ecap2_isr(void){
    GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1;

    ECap2Regs.ECCLR.bit.INT = 1;
    ECap2Regs.ECCLR.bit.CTR_EQ_CMP = 1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}

I expected to see a pulsed waveform whose duty is approximately 50% and frequence is half of the APWM. But actually, when I ran the program, I found the duty is very small (close to 0) and the frequency is the same as APWM. So I think probably there is some problem with my interrupt flag clearing process and it triggers the interrupt function being operated two times in each APWM cycle.

After that, I have made a modification. I change the order of two lines of the code above ,which is shown below

__interrupt void ecap2_isr(void){
    GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1;
    
    ECap2Regs.ECCLR.bit.CTR_EQ_CMP = 1;
    ECap2Regs.ECCLR.bit.INT = 1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}

And the waveform turned to be the same as I expected. But I have no idea about this phenomenon, could you please give me some information related to this weird thing? Thank you.

  • Hi,

    Can you try putting that code in 

    EALLOW;

    EDIS;

  • Hi, thank you for your reply. I think that might not be the issue since the two register, GPATOGGLE and ECCLR, are not EALLOW protected though I haven't tried that yet.

  • Hi,

    Please try this or I will try to recreate the issue on my setup tomorrow.

  • Hi Santosh. I have tried to put EALLOW and EDIS and here is my code

    __interrupt void ecap2_isr(void){
        EALLOW;
        GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1;
        ECap2Regs.ECCLR.bit.INT = 1;
        ECap2Regs.ECCLR.bit.CTR_EQ_CMP = 1;
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
        EDIS;
    }

    And here is my waveform captured.

    The top two channels are the output of APWM and the last channel is the GPIO0. As you can see, the frequency of channel2 is the same as channel 0 and channel1, which is not what I'm expecting. Besides, the pulse duration of GPIO0 is quite small, almost 500ns(the period is 500us), which is also weird.

    When I modified the code as

    __interrupt void ecap2_isr(void){
        EALLOW;
        GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1;
        ECap2Regs.ECCLR.bit.CTR_EQ_CMP = 1;
        ECap2Regs.ECCLR.bit.INT = 1;
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
        EDIS;
    }

    Then, the waveform is exactly what I expected, which is put below.

    In order that you can completely recreate this issue, I put my ECAP initialization code as below.

    void initAPWM(){
        ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts
        ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags
        ECap1Regs.ECCTL2.bit.CAP_APWM = 1;   // Enable APWM mode
        ECap2Regs.ECCTL2.bit.CAP_APWM = 1;   // Enable APWM mode
    
    
        ECap2Regs.ECEINT.bit.CTR_EQ_CMP = 1; //Enable APWM interrupt when CTR equals CMP
    //    ECap2Regs.ECEINT.bit.CEVT2 = 1;
    
        ECap1Regs.ECCLR.all = 0x0FF;         // Clear pending interrupts
    
        ECap1Regs.ECCTL2.bit.APWMPOL = 1;
        ECap2Regs.ECCTL2.bit.APWMPOL = 0;
        ECap1Regs.CAP1 = pwm1_prd;         // Set Period value
        ECap1Regs.CAP2 = pwm1_cmp;         // Set Compare value
    //
        ECap2Regs.CAP1 = pwm2_prd;         // Set Period value
        ECap2Regs.CAP2 = pwm2_cmp;         // Set Compare value
        // Start counters
        ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;
        ECap2Regs.ECCTL2.bit.TSCTRSTOP = 1;
    
        ECap1Regs.ECCTL2.bit.SYNCO_SEL = 1;
        ECap2Regs.ECCTL2.bit.SYNCI_EN = 1;
        ECap2Regs.CTRPHS  = pwm2_pha;         // Set Compare value
    }

    Thank you.

  • Hi,

    Do you have sample project which I can try?