Implementation, Characterization, and Optimization of an FPGA-based Time-to-Digital Converter