Compare commits

..

2 Commits

Author SHA1 Message Date
zieglerhe
c90753aa23 New FFT.vhd Template and Fix FFT TB (expected values) 2025-05-30 11:33:35 +02:00
zieglerhe
5efb80253b Fixed FFT Makefile Vorlage 2025-05-29 07:54:55 +02:00
8 changed files with 274 additions and 432 deletions

View File

@ -1,13 +1,26 @@
------------------------------------------------------------------------
-- fft
--
-- calculation of FFT magnitude
-- calculation of FFT magnitudes
--
-- Inputs:
-- 32-Bit Floating Point number in range +-16 expected (loaded from FIFO)
--
-- Outputs
-- 32-Bit Floating Point number in range +-16 calculated (stored in FIFO)
--
--
-- Zahlen aus dem Eingangs-FIFO liegen in 32-Bit Floating Point mit Wertebereich +-16 vor
-- Diese Zahlen müssen in Floating Point auf den Wertebereich +-1 gebracht werden (In Floating Point können Sie durch :16 teilen, wenn Sie den Exponenten der Floating Point Zahl um -4 verkleinern, falls dieser ungleich Null ist)
-- Die auf den Wertebereich +-1 gebrachten Floating Point Zahlen mit to_fixed auf eine Fixpointzahl wandeln
-- Diese Fixpointzahl kann dem FFT IP-Core (fftmain) als Eingangswert übergeben werden (Realteil = skalierte auf Fixpoint gewandelte Zahlen; Imaginärteil=0)
-- Die vom FFT IP-Core berechneten werden (Realteil und Imaginärteil) können direkt dem IP-Core für die FFT Magnitude Berechnung (fft_magnitude_calc) übergeben werden (dieser arbeitet auch in Fixpoint im gleichen Wertebereich)
-- Das Ergebnis des FFT Magnitude Berechnung IP-Cores (fft_magnitude_calc) dann auf Floating Point wandeln (to_float)
-- Diese Floating Point Zahlen dann wieder skalieren mit *16 bzw. *32 für den DC-Anteil um auf den ursprünglichen Wertebereich mit +-16 zu kommen (aus dem FFT IP-Core kommt der DC-Anteil / Index 0 um den Faktor 2 zu klein, deswegen dort *32).
-- (In Floating Point können Sie *16 machen, wenn Sie den Exponenten der Floating Point Zahl um +4 vergrößern, *32 wenn dieser um +5 vergrößert wird, falls der Exponent ungleich Null ist)
-- Die Ergebnisse liegen noch in der bit-reveserd order vor (FFT IP-Core arbeitet nicht in-place) und müssen deswegen noch auf die natural order gebracht werden (https://de.mathworks.com/help/dsp/ug/linear-and-bit-reversed-output-order.html)
-- (z.B: ein Array verwenden, um die Werte zu sortieren)
-- Dann das Ergebnis in den Ausgangsfifo speichern
--
-----------------------------------------------------------------------
library ieee;
@ -22,10 +35,10 @@ library work;
entity fft is
generic (
-- input data width of real/img part
-- input data width of real/img part
input_data_width : integer := 32;
-- output data width of real/img part
-- output data width of real/img part
output_data_width : integer := 32
);
@ -35,10 +48,10 @@ entity fft is
task_start : in std_logic;
task_state : out work.task.State;
signal_read : out std_logic;
signal_readdata : in std_logic_vector( 31 downto 0 );
signal_write : out std_logic;
signal_writedata : out std_logic_vector( 31 downto 0 )
);
@ -46,12 +59,103 @@ end entity fft;
architecture rtl of fft is
-- Signale für Task State Machine
signal current_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 2000;
-- component des Verilog IP-Cores fuer die FFT
component fftmain is
port(
clock: in std_logic; -- Master Clock
reset: in std_logic; -- Active High Asynchronous Reset
di_en: in std_logic; -- Input Data Enable
di_re: in std_logic_vector(input_data_width-1 downto 0); -- Input Data (Real)
di_im: in std_logic_vector(input_data_width-1 downto 0); -- Input Data (Imag)
do_en: out std_logic; -- Output Data Enable
do_re: out std_logic_vector(output_data_width-1 downto 0); -- Output Data (Real)
do_im: out std_logic_vector(output_data_width-1 downto 0) -- Output Data (Imag)
);
end component;
-- Signale Input skaliert
signal fft_float_input : signed( 31 downto 0 );
signal fft_float_scaled_input : signed( 31 downto 0 );
-- Signale fuer FFT-IP Core
-- fft data input signal
signal fft_input_data_enable: std_logic;
signal data_in_re : std_logic_vector (input_data_width-1 downto 0);
signal data_in_im : std_logic_vector (input_data_width-1 downto 0);
-- fft output data
signal fft_output_valid : std_logic;
signal data_out_re : std_logic_vector (output_data_width-1 downto 0);
signal data_out_im : std_logic_vector (output_data_width-1 downto 0);
-- Signale fuer Magnitude IP-Core
signal fft_mag_calc_valid : std_logic;
signal fft_mag_calc_result: std_logic_vector (output_data_width-1 downto 0);
-- Signale fuer Ergebnis skaliert
signal data_out_mag_signed_float : signed (output_data_width-1 downto 0);
signal fft_float_scaled : signed( 31 downto 0 );
-- Signale/Array um Ergebnisse der FFT in der natural order zu speichern
signal data_memory : work.reg32.RegArray( 0 to 1023 );
signal index_reversed : std_logic_vector(9 downto 0);
signal index_output_sv : std_logic_vector(9 downto 0);
signal index_output : integer range 0 to 1023;
-- Signal um in den Write FIFO zu schreiben
signal wr_fifo : std_logic;
begin
task_state_transitions : process ( current_task_state, task_start, index ) is
-----------------------------------------------------------------------------------------------
-- Hier muss der Verilog FFT IP-Core instanziert werden
-----------------------------------------------------------------------------------------------
--u_fft : fftmain
-- port map (
-- clock => , -- system clock
-- reset => , -- Active High Asynchronous Reset
-- di_en => , -- Input Data Enable
-- di_re => , -- Input Data (Real)
-- di_im => , -- Input Data (Imag)
-- do_en => , -- Output Data Enable
-- do_re => , -- Output Data (Real)
-- do_im => -- Output Data (Imag)
-- );
fft_output_valid <= '0';
data_out_re <= (others => '0');
data_out_im <= (others => '0');
-----------------------------------------------------------------------------------------------
-- Hier muss der VHDL Magnitue IP-COre instanziert werden
-----------------------------------------------------------------------------------------------
-- u_fft_mag_calc : entity work.fft_magnitude_calc
-- port map (
-- clk => , -- system clock
-- reset => , -- Active High Asynchronous Reset
-- input_valid => , -- Input Data Valid
-- input_re => , -- Input Realteil in Fixpoint format
-- input_im => , -- Input Imaginaerteil in Fixpoint format
-- output_valid => , -- Output Data Valid
-- output_magnitude => -- Magnitude Output in Fixpoint format
-- );
fft_mag_calc_valid <= '1' when index = 0 else '0';
fft_mag_calc_result <= (others => '0');
-----------------------------------------------------------------------------------------------
-- Zustandsmaschine fuer die Taskabarbeitung (Uebergangsschaltnetz)
-----------------------------------------------------------------------------------------------
task_state_transitions : process (all) is
begin
next_task_state <= current_task_state;
case current_task_state is
@ -60,7 +164,7 @@ begin
next_task_state <= work.task.TASK_RUNNING;
end if;
when work.task.TASK_RUNNING =>
if ( index = work.task.STREAM_LEN - 1 ) then
if ( index = 2 ) then
next_task_state <= work.task.TASK_DONE;
end if;
when work.task.TASK_DONE =>
@ -70,28 +174,157 @@ begin
end case;
end process task_state_transitions;
sync : process ( clk, reset ) is
-----------------------------------------------------------------------------------------------
-- Zustandsmaschine fuer die eigentliche Ablaufsteuerung fuer die FFT (Uebergangsschaltnetz)
-----------------------------------------------------------------------------------------------
-- Hier soll Ihre Ablaufsteuerung fuer die FFT stehen
-----------------------------------------------------------------------------------------------
-- Ausgangsschaltnetz/Zustandsspeicher fuer die Task und FFT Zustandsmaschine
-----------------------------------------------------------------------------------------------
sync : process ( clk, reset ) is
begin
if ( reset = '1' ) then
current_task_state <= work.task.TASK_IDLE;
index <= 0;
wr_fifo <= '0';
elsif ( rising_edge( clk ) ) then
current_task_state <= next_task_state;
wr_fifo <= '0';
case next_task_state is
when work.task.TASK_IDLE =>
index <= 0;
signal_write <= '0';
when work.task.TASK_RUNNING =>
index <= index + 1;
signal_write <= '1';
signal_writedata <= ( others => '0' );
when work.task.TASK_DONE =>
index <= 0;
signal_write <= '0';
when work.task.TASK_IDLE =>
index <= 0;
when work.task.TASK_RUNNING =>
-- Nur damit das Template durchlaueft bei index=0 wird das natural order array mit Nullen gefuellt
-- Bei index=1 werden die 1024 Werte in den Ausgangsfifo geschrieben (Task done bei index=2)
if ( index_output = work.task.STREAM_LEN - 1 ) then
index <= index + 1;
end if;
if index = 1 then
wr_fifo <= '1';
end if;
when work.task.TASK_DONE => null;
end case;
end if;
end process sync;
end process sync;
task_state <= current_task_state;
-----------------------------------------------------------------------------------------------
--
-- Skalierung der Eingangswerte welche vom FIFO gelesen werden
-- Dies soll außerhalb eines Prozesses geschehen damit die gelesenen Werte direkt skaliert werden
-- und im naechsten Takt schon weiter verarbeitet werden können
--
-- Erforderliches Scaling:
--
-- By selecting the amplitude as a power of two (e.g. 2 ** 2) the
-- multiplication is a simple addition of the exponents.
-- In the following calculation the inputs are scaled from FP in range +-16 to FP in range +-1
-- This means an divsion through 16 -> exponent needs an addition of - 4
--
-- fft_float_input = gelesener Wert vom FIFO (floating point)
-- fft_float_scaled_input = soll skalierter Wert vom FIFO seien (floating point)
-- (Anm. Der FFT IP-Core braucht als Format Fix-Point -> noch eine weitere Wandlung erforderlich)
-----------------------------------------------------------------------------------------------
fft_float_input <= signed(signal_readdata);
fft_float_scaled_input <= fft_float_input; -- Der Eingang muss noch entsprechend skaliert werden
-----------------------------------------------------------------------------------------------
--
-- Skalierung der Eingangswerte welche vom FIFO gelesen werden
-- Dies soll außerhalb eines Prozesses geschehen damit die gelesenen Werte direkt skaliert werden
-- und im naechsten Takt schon weiter verarbeitet werden können
--
-- Erforderliches Scaling:
--
-- By selecting the amplitude as a power of two (e.g. 2 ** 2) the
-- multiplication is a simple addition of the exponents.
-- In the following calculation the inputs are scaled from FP in range +-1 to FP in range +-16
-- the first frequency bin (DC-bin) needs a multiplication by two compared to the other frequency bins (the used fft ip-core divides the result of the first frequency bin by N instead of the correct N/2)
-- This means an divsion through 16 is required for the first frequency bin (DC Part) -> exponent needs an addition of +4
-- This means an divsion through 32 is required for the first frequency bin (DC Part) -> exponent needs an addition of +5
--
-- data_out_mag_signed_float = in float gewandelter Wert der Magnitude Berechnung
-- fft_float_scaled = soll der skalierte float Wert der Magnitude seien
-----------------------------------------------------------------------------------------------
data_out_mag_signed_float <= signed(to_float(fft_mag_calc_result));
fft_float_scaled <= data_out_mag_signed_float; -- Der Ausgang muss noch entsprechend skaliert werden
-----------------------------------------------------------------------------------------------
-- Der FFT-IP Core liefert das Ergebnis nicht in der natuerlichen Reihenfolge deswegen muss eine
-- Umordnung der Ausgangswerte erfolgen
--
-- index_output_sv = std_logic_vector des Integer Ausgangsindex
-- index_reversed = der reversed Ausgangsindex (wird benoetigt fuer damit man die FFT Ergebnisse in die natuerliche Ordnung bringt
--
c_index_output_sv:
index_output_sv <= std_logic_vector(to_unsigned(index_output, index_reversed'length));
c_reversed_index:
index_reversed <= index_output_sv(0) & index_output_sv(1) & index_output_sv(2) & index_output_sv(3) & index_output_sv(4) & index_output_sv(5) & index_output_sv(6) & index_output_sv(7) & index_output_sv(8) & index_output_sv(9);
-----------------------------------------------------------------------------------------------
-- Prozess steuert das hochzaehlen des Ausgang Index
-----------------------------------------------------------------------------------------------
p_number_output_sample: process ( clk, reset ) is
begin
if ( reset = '1' ) then
index_output <= 0;
elsif ( rising_edge( clk ) ) then
-- Ruecksetz Bedingung für index_output
if index_output = 1023 then -- in diese IF-Bedingung ggf. noch den IDLE Zustand Ihrer FFT FSM einbringen
index_output <= 0;
-- index_output hochzaehlen um in natural order im array zu speichern
elsif fft_mag_calc_valid = '1' then
index_output <= index_output + 1;
-- index_output hochzaehlen um Werte im Ausgangsfifo zu speichern
elsif wr_fifo = '1' then
index_output <= index_output + 1;
end if;
end if;
end process p_number_output_sample;
-----------------------------------------------------------------------------------------------
-- Prozess speichert das skalierte Endergbenis iun der natural order
-----------------------------------------------------------------------------------------------
p_output2float_memory: process ( clk, reset) is
begin
if ( reset = '1' ) then
null;
elsif ( rising_edge( clk ) ) then
if fft_mag_calc_valid = '1' then
data_memory(to_integer(unsigned(index_reversed))) <= std_logic_vector(fft_float_scaled);
end if;
end if;
end process p_output2float_memory;
-----------------------------------------------------------------------------------------------
-- Schreiben der berechneten Werte in den FIFO
-----------------------------------------------------------------------------------------------
p_output_fifo: process ( clk, reset ) is
begin
if ( reset = '1' ) then
signal_writedata <= (others => '0');
signal_write <= '0';
elsif ( rising_edge( clk ) ) then
signal_write <= '0';
if wr_fifo = '1' then
signal_writedata <= data_memory(index_output);
signal_write <= '1';
end if;
end if;
end process p_output_fifo;
-- Hier sollen die sonstigen benoetigten Anweisungen stehen
task_state <= current_task_state;
end architecture rtl;

View File

@ -26,37 +26,7 @@ architecture rtl of rand is
signal next_task_state : work.task.State;
signal index : integer range 0 to work.task.STREAM_LEN;
--Signale anlegen:
signal data_valid_intern : std_logic; --um skalieren zu gehen
--signal angle_intern : signed(31 downto 0);
--signal busy_intern : std_logic;
--signal result_valid_intern : std_logic;
--signal sine_intern : signed(31 downto 0);
--State Machine anlegen:
type CalcState is(
CALC_IDLE,
CALC_RANDOMISIEREN,--2) neuen Randomwert berechnen
--(dauert einige Takte)
CALC_SKALIEREN,--3) den berechneten Wert skalieren
CALC_IN_FIFO_ABSPEICHERN); --4) im FIFO abspeichern
signal current_calc_state : CalcState;
signal next_calc_state : CalcState;
begin
--IP-Core instanzieren und entsprechende Signale verbinden:
task_state_transitions : process ( current_task_state, task_start, index ) is
begin
next_task_state <= current_task_state;
@ -76,69 +46,11 @@ begin
end case;
end process task_state_transitions;
--ZUSTANDSMASCHINE:
calc_state_transitions : process (all) is
begin
next_calc_state <= current_calc_state;
case current_calc_state is
when CALC_IDLE =>
if(current_task_state = work.task.TASK_RUNNING) then
next_calc_state <= CALC_RANDOMISIEREN;
end if;
when CALC_RANDOMISIEREN =>
--if(result_valid_intern = '1' and busy_intern = '0') then--busy_intern = '0'
if(data_valid_intern = '1') then
next_calc_state <= CALC_SKALIEREN;
end if;
when CALC_SKALIEREN =>
next_calc_state <= CALC_IN_FIFO_ABSPEICHERN;
when CALC_IN_FIFO_ABSPEICHERN =>
next_calc_state <= CALC_RANDOMISIEREN;
if(index = 1024) then
next_calc_state <= CALC_IDLE;
end if;
end case;
end process calc_state_transitions;
sync : process ( clk, reset ) is
--VARIABLEN:
VARIABLE randomisiert : signed ( 31 downto 0 );
VARIABLE scaled : signed ( 31 downto 0 );
random_number_word : std_logic_vector(31 downto 0);
variable mask_bit_0 : std_logic_vector(31 downto 0);
variable mask_bit_1 : std_logic_vector(31 downto 0);
variable mask_bit_21 : std_logic_vector(31 downto 0);
variable mask_bit_31 : std_logic_vector(31 downto 0);
variable xor_result : std_logic_vector(0 downto 0);
variable shifted : std_logic_vector(31 downto 0);
variable exponent : std_logic_vector(7 downto 0);
variable shifted_modified : std_logic_vector(31 downto 0);
variable shifted_exponent : std_logic_vector(31 downto 0);
variable shifted_modifiziert : std_logic_vector(31 downto 0);
begin
if ( reset = '1' ) then
current_task_state <= work.task.TASK_IDLE;
index <= 0;
--START VALUES:
randomisiert := (others => '0');
data_valid_intern <= '0';
signal_write <= '0';
signal_writedata <= ( others => '0' );
elsif ( rising_edge( clk ) ) then
current_task_state <= next_task_state;
case next_task_state is
@ -153,102 +65,9 @@ begin
index <= 0;
signal_write <= '0';
end case;
--ZUSTANDSMACHINE LOGIK:
--A:
current_calc_state <= next_calc_state;
data_valid_intern <= '0';
signal_write <= '0';
case next_calc_state is
when CALC_IDLE =>
--angle_intern <= (others => '0');
index <= 0;
when CALC_RANDOMISIEREN =>
randomisiert := 5;
if (index == 0) then
random_number_word := seed;
end if;
-- Bits extrahieren und XOR durchführen
bit_0 := random_number_word(0) and mask_bit_0(0);
bit_1 := random_number_word(1) and mask_bit_1(1);
bit_21 := random_number_word(21) and mask_bit_21(21);
bit_31 := random_number_word(31) and mask_bit_31(31);
xor_result := bit_0 xor bit_1 xor bit_21 xor bit_31;
-- Shift um 1 nach rechts
shifted := random_number_word(30 downto 0) & '0';
shifted(31) := xor_result(0); -- XOR-Ergebnis an das MSB (Bit 31) setzen
-- Ergebnis ausgeben
shifted_result <= shifted;
data_valid_intern <= '1';
when CALC_SKALIEREN =>
--if(result_valid_intern = '1') then
scaled := randomisiert;
--scaled := 6;
--randomisiert(30 downto 23) := randomisiert(30 downto 23) + ( signed(amplitude(30 downto 23)) - 127);
--end if;
-- Exponent extrahieren
exponent := shifted_result(30 downto 23);
-- Überprüfen, ob das 7. Bit des Exponenten gesetzt ist
if (exponent(7) = '1') then
exponent := exponent and "10000001";
else
exponent := exponent or "01111100";
end if;
-- Verschiebung vorbereiten
shifted_modified := shifted_result;
shifted_exponent := ('0' & exponent) & (others => '0');
-- Verschiedene Teile kombinieren
shifted_modifiziert := shifted_modified and x"807FFFFF";
shifted_modifiziert := shifted_modifiziert or shifted_exponent;
-- Ergebnis ausgeben
scaled_modified_result <= shifted_modifiziert;
when CALC_IN_FIFO_ABSPEICHERN =>
if(index > 1) then
signal_writedata <= std_logic_vector(scaled);
end if;
signal_write <= '1';
index <= index + 1;
end case;
--E
end if;
end process sync;
task_state <= current_task_state;
end architecture rtl;

