⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r2p_post.vhd

📁 本人根据opencores.org上的cordic算法改写的可配置位宽的cordic算法
💻 VHD
字号:
----	post.vhd----	Cordic post-processing block---- Compensate cordic algorithm K-factor; divide Radius by 1.6467, or multiply by 0.60725. -- Approximation:  Ra = Ri/2 + Ri/8 - Ri/64 - Ri/512--                 Radius = Ra - Ra/4096 = Ri * 0.60727. This is a 0.0034% error.-- Implementation: Ra = (Ri/2 + Ri/8) - (Ri/64 + Ri/512)--                 Radius = Ra - Ra/4096--	Position calculated angle in correct quadrant.--library ieee;use     IEEE.STD_LOGIC_1164.ALL;use     IEEE.STD_LOGIC_ARITH.ALL;use     IEEE.MATH_REAL.ALL;entity r2p_post is	generic(	    RADIUS_CORRECTION    : boolean := true;		WIDTH 	             : natural := 16;		Z_WIDTH              : integer := 20;		XY_WIDTH             : integer := 18                    	);	port(		clk	 : in std_logic;		ena	 : in std_logic;		Ai	 : in signed(Z_WIDTH-1 downto 0);     		Ri	 : in unsigned(XY_WIDTH -1 downto 0);		Q	 : in std_logic_vector(2 downto 0);		Ro	 : out unsigned(XY_WIDTH -1 downto 0);  --is corrected by multiplication with 0.60650 if GENERIC AMBLITUDE_CORRECTION is set to true		Ao 	 : out signed(Z_WIDTH-1 downto 0)	);end entity r2p_post;architecture dataflow of r2p_post isbegin	radius: block		signal RadA, RadB, RadC : unsigned(XY_WIDTH -1 downto 0);	begin		process(clk)		begin			if (clk'event and clk = '1') then				if (ena = '1') then				    if RADIUS_CORRECTION=true then						RadA <= ('0' & Ri(XY_WIDTH -1 downto 1)) + ("000" & Ri(XY_WIDTH -1 downto 3));						RadB <= ("000000" & Ri(XY_WIDTH -1 downto 6)) + ("000000000" & Ri(XY_WIDTH -1 downto 9));						RadC <= RadA - RadB;						Ro   <= RadC - RadC(XY_WIDTH -1 downto 12);					else						Ro<=Ri; --uncorrected radius output				    end if;				end if;			end if;		end process;	end block radius;	 	angle: block		constant const_PI2: signed(Z_WIDTH-1 downto 0) := conv_signed(integer(math_pi/2.0 * 2.0**Z_WIDTH/(2.0*math_pi)), Z_WIDTH); -- changed by Yue 16/07/2007		constant const_PI: signed(Z_WIDTH-1 downto 0) := conv_signed(integer(math_pi * 2.0**Z_WIDTH/(2.0*math_pi)), Z_WIDTH); -- changed by Yue 16/07/2007		constant const_2PI : signed(Z_WIDTH-1 downto 0) := (others => '0');            -- 2PI -- changed by Yue 16/07/2007		signal dQ : std_logic_vector(2 downto 1);		signal ddQ : std_logic;		signal AngStep1 : signed(Z_WIDTH-1 downto 0);   -- changed by Yue 16/07/2007		signal AngStep2 : signed(Z_WIDTH-1 downto 0);	begin		angle_step1: process(clk, Ai, Q)			variable overflow : std_logic;			variable AngA, AngB, Ang : signed(Z_WIDTH-1 downto 0);  -- changed by Yue 16/07/2007		begin			-- check if angle is negative, if so set it to zero			overflow := Ai(Z_WIDTH-1); --and Ai(18);   -- changed by Yue 16/07/2007			if (overflow = '1') then				AngA := (others => '0');			else				AngA := Ai;			end if;			-- step 1: Xabs and Yabs are swapped			-- Calculated angle is the angle between vector and Y-axis.			-- ActualAngle = PI/2 - CalculatedAngle		 	AngB := const_PI2 - AngA;			if (Q(0) = '1') then				Ang := AngB;			else				Ang := AngA;			end if;			if (clk'event and clk = '1') then				if (ena = '1') then					AngStep1 <= Ang;					dQ <= q(2 downto 1);				end if;			end if;		end process angle_step1;		angle_step2: process(clk, AngStep1, dQ)			variable AngA, AngB, Ang : signed(Z_WIDTH-1 downto 0);    -- changed by Yue 16/07/2007		begin			AngA := AngStep1;			-- step 2: Xvalue is negative			-- Actual angle is in the second or third quadrant			-- ActualAngle = PI - CalculatedAngle			AngB := const_PI - AngA;			if (dQ(1) = '1') then				Ang := AngB;			else				Ang := AngA;			end if;			if (clk'event and clk = '1') then				if (ena = '1') then					AngStep2 <= Ang;					ddQ <= dQ(2);				end if;			end if;		end process angle_step2;		angle_step3: process(clk, AngStep2, ddQ)			variable AngA, AngB, Ang : signed(Z_WIDTH-1 downto 0);   -- changed by Yue 16/07/2007		begin			AngA := AngStep2;			-- step 3: Yvalue is negative			-- Actual angle is in the third or fourth quadrant			-- ActualAngle = 2PI - CalculatedAngle			AngB := const_2PI - AngA;			if (ddQ = '1') then				Ang := AngB;			else				Ang := AngA;			end if;						if (clk'event and clk = '1') then				if (ena = '1') then					Ao <= Ang;				else				end if;			end if;		end process angle_step3;	end block angle;end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -