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
}