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/TMS320F280049: Meauring Duty Cycle/Period/Frequency of an Input Signal (digital square wave) Using ECap

Part Number: TMS320F280049
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Dear All,

I am trying to measure the frequency of an input signal using F280049. In the device support of F28004x, I could not find the PWM Capture example, so I have tried to use a code from F2807x into a project created for F280049. However, I am unable to read see anything in ECap Registers.

Following is the code that I am using:

#include "F28x_Project.h"


Uint32 ECap1IntCount;

void InitECapGpio(void);
void InitECapture(void);
__interrupt void ecap1_isr(void);

void main(void)
{
InitSysCtrl();

InitECapGpio();
GPIO_SetupPinOptions(16, GPIO_INPUT, GPIO_ASYNC);

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

EALLOW;
PieVectTable.ECAP1_INT = &ecap1_isr;
EDIS;

InitECapture();

ECap1IntCount = 0;

IER |= M_INT4;

PieCtrlRegs.PIEIER4.bit.INTx1 = 1;

EINT;
ERTM;

for(;;)
{

}
}

__interrupt void ecap1_isr(void)

{

ECap1IntCount++;

ECap1Regs.ECCLR.bit.CEVT4 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}


void InitECapGpio()
{
EALLOW;
InputXbarRegs.INPUT7SELECT = 16; // Set eCAP1 source to GPIO-pin
EDIS;
}


void InitECapture()
{
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture __interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP __interrupt flags
ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped

//
// Configure peripheral registers
//
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1; // One-shot
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP2POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP4POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Enable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Pass through
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units

ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap1Regs.ECEINT.bit.CEVT4 = 1; // 4 events = __interrupt
}

  • Hi Muhammad,

    You can refer to following C200Ware example:

    C:\ti\c2000\C2000Ware_2_00_00_02\driverlib\f28004x\examples\ecap\ecap_ex2_capture_pwm.c.

    Regards,

    Nirav

  • I have tried that but was failed to import project due to the error called "compiler not installed". I think I am using a new compiler version and this project is associated with an older version. Also, my main project is built including source and headers from device support files.

  • Hi Muhammad,

    You should be able to download the older compiler version from web to be able to import the project. Other option is to refer ecap_ex2_capture_pwm.c code for eCAP configuration to capture the pulse/duty cycle of PWM.

    Regards,

    Nirav

  • Thank you so much for your reply.

    I have tried that as well. If you see the ecap_ex2_capture_pwm.c  file, there are many functions which are called but are not available in the associated ecap.c file present in the driverlib folder. ecap.c has only 1 function defining emulation mode, so, it's incomplete.  

  • The project works using ecap_ex2_capture_pwm.c from driverlib folder of c200ware, however, my original code is based on device support folder and it would really be difficult to merge this example with my original code.

    Is it possible to get simple code continuous mode capture operation of Ecap type1 compatible with F280049?

    Thank you so much for your time and help!