Hi,
Thanks for your sharing code. I'm using the eTimer1 now.
So I adjust some module configuration.
But when I want to capture the pulse.
It's always running the line 'while(!(0x0080 & ETIMER_1.CH[1].STS.R)){}' .
What's wrong with my project? Could you give me some suggestions?
Thanks.
void FdivInit(void)
{
//FDIV PAD_4 GPIO[4] Etimer 1 timer channel 0
//SAT_RX PAD_45 GPIO[45] Etimer 1 timer channel 1
//GPIO
SIUL2.MSCR[4].B.IBE = 1; /* GPIO[4]: Enable pad for input - eTimer1 ch0 */
SIUL2.MSCR[4].B.PUE = 1;
SIUL2.IMCR[27].B.SSS = 1; /* eTimer1 ch0: connected to pad4 */
// SIUL2.MSCR[45].B.IBE = 1; /* GPIO[45]: Enable pad for input - eTimer1 ch1 */
// SIUL2.IMCR[28].B.SSS = 1; /* eTimer1 ch1: connected to pad */
//ETIME
ETIMER_1.ENBL.R = 0x0;
ETIMER_1.CH[0].CTRL1.R = 0x3801;
// Counts only rising edge of the MC_CLK (133MHz in RUN0), divide by 1, count up, count repeatedly, rollover
ETIMER_1.CH[0].COMP1.R = 0xFFFF;
ETIMER_1.CH[0].CCCTRL.R = 0x0264; // compare on COMP1 when counting up, COMP2 when counting down
// CAPT2 on falling edge, CAPT1 on rising edge, 2 entries
// free-running mode
ETIMER_1.CH[0].CTRL3.R = 1;
ETIMER_1.CH[1].CTRL1.R = 0xF001; // cascaded mode, count up, rollover, count repeatedly
ETIMER_1.CH[1].COMP1.R = 0xFFFF;
ETIMER_1.CH[1].CCCTRL.R = 0x0264; // compare on COMP1 when counting up, COMP2 when counting down
// CAPT2 on falling edge, CAPT1 on rising edge, 2 entries
// free-running mode
ETIMER_1.CH[1].CTRL3.R = 1;
ETIMER_1.ENBL.R = 0x0003; //Channel 0 and 1
// ETIMER_1.CH[0].CCCTRL.B.ARM = 1; // starts the input capture process
// ETIMER_1.CH[1].CCCTRL.B.ARM = 1;
}
void PulseFreqCal(void)
{
float freq;
uint32_t counts, edge1,edge2,edge3,edge4 ;
uint32_t capture_ch0[8],capture_ch1[8];
ETIMER_1.CH[0].CCCTRL.B.ARM = 1; // starts the input capture process
ETIMER_1.CH[1].CCCTRL.B.ARM = 1;
while(!(0x0080 & ETIMER_1.CH[1].STS.R)){} // wait for channel 1's capture2 flag
while(!(0x0080 & ETIMER_1.CH[0].STS.R)){}
capture_ch1[0] = ETIMER_1.CH[1].CAPT1.R;
capture_ch1[1] = ETIMER_1.CH[1].CAPT2.R;
capture_ch1[2] = ETIMER_1.CH[1].CAPT1.R;
capture_ch1[3] = ETIMER_1.CH[1].CAPT2.R;
capture_ch0[0] = ETIMER_1.CH[0].CAPT1.R;
capture_ch0[1] = ETIMER_1.CH[0].CAPT2.R;
capture_ch0[2] = ETIMER_1.CH[0].CAPT1.R;
capture_ch0[3] = ETIMER_1.CH[0].CAPT2.R;
capture_ch1[4] = ETIMER_1.CH[1].CAPT1.R;
capture_ch1[5] = ETIMER_1.CH[1].CAPT2.R;
capture_ch1[6] = ETIMER_1.CH[1].CAPT1.R;
capture_ch1[7] = ETIMER_1.CH[1].CAPT2.R;
capture_ch0[4] = ETIMER_1.CH[0].CAPT1.R;
capture_ch0[5] = ETIMER_1.CH[0].CAPT2.R;
capture_ch0[6] = ETIMER_1.CH[0].CAPT1.R;
capture_ch0[7] = ETIMER_1.CH[0].CAPT2.R;
edge1 = capture_ch1[0]*65536 + capture_ch0[0]; // save 1st rising edge
edge2 = capture_ch1[1]*65536 + capture_ch0[1]; // save 1st falling edge
edge3 = capture_ch1[2]*65536 + capture_ch0[2]; // save 2nd rising edge
edge4 = capture_ch1[3]*65536 + capture_ch0[3]; // save 2nd falling edge
// calculate period, pulseH, pulseL, freq and duty
if(edge3 > edge1)
{
counts = edge3 - edge1;
}
else
{
counts = (0xFFFFFFFF - edge1 + 1) + edge3;
}
// freq = (float)100000000.0/counts;
ETIMER_1.CH[1].STS.R = 0x00C0; // clear eTimer0 channel 1's capture1/2 flags
ETIMER_1.CH[0].STS.R = 0x00C0; // clear eTimer0 channel 0's capture1/2 flags
}