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
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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.
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