library IEEE; use IEEE.electrical_systems.all; use ieee.math_real.all; entity PLL is generic ( Fp : real := 20.0e3; -- Loop Filter pole freq [Hz] Fz : real := 1.0e6; -- Loop filter zero freq [Hz] Kv : real := 100.0e3; -- VCO Gain [Hz/V] Fv : real := 1.0e6); -- VCO Center Freq [Hz] port (terminal input, lf_out, vco_out : electrical); end entity PLL; architecture behavioral of PLL is quantity v_in across input to electrical_ref; quantity v_lf across i_lf through lf_out to electrical_ref; quantity v_vco across i_vco through vco_out to electrical_ref; -- Internal quantities and constants -- Multiplier quantity mult : real; -- Loop filter (Lag) constant wp : real := math_2_pi*fp; -- Pole Freq in Rad/s constant wz : real := math_2_pi*fz; -- Zero Freq in Rad/s constant num : real_vector := (1.0, 1.0/wz); -- Numerator array constant den : real_vector := (1.0, 1.0/wp); -- Denominator array -- VCO quantity phi : real; -- used in VCO equation constant Kv_w : real := math_2_pi*Kv; -- Change gain to (Rad/s)/V constant wc : real := math_2_pi*Fv; -- Change freq to Rad/s begin if domain = quiescent_domain use phi == 0.0; -- initialize phi else phi'dot == wc + Kv_w*(v_lf); -- Calculate VCO Frequency end use; mult == v_in * v_vco; -- Multiplier output v_lf == mult'LTF(num,den); -- Loop Filter output v_vco == cos(phi); -- VCO output end architecture behavioral;