Measure Pulsewidth Input capture QG8

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

Measure Pulsewidth Input capture QG8

Jump to solution
774 Views
abicash
Contributor III

Hello

 

I am trying this seemingly effortless task, but am not able to get there.

 

I am measuring a pulse time of an input pulse on TPM Channel-1. Frequency is 50Hz.

Please see attached code snippets where i initialise the timer.

 

#define BusFrequency        8MHz

#define TIMER_START         0x4F      // bus clk,divide by 128

#define TIMER_OVERFLOW          0xFFFF //maximum

 

interrupt 6 void Timer1_Capture (void)

  {

       TPMC1SC = 0; //Clear interrupt   , ack interrupt   

       inputCycleTime[p] = TPMC1V;   //get value of TPMC1V at this edge

       p++;  // increment count for next edge capture

       if(p >= 1)

       {

         inputWidth = inputCycleTime[1]-inputCycleTime[0]; //determine duration

         p=0;

         TPMC1V  =0;

       }

    TPMC1SC = 0x44; // rising edge initiate

  }

 

void Timer1_init(void)

{

  // Timer1 period 

    TPMMOD = TIMER_OVERFLOW;

 

  TPMC1SC = 0x44; //i/p capture rising edge captures

                 //0x0c =both edges, 0x08 = falling edges

}


Now i run in all sorts of troubles with above code.I should be able to read 20ms of time = 1250 counts between both rising edges

but i get a varied value unaccounted for.

Can someone throw some light?


Thnks and Regards

Labels (1)
0 Kudos
Reply
1 Solution
497 Views
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

View solution in original post

0 Kudos
Reply
1 Reply
498 Views
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

0 Kudos
Reply