Browse Source

funktioniert

master
binnerda82916 4 days ago
parent
commit
fe4bf812ef
1 changed files with 63 additions and 24 deletions
  1. 63
    24
      hardware/signal_processing/fft.vhd

+ 63
- 24
hardware/signal_processing/fft.vhd View File



architecture rtl of fft is architecture rtl of fft is


function mag_scale(pre_scale : std_logic_vector(31 downto 0))
return std_logic_vector
is
variable value_data_out_mag_float : std_logic_vector(31 downto 0);
variable value_data_out_mag_float_scaled : std_logic_vector(31 downto 0);
begin

value_data_out_mag_float := to_float(pre_scale);

value_data_out_mag_float_scaled(31) := value_data_out_mag_float(31);
value_data_out_mag_float_scaled(22 downto 0) := std_logic_vector(signed(value_data_out_mag_float(22 downto 0)));
if value_data_out_mag_float(30 downto 23) = "00000000" then
value_data_out_mag_float_scaled(30 downto 23) := std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 4);
else
value_data_out_mag_float_scaled(30 downto 23) := std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 5);
end if;
return value_data_out_mag_float_scaled;

end function;

signal current_task_state : work.task.State; signal current_task_state : work.task.State;
signal next_task_state : work.task.State; signal next_task_state : work.task.State;
signal index : integer range 0 to work.task.STREAM_LEN; signal index : integer range 0 to work.task.STREAM_LEN;
-- Eigene Steuersignale. -- Eigene Steuersignale.
signal value_data_in_ready : std_logic; signal value_data_in_ready : std_logic;
signal value_data_in_real : std_logic_vector(31 downto 0); signal value_data_in_real : std_logic_vector(31 downto 0);
signal value_data_in_real_scaled : std_logic_vector(31 downto 0);
--signal value_data_in_real_scaled : std_logic_vector(31 downto 0);
signal value_data_in_real_scaled_fixed : std_logic_vector(31 downto 0); signal value_data_in_real_scaled_fixed : std_logic_vector(31 downto 0);
--signal value_data_in_real_temp : std_logic_vector(31 downto 0);
signal value_data_in_imag : std_logic_vector(31 downto 0); signal value_data_in_imag : std_logic_vector(31 downto 0);
signal value_data_out_ready : std_logic; signal value_data_out_ready : std_logic;
signal value_data_out_real : std_logic_vector(31 downto 0); signal value_data_out_real : std_logic_vector(31 downto 0);
signal value_data_out_mag_float : std_logic_vector(31 downto 0); signal value_data_out_mag_float : std_logic_vector(31 downto 0);
signal value_data_out_mag_float_scaled : std_logic_vector(31 downto 0); signal value_data_out_mag_float_scaled : std_logic_vector(31 downto 0);


type memory_array is array (0 to work.task.STREAM_LEN - 1) of std_logic_vector(31 downto 0);
type memory_array is array (0 to work.task.STREAM_LEN) of std_logic_vector(31 downto 0);
signal memory : memory_array := (others => (others => '0')); signal memory : memory_array := (others => (others => '0'));
signal sorted_memory : memory_array := (others => (others => '0')); signal sorted_memory : memory_array := (others => (others => '0'));
signal bitsort_index : integer range 0 to work.task.STREAM_LEN; signal bitsort_index : integer range 0 to work.task.STREAM_LEN;


signal a_vec : std_logic_vector(9 downto 0); -- Vector for 1024 range
signal b_vec : std_logic_vector(9 downto 0); -- Reversed vector
--signal a_vec : std_logic_vector(9 downto 0); -- Vector for 1024 range
--signal b_vec : std_logic_vector(9 downto 0); -- Reversed vector


signal b : integer range 0 to 1023; -- Reversed integer output
signal read_wait : integer range 0 to 4;
--signal b : integer range 0 to 1023; -- Reversed integer output
signal read_wait : integer range 0 to (2048);


signal value_mag_in_ready: std_logic; signal value_mag_in_ready: std_logic;
signal value_mag_out_ready: std_logic; signal value_mag_out_ready: std_logic;


fft : process (clk, reset) is fft : process (clk, reset) is


variable value_data_in_real_scaled : std_logic_vector(31 downto 0);
variable value_data_in_real_temp : std_logic_vector(31 downto 0);
variable a_vec : std_logic_vector(9 downto 0); -- Reversed vector
variable b_vec : std_logic_vector(9 downto 0); -- Reversed vector
variable b : integer range 0 to 1023;
variable mag_temp : std_logic_vector(31 downto 0);




