proc SCHEMATIC_digital_phase_detector {} {
make name_net -name freq_err -origin {840 210}
make name_net -name del_ph -origin {710 220}
make name_net -name del_ph2 -origin {660 380}
make dco_phase_counter -name xi0 -origin {540 220}
make accumulator -name xi1 -origin {960 230}
make sub2 -orient R90Y -name xi3 -origin {810 380}
make input -name ref_in -origin {-160 290}
make input -name div_val -origin {-160 540}
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 time_to_digital_converter -name xi6 -delay_resolution delay_resolution -num_levels num_levels -origin {160 230}
make name_net -name ph_r -origin {360 220}
make name_net -name ph_f -origin {330 250}
make first_order_difference -name xi2 -origin {530 380}
make add2 -orient RY -name xi4 -origin {730 380}
  make_wire 420 220 440 220
  make_wire 400 410 440 410
  make_wire 730 220 730 350
  make_wire 400 300 860 300
  make_wire 810 350 810 210
  make_wire 860 250 880 250
  make_wire 420 120 420 220
  make_wire 400 290 260 290
  make_wire 400 250 440 250
  make_wire 440 380 330 380
  make_wire 40 120 40 220
  make_wire 60 220 40 220
  make_wire -160 120 40 120
  make_wire 40 120 420 120
  make_wire 400 250 400 290
  make_wire 860 300 860 250
  make_wire 1060 210 1040 210
  make_wire 1060 210 1090 210
  make_wire 1060 300 860 300
  make_wire 1060 300 1090 300
  make_wire 660 380 620 380
  make_wire 660 380 700 380
  make_wire 360 220 260 220
  make_wire 330 250 260 250
  make_wire 330 250 330 380
  make_wire 400 290 400 300
  make_wire 400 300 400 410
  make_wire 60 290 -160 290
  make_wire 810 210 840 210
  make_wire 840 210 880 210
  make_wire -160 540 810 540
  make_wire 760 380 780 380
  make_wire 640 220 710 220
  make_wire 710 220 730 220
  make_wire 810 540 810 410
}

proc ICON_digital_phase_detector args {


  icon_setup $args {{origin {0 0}} {orient R0} {name x}  {delay_resolution 1.0} {num_levels 1.0} {ref_freq 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 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
  icon_property -origin {-90 250} -type user -name ref_freq -default 1.0



}

