Time counter and phase discriminator