View File

@ -28,48 +28,9 @@ architecture rtl of sine is
signal current_task_state : work.task.State;
signal next_task_state : work.task.State;
signal index : integer range 1 to 1025;
--Signale anlegen:
signal data_valid_intern : std_logic;
signal angle_intern : signed(31 downto 0);
signal busy_intern : std_logic;
signal result_valid_intern : std_logic;
signal sine_intern : signed(31 downto 0);
signal count : INTEGER RANGE 1 TO 1025;
type CalcState is(
CALC_IDLE,
CALC_ZUWEISEN,--1) dem IP-Core einen neuen angle Wert zuführen
CALC_WARTEN,--2) warten bis dieser einen neuen Sinuswert berechnet hat
--(dauert einige Takte - Hinweis result_valid und busy Signale des IP-Cores)
CALC_SKALIEREN,--3) den berechneten Wert skalieren
CALC_IN_FIFO_ABSPEICHERN); --4) im FIFO abspeichern
signal current_calc_state : CalcState;
signal next_calc_state : CalcState;
signal index : integer range 0 to work.task.STREAM_LEN;
begin
--IP-Core instanzieren und entsprechende Signale verbinden:
u_float_sine: entity work.float_sine
generic map (
ITERATIONS => 8
)
port map (
clk => clk,
reset => reset,
data_valid => data_valid_intern,
angle => angle_intern,
busy => busy_intern,
result_valid => result_valid_intern,
sine => sine_intern
);
task_state_transitions : process ( current_task_state, task_start, index ) is
begin
next_task_state <= current_task_state;
@ -79,7 +40,7 @@ begin
next_task_state <= work.task.TASK_RUNNING;
end if;
when work.task.TASK_RUNNING =>
if ( index = work.task.STREAM_LEN ) then
if ( index = work.task.STREAM_LEN - 1 ) then
next_task_state <= work.task.TASK_DONE;
end if;
when work.task.TASK_DONE =>
@ -89,88 +50,25 @@ begin
end case;
end process task_state_transitions;
calc_state_transitions : process (all) is
begin
next_calc_state <= current_calc_state;
case current_calc_state is
when CALC_IDLE =>
if(current_task_state = work.task.TASK_RUNNING) then
next_calc_state <= CALC_ZUWEISEN;
end if;
when CALC_ZUWEISEN =>
next_calc_state <= CALC_WARTEN;
when CALC_WARTEN =>
if(result_valid_intern = '1' and busy_intern = '0') then--busy_intern = '0'
next_calc_state <= CALC_SKALIEREN;
end if;
when CALC_SKALIEREN =>
next_calc_state <= CALC_IN_FIFO_ABSPEICHERN;
when CALC_IN_FIFO_ABSPEICHERN =>
next_calc_state <= CALC_ZUWEISEN;
if(index = 1024) then
next_calc_state <= CALC_IDLE;
end if;
end case;
end process calc_state_transitions;
sync : process ( clk, reset ) is
VARIABLE sine_scaled : signed ( 31 downto 0 );
begin
if ( reset = '1' ) then
current_task_state <= work.task.TASK_IDLE;
index <= 1;
count <= 1;
sine_scaled := (others => '0');
data_valid_intern <= '0';
signal_write <= '0';
signal_writedata <= ( others => '0' );
index <= 0;
elsif ( rising_edge( clk ) ) then
current_task_state <= next_task_state;
case next_task_state is
when work.task.TASK_IDLE =>
index <= 0;
signal_write <= '0';
when work.task.TASK_RUNNING =>
index <= index + 1;
signal_write <= '1';
signal_writedata <= ( others => '0' );
when work.task.TASK_DONE =>
index <= 0;
signal_write <= '0';
end case;
--A:
current_calc_state <= next_calc_state;
data_valid_intern <= '0';
signal_write <= '0';
case next_calc_state is
when CALC_IDLE =>
angle_intern <= (others => '0');
count <= 1;
when CALC_ZUWEISEN =>
--if(index > 1) then
angle_intern <= angle_intern + signed(step_size);
--end if;
data_valid_intern <= '1';
when CALC_WARTEN =>
when CALC_SKALIEREN =>
--if(result_valid_intern = '1') then
sine_scaled := sine_intern;
sine_scaled(30 downto 23) := sine_scaled(30 downto 23) + ( signed(amplitude(30 downto 23)) - 127);
--end if;
when CALC_IN_FIFO_ABSPEICHERN =>
if(index > 1) then
signal_writedata <= std_logic_vector(sine_scaled);
end if;
signal_write <= '1';
index <= index + 1;
count <= count + 1;
end case;
--E
end if;
end process sync;

