123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
-
- library work;
- use work.reg32.all;
- use work.float.all;
- use work.task.all;
-
- entity sine is
- port (
- clk : in std_logic;
- reset : in std_logic;
-
- task_start : in std_logic;
- task_state : out work.task.State;
-
- step_size : in work.reg32.word;
- phase : in work.reg32.word;
- amplitude : in work.reg32.word;
-
- signal_write : out std_logic;
- signal_writedata : out std_logic_vector( 31 downto 0 )
- );
- end entity sine;
-
- 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;
-
-
- 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;
- case current_task_state is
- when work.task.TASK_IDLE =>
- if ( task_start = '1' ) then
- next_task_state <= work.task.TASK_RUNNING;
- end if;
- when work.task.TASK_RUNNING =>
- if ( index = work.task.STREAM_LEN ) then
- next_task_state <= work.task.TASK_DONE;
- end if;
- when work.task.TASK_DONE =>
- if ( task_start = '1' ) then
- next_task_state <= work.task.TASK_RUNNING;
- end if;
- 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' );
- elsif ( rising_edge( clk ) ) then
- current_task_state <= next_task_state;
- case next_task_state is
- when work.task.TASK_IDLE =>
- when work.task.TASK_RUNNING =>
- when work.task.TASK_DONE =>
- 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;
-
- task_state <= current_task_state;
-
- end architecture rtl;
|