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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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;
  23. signal next_task_state : work.task.State;
  24. signal index : integer range 1 to 1025;
  25. --Signale anlegen:
  26. signal data_valid_intern : std_logic;
  27. signal angle_intern : signed(31 downto 0);
  28. signal busy_intern : std_logic;
  29. signal result_valid_intern : std_logic;
  30. signal sine_intern : signed(31 downto 0);
  31. signal count : INTEGER RANGE 1 TO 1025;
  32. type CalcState is(
  33. CALC_IDLE,
  34. CALC_ZUWEISEN,--1) dem IP-Core einen neuen angle Wert zuführen
  35. CALC_WARTEN,--2) warten bis dieser einen neuen Sinuswert berechnet hat
  36. --(dauert einige Takte - Hinweis result_valid und busy Signale des IP-Cores)
  37. CALC_SKALIEREN,--3) den berechneten Wert skalieren
  38. CALC_IN_FIFO_ABSPEICHERN); --4) im FIFO abspeichern
  39. signal current_calc_state : CalcState;
  40. signal next_calc_state : CalcState;
  41. begin
  42. --IP-Core instanzieren und entsprechende Signale verbinden:
  43. u_float_sine: entity work.float_sine
  44. generic map (
  45. ITERATIONS => 8
  46. )
  47. port map (
  48. clk => clk,
  49. reset => reset,
  50. data_valid => data_valid_intern,
  51. angle => angle_intern,
  52. busy => busy_intern,
  53. result_valid => result_valid_intern,
  54. sine => sine_intern
  55. );
  56. task_state_transitions : process ( current_task_state, task_start, index ) is
  57. begin
  58. next_task_state <= current_task_state;
  59. case current_task_state is
  60. when work.task.TASK_IDLE =>
  61. if ( task_start = '1' ) then
  62. next_task_state <= work.task.TASK_RUNNING;
  63. end if;
  64. when work.task.TASK_RUNNING =>
  65. if ( index = work.task.STREAM_LEN ) then
  66. next_task_state <= work.task.TASK_DONE;
  67. end if;
  68. when work.task.TASK_DONE =>
  69. if ( task_start = '1' ) then
  70. next_task_state <= work.task.TASK_RUNNING;
  71. end if;
  72. end case;
  73. end process task_state_transitions;
  74. calc_state_transitions : process (all) is
  75. begin
  76. next_calc_state <= current_calc_state;
  77. case current_calc_state is
  78. when CALC_IDLE =>
  79. if(current_task_state = work.task.TASK_RUNNING) then
  80. next_calc_state <= CALC_ZUWEISEN;
  81. end if;
  82. when CALC_ZUWEISEN =>
  83. next_calc_state <= CALC_WARTEN;
  84. when CALC_WARTEN =>
  85. if(result_valid_intern = '1' and busy_intern = '0') then--busy_intern = '0'
  86. next_calc_state <= CALC_SKALIEREN;
  87. end if;
  88. when CALC_SKALIEREN =>
  89. next_calc_state <= CALC_IN_FIFO_ABSPEICHERN;
  90. when CALC_IN_FIFO_ABSPEICHERN =>
  91. next_calc_state <= CALC_ZUWEISEN;
  92. if(index = 1024) then
  93. next_calc_state <= CALC_IDLE;
  94. end if;
  95. end case;
  96. end process calc_state_transitions;
  97. sync : process ( clk, reset ) is
  98. VARIABLE sine_scaled : signed ( 31 downto 0 );
  99. begin
  100. if ( reset = '1' ) then
  101. current_task_state <= work.task.TASK_IDLE;
  102. index <= 1;
  103. count <= 1;
  104. sine_scaled := (others => '0');
  105. data_valid_intern <= '0';
  106. signal_write <= '0';
  107. signal_writedata <= ( others => '0' );
  108. elsif ( rising_edge( clk ) ) then
  109. current_task_state <= next_task_state;
  110. case next_task_state is
  111. when work.task.TASK_IDLE =>
  112. when work.task.TASK_RUNNING =>
  113. when work.task.TASK_DONE =>
  114. end case;
  115. --A:
  116. current_calc_state <= next_calc_state;
  117. data_valid_intern <= '0';
  118. signal_write <= '0';
  119. case next_calc_state is
  120. when CALC_IDLE =>
  121. angle_intern <= (others => '0');
  122. count <= 1;
  123. when CALC_ZUWEISEN =>
  124. --if(index > 1) then
  125. angle_intern <= angle_intern + signed(step_size);
  126. --end if;
  127. data_valid_intern <= '1';
  128. when CALC_WARTEN =>
  129. when CALC_SKALIEREN =>
  130. --if(result_valid_intern = '1') then
  131. sine_scaled := sine_intern;
  132. sine_scaled(30 downto 23) := sine_scaled(30 downto 23) + ( signed(amplitude(30 downto 23)) - 127);
  133. --end if;
  134. when CALC_IN_FIFO_ABSPEICHERN =>
  135. if(index > 1) then
  136. signal_writedata <= std_logic_vector(sine_scaled);
  137. end if;
  138. signal_write <= '1';
  139. index <= index + 1;
  140. count <= count + 1;
  141. end case;
  142. --E
  143. end if;
  144. end process sync;
  145. task_state <= current_task_state;
  146. end architecture rtl;