View File

@ -3,78 +3,10 @@
#include "system/data_channel.h"
#include "system/float_word.h"
#include <stdio.h>
int task_rand_run( void * task ) {
int task_rand_run( void * data )
{
// TODO
rand_config * task = ( rand_config * ) data;
uint32_t data_channel_base = task->base.sink;
float seed = task->seed; //1.3
float abs_min = task->abs_min; //0.125
float abs_max = task->abs_max; //9.0
float_word random_number;
random_number.value = seed;
uint32_t mask_bit_0 = 0x1;
uint32_t mask_bit_1 = 0x2;
uint32_t mask_bit_21 = 0x200000;
uint32_t mask_bit_31 = 0x80000000;
uint32_t exponent = 0;
uint32_t shifted_exponent = 0;
uint32_t shifted = 0;
uint32_t shifted_modifiziert = 0;
data_channel_clear( data_channel_base );
for(uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i)
{
//Bits extrahieren:
uint32_t bit_0 = (random_number.word & mask_bit_0) >> 0;
uint32_t bit_1 = (random_number.word & mask_bit_1) >> 1;
uint32_t bit_21 = (random_number.word & mask_bit_21) >> 21;
uint32_t bit_31 = (random_number.word & mask_bit_31) >> 31;
//XOR:
uint32_t xor_result = bit_0 ^ bit_1 ^ bit_21 ^ bit_31;
//Shifted:
shifted = random_number.word >> 1;
//shifted &= ~(0x80000000);
shifted |= (xor_result << 31);
printf("%08x %08x %d \n", random_number.word, shifted, xor_result);
//Skalierung:
#if 1
exponent = (shifted >> 23) & 0xFF;
if(exponent & (1 << 7)){
exponent &= (0b10000001);
}else{
exponent |= (0b01111100);
}
shifted_modifiziert = shifted;
shifted_exponent = exponent << 23;
shifted_modifiziert &= 0x807FFFFF;
shifted_modifiziert |= shifted_exponent;
#endif
random_number.word = shifted_modifiziert;
data_channel_write( data_channel_base, random_number.word );
random_number.word = shifted;
}
return 0;
return 0;
}

View File

@ -2,54 +2,9 @@
#include "system/data_channel.h"
#include "system/float_word.h"
#include <math.h>
int task_sine_run( void * data ) {
sine_config * task = ( sine_config * ) data;
// TODO
uint32_t data_channel_base = task->base.sink;
uint32_t samples_per_periode = task->samples_per_periode;
float phase = task->phase;
float amplitude = task->amplitude;
data_channel_clear( data_channel_base );
#if 0
for (uint32_t i = 0; i < (DATA_CHANNEL_DEPTH/samples_per_periode); ++i)
{
for(uint32_t j = 0; j < (samples_per_periode); ++j)
{
float_word res;
res.value = amplitude * sin((2.0*M_PI/samples_per_periode) * j + phase);
data_channel_write( data_channel_base, res.word );
}
}
#endif
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i)
{
float_word res;
res.value = amplitude * sin((2.0*M_PI/samples_per_periode) * i + phase);
data_channel_write( data_channel_base, res.word );
}
return 0;
return 0;
}

