proc SCHEMATIC_time_to_digital_converter {} {
make input -name ref_in -origin {190 190}
make input -name clk_in -origin {190 240}
make output -name ref_retimed -origin {1270 190}
make reg_double -name xi1 -origin {690 -180}
make dff2 -name xi2 -origin {300 220}
make mixer -name xi3 -origin {1200 -190}
make time_to_digital_primitive -name xi0 -delay_resolution delay_resolution -num_levels num_levels -origin {360 -180}
make name_net -name td_sig -origin {490 -190}
make name_net -name td_sig_lat -origin {820 -190}
make output -name out_rising -origin {1270 -190}
make output -name out_falling -origin {1270 80}
make reg_double -name xi6 -origin {690 90}
make mixer -orient RY -name xi7 -origin {1200 80}
make time_to_digital_period_avg -name xi8 -avg_length 100 -origin {790 -60}
make period_avg_inverse -name xi4 -origin {1030 -70}
make name_net -name inv_avg -origin {1150 -70}
make name_net -name avg -origin {920 -70}
  make_wire 240 190 190 190
  make_wire 240 190 260 190
  make_wire 220 240 190 240
  make_wire 220 240 260 240
  make_wire 820 -190 750 -190
  make_wire 820 -190 1160 -190
  make_wire 490 -190 460 -190
  make_wire 1240 -190 1270 -190
  make_wire 1240 80 1270 80
  make_wire 240 -160 240 190
  make_wire 220 -190 220 240
  make_wire 1160 80 750 80
  make_wire 510 80 630 80
  make_wire 610 110 630 110
  make_wire 610 -160 630 -160
  make_wire 460 -160 510 -160
  make_wire 220 -190 260 -190
  make_wire 240 -160 260 -160
  make_wire 560 -70 690 -70
  make_wire 560 -190 490 -190
  make_wire 560 -190 630 -190
  make_wire 510 -40 690 -40
  make_wire 560 -10 690 -10
  make_wire 610 -160 610 110
  make_wire 560 190 350 190
  make_wire 560 190 610 190
  make_wire 510 -40 510 -160
  make_wire 510 -40 510 80
  make_wire 560 -10 560 190
  make_wire 560 -190 560 -70
  make_wire 1200 -70 1200 -150
  make_wire 1200 -70 1200 40
  make_wire 920 -40 950 -40
  make_wire 920 190 610 190
  make_wire 920 190 1270 190
  make_wire 610 110 610 190
  make_wire 920 -70 890 -70
  make_wire 920 -70 950 -70
  make_wire 1150 -70 1200 -70
  make_wire 1150 -70 1110 -70
  make_wire 920 -40 920 190
}

proc ICON_time_to_digital_converter args {


  icon_setup $args {{origin {0 0}} {orient R0} {name x} {delay_resolution 1.0} {num_levels 1.0}}
icon_term -type input -origin {-100 60} -name ref_in
icon_term -type input -origin {-100 -10} -name clk_in
icon_term -type output -origin {100 60} -name ref_retimed
icon_term -type output -origin {100 -10} -name out_rising
icon_term -type output -origin {100 20} -name out_falling
icon_property -origin {-90 60} -label ref_in
icon_property -origin {-90 -10} -label clk_in
icon_property -origin {90 -10} -anchor e -label out_rising
icon_property -origin {90 60} -anchor e -label ref_retimed
icon_property -origin {-90 -60} -label {$name}
icon_property -origin {-90 -40} -label time_to_digital_converter
  icon_line -100 -50 100 -50 100 80 -100 80 -100 -50
icon_property -origin {-90 90} -label {delay_resolution=$delay_resolution}
  icon_property -origin {-90 150} -type user -name name -default x
  icon_property -origin {-90 170} -type user -name delay_resolution -default 1.0
icon_property -origin {-90 110} -label {num_levels=$num_levels}
  icon_property -origin {-90 190} -type user -name num_levels -default 1.0
icon_property -origin {90 20} -anchor e -label out_falling


}

