Studentenversion des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sine.vhd 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library work;
  5. use work.reg32.all;
  6. use work.float.all;
  7. use work.task.all;
  8. entity sine is
  9. port (
  10. clk : in std_logic;
  11. reset : in std_logic;
  12. task_start : in std_logic;
  13. task_state : out work.task.State;
  14. step_size : in work.reg32.word;
  15. phase : in work.reg32.word;
  16. amplitude : in work.reg32.word;
  17. signal_write : out std_logic;
  18. signal_writedata : out std_logic_vector( 31 downto 0 )
  19. );
  20. end entity sine;
  21. architecture rtl of sine is
  22. signal current_task_state : work.task.State; --multiple sources
  23. signal next_task_state : work.task.State;
  24. signal index : integer range 0 to work.task.STREAM_LEN; --multiple sources
  25. --Selbst angelegte Signal:
  26. signal data_valid_flag : std_logic;
  27. signal busy_flag : std_logic;
  28. signal result_valid_flag : std_logic;
  29. signal angle_sig : signed( 31 downto 0);
  30. signal ergebnis : signed( 31 downto 0 );
  31. signal ampl_sig : signed( 31 downto 0 );
  32. --Zustände für die Zustandsmaschine für die Berechnung
  33. type CalcState is (
  34. CALC_IDLE,
  35. CALC_START,
  36. CALC_SINE,
  37. CALC_STORE_RESULT
  38. );
  39. --Signale für die Zustandsmaschine für die Berechnung
  40. signal current_calc_state : CalcState;
  41. signal next_calc_state : CalcState;
  42. begin
  43. u_float_sine : entity work.float_sine -- Das hier ist der Core!
  44. generic map (
  45. ITERATIONS => 8
  46. )
  47. port map (
  48. clk => clk,
  49. reset => reset,
  50. data_valid => data_valid_flag, --# load new input data
  51. busy => busy_flag, --# generating new result
  52. result_valid => result_valid_flag, --# flag when result is valid
  53. angle => angle_sig, -- angle in brads (2**size brads = 2*pi radians)
  54. sine => ergebnis --Hierzu nachfragen
  55. );
  56. --Bei diesem task nichts ändern!
  57. task_state_transitions : process ( all ) is
  58. begin
  59. next_task_state <= current_task_state;
  60. case current_task_state is
  61. when work.task.TASK_IDLE =>
  62. if ( task_start = '1' ) then
  63. next_task_state <= work.task.TASK_RUNNING;
  64. end if;
  65. when work.task.TASK_RUNNING =>
  66. if ( index = work.task.STREAM_LEN - 1 ) then
  67. next_task_state <= work.task.TASK_DONE;
  68. end if;
  69. when work.task.TASK_DONE =>
  70. if ( task_start = '1' ) then
  71. next_task_state <= work.task.TASK_RUNNING;
  72. end if;
  73. end case;
  74. end process task_state_transitions;
  75. --Übergangsschaltnetz der Zustandsmaschine für die Berechnung ###Fertig
  76. calc_state_transitions: process (all) is
  77. begin
  78. next_calc_state <= current_calc_state;
  79. case current_calc_state is
  80. when CALC_IDLE=>
  81. if (current_task_state= work.task.TASK_RUNNING) then
  82. next_calc_state <= CALC_START;
  83. end if;
  84. when CALC_START=>
  85. next_calc_state <= CALC_SINE;
  86. when CALC_SINE =>
  87. if (result_valid_flag = '1' and busy_flag = '0') then --or falling_edge( busy) ?
  88. next_calc_state <= CALC_STORE_RESULT;
  89. end if;
  90. when CALC_STORE_RESULT =>
  91. if ( index = work.task.STREAM_LEN ) then
  92. next_calc_state <= CALC_IDLE;
  93. else
  94. next_calc_state <= CALC_START;
  95. end if;
  96. end case;
  97. end process calc_state_transitions;
  98. --Zustandsspeicher und Ausgangsschaltnetz zu der Steuerung der Tasks
  99. task_sync : process (clk, reset) is
  100. begin
  101. if (reset = '1') then
  102. current_task_state <= work.task.TASK_IDLE;
  103. elsif (rising_edge( clk)) then
  104. current_task_state <= next_task_state;
  105. case next_task_state is
  106. when work.task. TASK_IDLE => null;
  107. when work.task. TASK_RUNNING => null;
  108. when work.task. TASK_DONE => null;
  109. end case;
  110. end if;
  111. end process task_sync;
  112. --Zustandsspeicher und Ausgangsschaltnetz zu Berechnung
  113. sync : process (clk, reset) is
  114. begin
  115. if (reset = '1') then
  116. index <= 0;
  117. data_valid_flag <= '0';
  118. current_calc_state <= CALC_IDLE;
  119. --ergebnis <= (others => '0'); --Wird von IP Core gesteuert und darf deshalb hier nicht getrieben werden
  120. signal_writedata <= (others => '0');
  121. signal_write <= '0';
  122. angle_sig <= (others => '0');
  123. elsif (rising_edge( clk)) then
  124. current_calc_state <= next_calc_state;
  125. case next_calc_state is
  126. when CALC_IDLE =>
  127. data_valid_flag <= '0';
  128. signal_write <= '0';
  129. angle_sig <= signed (phase);
  130. ampl_sig <= signed (amplitude);
  131. when CALC_START =>
  132. data_valid_flag <= '1';
  133. signal_write <= '0';
  134. angle_sig <= angle_sig + signed(step_size); --step_size = 2 * PI / 32
  135. when CALC_SINE => --hier Berechnung mit IP Core?
  136. data_valid_flag <= '0';
  137. when CALC_STORE_RESULT =>
  138. index <= index + 1;
  139. signal_write <= '1';
  140. --Berechne float multiplikation zu Fuss. Exponent + Exponent usw.
  141. signal_writedata <= std_logic_vector( ergebnis(31 downto 31) & (ergebnis(30 downto 23) + (signed(ampl_sig(30 downto 23)) - 127)) & ergebnis(22 downto 0));
  142. end case;
  143. end if;
  144. end process sync;
  145. task_state <= current_task_state;
  146. end architecture rtl;