Reading and generating square waves at the same time.

From first post:

...the output being stable is more important. If it takes 500ms to update that is fine.

If 500 ms to update the output is OK, then at 5 KHz input you have 2,500 interval measurements to work with. Just adding those 2,500 readings then calculating the output will reduce jitter by a factor of 2,500.