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

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

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

2,432 Views
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 Kudos
Reply
3 Replies

1,567 Views
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 Kudos
Reply

1,567 Views
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 Kudos
Reply

1,567 Views
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 Kudos
Reply