begin begin
signal_write <= '0'; signal_write <= '0';
signal_read <= '0'; signal_read <= '0';
flag_index <= '0'; flag_index <= '0';
a_vec <= (others => '0');
b_vec <= (others => '0');
b <= 0;

read_wait <= 0; read_wait <= 0;


-- Für jeden Takt fft_state Zustandsmaschine aufrufen. -- Für jeden Takt fft_state Zustandsmaschine aufrufen.


when FFT_STATE_FILL_IP_CORE => when FFT_STATE_FILL_IP_CORE =>


value_data_in_ready <= '1';
--value_data_in_real <= signal_readdata;

read_wait <= read_wait + 1;
value_data_in_real_scaled(31) := signal_readdata(31);
value_data_in_real_scaled(22 downto 0) := std_logic_vector(signed(signal_readdata(22 downto 0)));
if value_data_in_real_scaled(30 downto 23) = "00000000" then
value_data_in_real_scaled(30 downto 23) := std_logic_vector(signed(signal_readdata(30 downto 23)));
else
value_data_in_real_scaled(30 downto 23) := std_logic_vector(signed(signal_readdata(30 downto 23)) - 4);
end if;
value_data_in_real_temp := to_fixed(std_logic_vector(value_data_in_real_scaled));
value_data_in_real_scaled_fixed <= value_data_in_real_temp;
value_data_in_ready <= '1';


value_data_in_real <= signal_readdata;


value_data_in_real_scaled(31) <= value_data_in_real(31);
value_data_in_real_scaled(22 downto 0) <= std_logic_vector(signed(value_data_in_real(22 downto 0)));
if value_data_in_real_scaled(30 downto 23) = "00000000" then
value_data_in_real_scaled(30 downto 23) <= std_logic_vector(signed(value_data_in_real(30 downto 23)));
else
value_data_in_real_scaled(30 downto 23) <= std_logic_vector(signed(value_data_in_real(30 downto 23)) - 4);
end if;
value_data_in_real_scaled_fixed <= to_fixed(std_logic_vector(value_data_in_real_scaled));


if (value_data_out_ready = '1') then if (value_data_out_ready = '1') then
fft_state <= FFT_STATE_GET_IP_CORE; fft_state <= FFT_STATE_GET_IP_CORE;
value_data_out_mag_float_scaled(30 downto 23) <= std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 4); value_data_out_mag_float_scaled(30 downto 23) <= std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 4);
else else
value_data_out_mag_float_scaled(30 downto 23) <= std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 5); value_data_out_mag_float_scaled(30 downto 23) <= std_logic_vector(signed(value_data_out_mag_float(30 downto 23)) + 5);
if (read_wait > 2) then

memory(index) <= value_data_out_mag_float_scaled;
end if; end if;


memory(index) <= value_data_out_mag_float_scaled;
end if;



flag_index <= '1'; flag_index <= '1';
end if; end if;


when FFT_STATE_SORT => when FFT_STATE_SORT =>


a_vec <= std_logic_vector(to_unsigned(bitsort_index, a_vec'length));
a_vec := std_logic_vector(to_unsigned(bitsort_index, a_vec'length));


for i in 0 to 9 loop for i in 0 to 9 loop
b_vec(i) <= a_vec(9 - i);
b_vec(i) := a_vec(9 - i);
end loop; end loop;


b <= to_integer(unsigned(b_vec));
b := to_integer(unsigned(b_vec));
sorted_memory(bitsort_index) <= memory(b); sorted_memory(bitsort_index) <= memory(b);


if (bitsort_index = work.task.STREAM_LEN - 1) then if (bitsort_index = work.task.STREAM_LEN - 1) then
bitsort_index <= 0; bitsort_index <= 0;
fft_state <= FFT_STATE_WRITE; fft_state <= FFT_STATE_WRITE;
end if; end if;


when FFT_STATE_WRITE => when FFT_STATE_WRITE =>
signal_write <= '1'; signal_write <= '1';
signal_writedata <= sorted_memory(bitsort_index); signal_writedata <= sorted_memory(bitsort_index);
bitsort_index <= bitsort_index + 1; bitsort_index <= bitsort_index + 1;

Loading…
Cancel
Save