mpc5643l etimer pulse measurement

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mpc5643l etimer pulse measurement

626 Views
lanhuahua
Contributor I

Hi:

     Im working in the MPC5643L_144pin ( LSM mode) . I'm using  the Capture feature of the eTimer0 module to measure the external signal frequency. Input signal is connected to channel 4, channel 3 is Cascaded counter mode.

Test Result:

156266_156266.pngpastedImage_3.png

The test result   is not correct .What's wrong with my project?

thanks

 

void etimer0_init(void)

{

         ETIMER_0.ENBL.R = 0x0;//禁止通道

         ETIMER_0.CHANNEL[3].CTRL1.R = 0x3804;

          ETIMER_0.CHANNEL[3].COMP1.R = 0xFFFF;

ETIMER_0.CHANNEL[3].CCCTRL.R = 0x0265;                                                   

ETIMER_0.CHANNEL[3].CTRL3.R= 1;                                                         

         SIU.PCR[99].B.IBE = 1;                   //etimer0_4

       SIU.PSMI[7].B.PADSEL = 3;

       ETIMER_0.CHANNEL[4].CTRL1.R = 0xF804;     // cascaded mode, count up, rollover, count repeatedl

         ETIMER_0.CHANNEL[4].COMP1.R = 0xFFFF;

    ETIMER_0.CHANNEL[4].CCCTRL.R = 0x0265;    // compare on COMP1 when counting up, COMP2 when counting down

                                                     // CAPT2 on falling edge, CAPT1 on rising edge, 2 entries

                                                     // free-running mode

       ETIMER_0.CHANNEL[4].CTRL3.R   = 1;

        

         ETIMER_0.ENBL.R =ENBL3 | ENBL4;     

}

main()

{

     ...........................

while{

         while(!(0x0080 & ETIMER_0.CHANNEL[4].STS.R)){};  // wait for channel 1's capture2 flag

         while(!(0x0080 & ETIMER_0.CHANNEL[3].STS.R)){};

 

         capture_ch1[0] = ETIMER_0.CHANNEL[4].CAPT1.R;

         capture_ch1[1] = ETIMER_0.CHANNEL[4].CAPT2.R;

         capture_ch1[2] = ETIMER_0.CHANNEL[4].CAPT1.R;

         capture_ch1[3] = ETIMER_0.CHANNEL[4].CAPT2.R;

         capture_ch0[0] = ETIMER_0.CHANNEL[3].CAPT1.R;

         capture_ch0[1] = ETIMER_0.CHANNEL[3].CAPT2.R;

         capture_ch0[2] = ETIMER_0.CHANNEL[3].CAPT1.R;

         capture_ch0[3] = ETIMER_0.CHANNEL[3].CAPT2.R;

         capture_ch1[4] = ETIMER_0.CHANNEL[4].CAPT1.R;

         capture_ch1[5] = ETIMER_0.CHANNEL[4].CAPT2.R;

         capture_ch1[6] = ETIMER_0.CHANNEL[4].CAPT1.R;

         capture_ch1[7] = ETIMER_0.CHANNEL[4].CAPT2.R;

         capture_ch0[4] = ETIMER_0.CHANNEL[3].CAPT1.R;

         capture_ch0[5] = ETIMER_0.CHANNEL[3].CAPT2.R;

         capture_ch0[6] = ETIMER_0.CHANNEL[3].CAPT1.R;

         capture_ch0[7] = ETIMER_0.CHANNEL[3].CAPT2.R;

         SIU.GPDO[7].R ^= 0x1;

         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)8000000.0/counts;

         period = counts / (float)8000.0;

 

         if(edge2>edge1)

         {

counts = edge2 - edge1;

         }

         else

         {

counts = (0xFFFFFFFF - edge1 +1) + edge2;

         }

         pulseH = counts / (float)8000.0;

         pulseL = period-pulseH;   

         ETIMER_0.CHANNEL[3].STS.R = 0x00C0;                  // clear eTimer0 channel 3's capture1/2 flags

         ETIMER_0.CHANNEL[4].STS.R = 0x00C0;                 

         ETIMER_0.CHANNEL[3].CCCTRL.B.ARM = 1;             // starts the input capture process

       ETIMER_0.CHANNEL[4].CCCTRL.B.ARM = 1;

}

}

Labels (1)
0 Kudos
1 Reply

418 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

This can easily happen, if the square signal is available on the pin and you debug/stop the code. In free-running capture mode the capture is still functional, and you configure the eTimer’s counter to be stopped in debug mode, thus if FIFO is empty, it can be filled with new values (same counter values as this is stopped).

So you can either:

- configure eTimer channels to run in debug mode too (CTRL3[DBGEN]) or better

- disable capture operation once you are going to read FIFO and calculate results, finaly enable capture again…use

while{

                while(!(0x0080 & ETIMER_0.CHANNEL[4].STS.R)){};  // wait for channel 1's capture2 flag

                while(!(0x0080 & ETIMER_0.CHANNEL[3].STS.R)){};

    ETIMER_0.CHANNEL[3].CCCTRL.B.ARM = 0;             // stop the input capture process

                ETIMER_0.CHANNEL[4].CCCTRL.B.ARM = 0;

                // read FIFO and calculate result, code can be stopped here

     ETIMER_0.CHANNEL[3].STS.R = 0x00C0;                  // clear eTimer0 channel 3's capture1/2 flags

                ETIMER_0.CHANNEL[4].STS.R = 0x00C0;                

                ETIMER_0.CHANNEL[3].CCCTRL.B.ARM = 1;             // starts the input capture process

                ETIMER_0.CHANNEL[4].CCCTRL.B.ARM = 1;

}

BR, Petr

0 Kudos