This circuit simulates the function of a ramp-compare analogic to digital converter.
In this type of circuit, the value of the ramp will be comparate with the input signal; if his value is > signal, the bits will be saved in a memory and the count will restart.
If you want, you can change the value of the input signal with the generator under the op-amp.
P.S. The relay can't be used in a real circuit!