AnsweredAssumed Answered

mpc5643l etimer pulse measurement

Question asked by lanhua hua on Jul 22, 2016
Latest reply on Jul 25, 2016 by Petr Stancik

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:

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;

}

}

Outcomes