There is no possibility to check the application logic without entire project. Moreover, it is out of our scope to solve application issues caused by SW logic. For this purpose paid support should be contacted.
The best solution to get duty cycle (for example left aligned) is to:
- If frequency is constant then enable interrupt on both edges and calculate period between rising and falling edge. The calculation can be then done anytime in dependence on current interrupt (whether it is from rising or falling edge.)
- If the frequency is variable then, if it is possible, it is good to connect to two inputs and set one for rising edge and the other one for falling edge. The calculation and processing is then easier.
- If the frequency is variable then, if it is possible, it is good to connect to two inputs and set one for rising edge and the other one for falling edge. The calculation and processing is then easier.
- If we have the only one input then we should set interrupt for both edges. The issue can be for small duty cycle when processing time is longer then time between two edges.
Plus, in all items above, there is additional issue with timer overflow processing. It adds some necessary conditions and calculations
The first issue I see is interrupt clearing.
Correct is TFLG1 = 0x80; // Clears interrupt flag from C7F only even more flags are set to 1.
See also https://community.nxp.com/message/1321059?commentID=1321059#comment-1321059
I can be wrong but I am not sure of period calculation.
I have attached a frequency measurement example together with calculations. You can compare with your and/or test in the first approach.
It is different MCU but the same peripheral (a little bit different names)
If you enable both edges and implement rising/falling edge logic you can easily adjust the code.
best regards,
Ladislav