|
发表于 2004-6-21 14:21:07
|
显示全部楼层
谁会?
--rms.vhd和sqrt.vhd用于产生fft的rms幅值
--这是rms.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity RMS is
generic (
data_width : integer := 16
);
port (
reset : in std_logic; -- power on reset
clk : in std_logic; -- Input clock
load : in std_logic; -- New Sample Read (Active High Sampling Clock)
input_data_real : in std_logic_vector(Data_width-1 downto 0); -- Input Data Real
input_data_imag : in std_logic_vector(Data_width-1 downto 0); -- Input Data Imag
rms_result : out std_logic_vector(Data_width-1 downto 0) -- RMS result
);
end RMS;
architecture RMS_Architecture of RMS is
component sqrt_calc
generic(
data_width : integer := 16 -- Size of Data (bits)
);
port (
data_in : in unsigned(data_width+data_width-1 downto 0); -- Input Data
data_out : out unsigned(data_width-1 downto 0) -- Output Data
);
end component;
component Multiplier
generic(
multiplier_width : integer := 16;
data_width : integer := 16);
port (
load : in std_logic;
mult1_data : in std_logic_vector(data_width-1 downto 0);
mult2_data : in std_logic_vector(multiplier_width-1 downto 0);
product : out std_logic_vector(multiplier_width+data_width-2 downto (multiplier_width-1))
);
end component;
signal last_load : std_logic; -- Used to detect rising edge of load signal
signal Mult_R_R_Out : std_logic_vector((data_width-1) downto 0); -- The square of the Real values
signal Mult_I_I_Out : std_logic_vector((data_width-1) downto 0); -- The square of the Imag values
signal squares_added_signed : signed(data_width+data_width-1 downto 0); -- The square values added together
signal squares_added_unsigned : unsigned(data_width+data_width-1 downto 0); -- Needs to be unsigned for square root calculation
signal sqrt_result : unsigned(data_width-1 downto 0); -- Result of square root calculation
begin
rms_calc: process(reset, clk)
begin
if reset = '0' then
squares_added_signed <= (others => '0');
rms_result <= (others => '0');
last_load <= '0';
elsif Rising_Edge(clk) then
if (load = '1' and last_load = '0') then -- begin on load rising edge
squares_added_signed <= resize((signed(Mult_R_R_Out) + signed(Mult_I_I_Out)), (data_width+data_width));
rms_result <= std_logic_vector(sqrt_result);
end if;
last_load <= load;
end if;
end process rms_calc;
squares_added_unsigned <= unsigned(squares_added_signed);
R_R_Mult: Multiplier
generic map (
multiplier_width => data_width,
data_width => data_width
)
port map (
load => load,
mult1_data => input_data_real,
mult2_data => input_data_real,
product => Mult_R_R_Out
);
I_I_Mult: Multiplier
generic map (
multiplier_width => data_width,
data_width => data_width
)
port map (
load => load,
mult1_data => input_data_imag,
mult2_data => input_data_imag,
product => Mult_I_I_Out
);
Square_Root : sqrt_calc
generic map (
data_width => data_width
)
port map (
data_in => squares_added_unsigned,
data_out => sqrt_result
);
end RMS_Architecture;
|
|