Here are details. A and B are square wave TTL level 50 Hz signals from field. Based on field conditions, B wave moves in steps of 5us with respect to A wave (the direction is always left wrt A wave, ie.. B leads A). All I need is to track this phase change and display it digitally. My first though was to use XOR gate and measure pulse width. But recomputing of this width happens everytime, the phase changes. I require that when B moves by 5us, count is 1 and 10us, count is incremented from 1 (already tracked value).