How to read time from one pulse ON time to another pulse ON time

I actually changed nothing. I made that code tested it, was working, then posted here. after a while I did further testing with different PWM waveforms, was working fine, but then suddenly it stopped giving me correct values