View File

@ -11,6 +11,8 @@ verilog_srcs = \
vhdl_srcs = \
../../../hardware/system/reg32.vhd \
../../../hardware/system/avalon_slave.vhd \
../test_utility.vhd \
../test_avalon_slave.vhd \
../../hardware/test_data_channel.vhd \
../../../hardware/system/avalon_slave_transitions.vhd \
../../../hardware/system/task.vhd \

View File

@ -63,7 +63,7 @@ architecture test of test_task_fft is
variable writedata_float : float32;
variable writedata_real : real;
variable expected_real : real;
variable abs_err : real := 0.5e-1;
variable abs_err : real := 0.6;
variable result : data_array( 0 to work.task.STREAM_LEN - 1 );
variable result_fft : data_array( 0 to work.task.STREAM_LEN - 1 );
file data_file : text;
@ -110,11 +110,13 @@ architecture test of test_task_fft is
std.textio.write( data_file_fft, "]" & LF );
file_close( data_file_fft );
index := 0;
while index < STREAM_LEN loop
writedata_float := to_float( result( index ) );
writedata_real := to_real( writedata_float );
expected_real := work.fft_data.expected( index );
assert_near( writedata_real, expected_real, abs_err );
index := index + 1;
end loop;
file_open( data_file_fft_bit_reversed, "fft_out_bit_reversed.py", write_mode );

View File

@ -1 +1,2 @@
add wave -position end sim:/test_task_fft/dut/*
add wave -position end sim:/test_task_fft/dut/u_fft/*