Part Number: TMS320F28035
Hi...
I am using TSM320f28035 for one of my application.
I am using the capture module of the device to check the zerocross of Grid signal(230 VAC RMS) which in further is used in calculating the frequency of the grid.
Please note that I am using both rising and falling edge trigger for capturing the signal in every alternate sample.
Below is the code which I used to initialize the capture module.
I am using GPIO5 as my capture pin.
Void init_capture(void)
{
ecapFlag = 0;
EALLOW;
/* Enable internal pull-up for the selected pins */
GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Enable pull-up on GPIO5 (CAP1)
// Inputs are synchronized to SYSCLKOUT by default.
GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 0; // Synch to SYSCLKOUT GPIO5 (CAP1)
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 3; // Configure GPIO5 as CAP1
EDIS;
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.ECCTL1.bit.PRESCALE = 0; //BYPASS THE prescaler
ECap1Regs.ECCTL2.bit.CAP_APWM = 0; //capture mode
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // Oneshot mode
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Capture event on Falling edge ECap1Regs.ECCTL1.bit.CAP2POL = 0; // Capture event on Falling edge
ECap1Regs.ECCTL1.bit.CAP3POL = 0; // Capture event on Falling edge
ECap1Regs.ECCTL1.bit.CAP4POL = 0; // Capture event on Falling edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Don't reset the counter
ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // Don't reset the counter
ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Don't reset the counter
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Don't reset the counter
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Disable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Pass through
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units
ECap1Regs.ECCTL2.bit.STOP_WRAP = 0; // Capture sequence stops after Capture event 2
ECap1Regs.ECCTL2.bit.REARM = 1; // reset and unfreeze counter
ECap1Regs.ECEINT.bit.CEVT1 = 1; // Capture event 1 is source of interrupt
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
}
The interrupt ISR is as follows.
interrupt void ECap1_ISR(void)
{
GpioDataRegs.GPATOGGLE.bit.GPIO23 = 1;
if (ecapFlag == 1)
{
ecapFlag = 0;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL1.bit.CTRRST1 = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Capture event on Falling edge
ECap1Regs.TSCTR = 0;
// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
return;
}
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL1.bit.CTRRST1 = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Capture event on Falling edge
ecapFlag = 1;
ECap1Regs.TSCTR = 0;
// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
Please note that I have already enabled the peripheral clocks for capture module along with the interrupt vector for capture which I have not mentioned in the sample code.
And also I am using 2 interrupts in my code "ADC interrupt triggered by PWM signal & Capture module event interrupt"
The routines mentioned above when executed sometimes showed abrupt results which in turn led to trip my system.
In order to ensure that my capture event was triggered properly I toggled a GPIO pin(GPIO23 as shown in interrupt routine) in the interrupt.
The waveform captured is as shown below.
FIGURE 1
FIGURE 2
Please ignore the "GREEN" & "YELLOW" waveforms from the figures.
Figure 2 is the enlarged version of Figure 1.
"PINK" is the zero-cross waveform which gets ON & OFF in every 10 ms. "BLUE" is the GPIO23 pin which I toggled.
From the waveform it is quite clear that there is a proper zero-cross waveform which I am capturing while there is some false capture event i.e the time period of the "BLUE" waveform has changed.
Even there seems to be no noise issues on zero-cross pin as there were no spikes captured on events in the waveform.
This has led to trip my system.
Your sincere response will be truly appreciated.
Thanks in advance.
Regards,
Kamal

