hwo to use timer(input capture) interrupt to calculate duty cycle

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

hwo to use timer(input capture) interrupt to calculate duty cycle

2,419 次查看
pratibhasurabhi
Contributor V

Hi,

I am using S12ZVML128 controller.

I want to calculate duty cycle on capture pin using single interrupt.

Please tell me if the code is available for the same?

0 项奖励
回复
3 回复数

1,554 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Please refer to the attached example. You can measure using a single channel.

But you need also an interrupt in case the timer overflows.

Regards,

Daniel

0 项奖励
回复

1,554 次查看
pratibhasurabhi
Contributor V

Thanks Daniel!

I referred and implemented the same in my code.

But value of duty cycle is not consistent and it is getting changed so it is affecting the motor rotation.

I am not getting the exact issue in code why duty cycle gets changed?

How the value of MAX_OVERFLOW=500 is decided?

I used same sample code,I have given lowest priority for Timer Channel 0 interrupt.

Please provide me solution for the same?

0 项奖励
回复

1,554 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

 

I’m not sure I understand your question. The duty cycle result is changing while your input signal is stable? Why did you set Timer Channel 0 interrupt with lowest priority?

 

Regarding MAX_OVERFLOW, whenever an edge is detected the overflow counter is cleared. If there is no edge that could be detected the overflow counter increases until it reaches an arbitrary high number (500) after which we can say the signal is not periodic. So, the duty cycle is then 100% or 0% based on the input state (PTIT_PTIT0).

 

Regards,

Daniel

0 项奖励
回复