Measure Pulsewidth Input capture QG8

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Measure Pulsewidth Input capture QG8

跳至解决方案
603 次查看
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

标签 (1)
0 项奖励
回复
1 解答
326 次查看
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

在原帖中查看解决方案

0 项奖励
回复
1 回复
327 次查看
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

0 项奖励
回复