Using of TPM to calculate pulse width in KL25Z

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

Using of TPM to calculate pulse width in KL25Z

2,190 Views
xiaocongfu
NXP Employee
NXP Employee

Hello,

I'm using Init_TPM of KL25Z, trying to calculate the pulse width of the input signal. I have finished the configuration of the component in processor expert. But I have problem to get the calculation result.

Can someone give me an example of using TPM to calculate pulse width or you have another methode to calculate pulse width of a input signal with frdm kl25z.

Thanks a lot.

Xiaocong

Tags (1)
3 Replies

923 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Xiaocong,

You can use the  input capture function of TPM,

For example , firstly set the rising edge interruption , when run into this interrupt , save the TPM counter and set falling edge interrupt.

and when  reach the interrupt , also save the the TPM counter , then  calculate  the time between the time use the two TPM counter data.

Hope it helps


Have a great day,

Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

923 Views
xiaocongfu
NXP Employee
NXP Employee

Thanks for your answer.

I did the same as you said, but it seems that the edge can not be changed during the excutation of code. event.PNG

and in my code, I use the function :

Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_BOTH);  or Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_FALLING);

to change the property of Edge.

All the values I got are time of the apprance of rising edge.

PS: in my Event.c, I have:

extern LDD_TDeviceData *Cap1DeviceData;

extern Cap1_TValueType CapValue_E,Cap_E[4];

extern  int countCap_E;  // 0

void Cap1_OnCapture(LDD_TUserData *UserDataPtr)

{

       Cap1_GetCaptureValue(Cap1DeviceData,&CapValue_E);

       switch (countCap_E){

       case 0:

            if(CapValue_E!=0){

            Cap_E[countCap_E]=CapValue_E;

            countCap_E++;

           Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_FALLING);

            }

       break;

       case 1:

            if(CapValue_E!=0){

            Cap_E[countCap_E]=CapValue_E;

            countCap_E++;

            Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_RISING);

            }

       break;

       case 2:

            if(CapValue_E!=0){

            Cap_E[countCap_E]=CapValue_E;

            countCap_E++;

            Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_FALLING);

            }

       break;

       case 3:

            if(CapValue_E!=0){

            Cap_E[countCap_E]=CapValue_E;

            countCap_E = 0;

            Cap1_SelectCaptureEdge(Cap1DeviceData,EDGE_RISING);

            Cap1_Reset(Cap1DeviceData);

            }

       break;

  }

I have a signal of 200Hz and 40% duty cycle, TimerUnit counter frequency is 375kHz.

And the result of Cap_E[4] is : 1870,  3745, 5620, 7495. It has a difference of 1875 between two values, 375kHz/1875 = 200Hz.

That is to say, 1870,  3745, 5620, 7495 are the time of rising edge.

0 Kudos

923 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

I have answered the issue at the discussion thread Re: Capture_LDD SelectCaptureEdge

There is a problem width the update of the channel status and control register (TPMx_CnSC).

Best Regards,

Marek Neuzil