proc SCHEMATIC_digital_phase_detector {} {
make name_net -name freq_err -origin {810 210}
make name_net -name del_ph -origin {680 220}
make name_net -name del_ph2 -origin {640 380}
make dco_phase_counter -name xi0 -origin {540 220}
make accumulator -name xi1 -origin {930 230}
make first_order_difference -name xi2 -origin {530 380}
make sub2 -orient R90Y -name xi3 -origin {780 380}
make add2 -orient RY -name xi5 -origin {690 380}
make input -name ref_in -origin {-160 180}
make input -name div_val -origin {-160 480}
make output -name ref_retimed -origin {1060 300}
make output -name ph_error -origin {1060 210}
make input -name vco_in -origin {-160 120}
make gain -name xi4 -gain ref_freq -origin {-40 290}
make time_to_digital_converter -name xi6 -delay_resolution delay_resolution -num_levels num_levels -origin {180 230}
  make_wire 0 180 -160 180
  make_wire 10 290 80 290
  make_wire 60 220 80 220
  make_wire 420 220 440 220
  make_wire 360 410 440 410
  make_wire 280 250 360 250
  make_wire 390 380 440 380
  make_wire 690 220 690 350
  make_wire 420 300 830 300
  make_wire 420 250 360 250
  make_wire 420 250 440 250
  make_wire 780 350 780 210
  make_wire 280 220 390 220
  make_wire 830 250 850 250
  make_wire 830 300 1060 300
  make_wire -110 290 -80 290
  make_wire 420 250 420 300
  make_wire 780 210 810 210
  make_wire 810 210 850 210
  make_wire 720 380 750 380
  make_wire 680 220 640 220
  make_wire 680 220 690 220
  make_wire 620 380 640 380
  make_wire 640 380 660 380
  make_wire 1010 210 1060 210
  make_wire 830 250 830 300
  make_wire 0 250 80 250
  make_wire -110 290 -110 480
  make_wire 0 180 0 250
  make_wire 60 120 60 220
  make_wire 780 410 780 480
  make_wire 420 120 420 220
  make_wire -160 480 -110 480
  make_wire -110 480 780 480
  make_wire 390 220 390 380
  make_wire 360 250 360 410
  make_wire -160 120 60 120
  make_wire 60 120 420 120
}

proc ICON_digital_phase_detector args {
  icon_setup $args {{origin {0 0}} {orient R0} {name x} {ref_freq 1.0} {delay_resolution 1.0} {num_levels 1.0}}
icon_term -type input -origin {-100 40} -name ref_in
icon_term -type input -origin {-100 -10} -name div_val
icon_term -type input -origin {-100 80} -name vco_in
icon_term -type output -origin {100 40} -name ref_retimed
icon_term -type output -origin {100 -10} -name ph_error
icon_property -origin {-90 40} -label ref_in
icon_property -origin {-90 -10} -label div_val
icon_property -origin {-90 80} -label vco_in
icon_property -origin {90 40} -anchor e -label ref_retimed
icon_property -origin {90 -10} -anchor e -label ph_error
icon_property -origin {-90 -60} -label {$name}
icon_property -origin {-90 -40} -label digital_phase_detector
  icon_line -100 -50 100 -50 100 100 -100 100 -100 -50
icon_property -origin {-90 150} -label {ref_freq=$ref_freq}
  icon_property -origin {-90 190} -type user -name name -default x
  icon_property -origin {-90 250} -type user -name ref_freq -default 1.0
icon_property -origin {-90 110} -label {delay_resolution=$delay_resolution}
icon_property -origin {-90 130} -label {num_levels=$num_levels}
  icon_property -origin {-90 210} -type user -name delay_resolution -default 1.0
  icon_property -origin {-90 230} -type user -name num_levels -default 1.0
}

