Measure Pulsewidth Input capture QG8

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Measure Pulsewidth Input capture QG8

ソリューションへジャンプ
1,025件の閲覧回数
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 解決策
748件の閲覧回数
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
749件の閲覧回数
abicash
Contributor III

Hi

I rectified the mistake.

Problem solved.

Shouldn't have stopped and restarted the channel in ISR

0 件の賞賛
返信