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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 0 to work.task.STREAM_LEN;
  25. signal angle_calc : signed(31 downto 0);
  26. signal angle_busy : std_logic;
  27. signal angle_valid : std_logic;
  28. signal angle_result : signed(31 downto 0);
  29. signal START : std_logic;
  30. signal angle_amplitude : reg32.word;
  31. type angle_matrix is ARRAY(natural range<>) of signed;
  32. signal angle_lut : angle_matrix (31 downto 0) (31 downto 0);
  33. angle_lut(0) <= "0";
  34. angle_lut(1) <= "138547331";
  35. angle_lut(2) <= "277094662";
  36. angle_lut(3) <= "415641993";
  37. angle_lut(4) <= "554189324";
  38. angle_lut(5) <= "692736655";
  39. angle_lut(6) <= "831283986";
  40. angle_lut(7) <= "969831317";
  41. angle_lut(8) <= "1108378649";
  42. angle_lut(9) <= "1246925980";
  43. angle_lut(10) <= "1385473311";
  44. angle_lut(11) <= "1524020642";
  45. angle_lut(12) <= "1662567973";
  46. angle_lut(13) <= "1801115304";
  47. angle_lut(14) <= "1939662635";
  48. angle_lut(15) <= "2078209966";
  49. angle_lut(16) <= "2216757298";
  50. angle_lut(17) <= "2355304629";
  51. angle_lut(18) <= "2493851960";
  52. angle_lut(19) <= "2632399291";
  53. angle_lut(20) <= "2770946622";
  54. angle_lut(21) <= "2909493953";
  55. angle_lut(22) <= "3048041284";
  56. angle_lut(23) <= "3186588615";
  57. angle_lut(24) <= "3325135947";
  58. angle_lut(25) <= "3463683278";
  59. angle_lut(26) <= "3602230609";
  60. angle_lut(27) <= "3740777940";
  61. angle_lut(28) <= "3879325271";
  62. angle_lut(29) <= "4017872602";
  63. angle_lut(30) <= "4156419933";
  64. angle_lut(31) <= "4294967265";
  65. type AngleState is (
  66. ANGLE_IDLE,
  67. ANGLE_SET_SIGNALS,
  68. ANGLE_RUNNING,
  69. ANGLE_DONE
  70. );
  71. signal current_angle_state : AngleState;
  72. signal next_angle_state : AngleState;
  73. begin
  74. f1:ENTITY work.float_sine PORT MAP(CLK => CLK, RESET => RESET, data_valid => START, angle =>angle_calc, busy => angle_busy, result_valid => angle_valid, sine => angle_result);
  75. task_state_transitions : process ( current_task_state, task_start, index ) is
  76. begin
  77. next_task_state <= current_task_state;
  78. case current_task_state is
  79. when work.task.TASK_IDLE =>
  80. if ( task_start = '1' ) then
  81. next_task_state <= work.task.TASK_RUNNING;
  82. end if;
  83. when work.task.TASK_RUNNING =>
  84. if ( index = work.task.STREAM_LEN - 1 ) then
  85. next_task_state <= work.task.TASK_DONE;
  86. end if;
  87. when work.task.TASK_DONE =>
  88. if ( task_start = '1' ) then
  89. next_task_state <= work.task.TASK_RUNNING;
  90. end if;
  91. end case;
  92. end process task_state_transitions;
  93. sync : process ( clk, reset ) is
  94. begin
  95. if ( reset = '1' ) then
  96. current_task_state <= work.task.TASK_IDLE;
  97. index <= 0;
  98. elsif ( rising_edge( clk ) ) then
  99. current_task_state <= next_task_state;
  100. case next_task_state is
  101. when work.task.TASK_IDLE =>
  102. index <= 0;
  103. when work.task.TASK_RUNNING =>
  104. if(current_angle_state = ANGLE_DONE) then
  105. index <= index + 1;
  106. end if;
  107. when work.task.TASK_DONE =>
  108. index <= 0;
  109. end case;
  110. end if;
  111. end process sync;
  112. end process sync;
  113. task_state <= current_task_state;
  114. angle_state_transitions : process ( current_angle_state, angle_valid, current_angle_state)
  115. begin
  116. next_angle_state <= current_angle_state;
  117. case current_angle_state is
  118. when ANGLE_IDLE =>
  119. if(current_angle_state = work.task.TASK_RUNNING) then
  120. next_angle_state <= ANGLE_SET_SIGNALS;
  121. end if;
  122. when ANGLE_SET_SIGNALS =>
  123. next_angle_state <= ANGLE_RUNNING;
  124. when ANGLE_RUNNING =>
  125. if(angle_valid = '1') then
  126. next_angle_state <= ANGLE_DONE;
  127. end if;
  128. when ANGLE_DONE =>
  129. next_angle_state <= angle_IDLE;
  130. end case;
  131. end process angle_state_transitions;
  132. angle_calc : process (clk, reset) is
  133. begin
  134. if ( reset = '1' ) then
  135. current_angle_state <= ANGLE_IDLE;
  136. elsif ( rising_edge( clk ) ) then
  137. current_ANGLE_state <= next_angle_state;
  138. case next_angle_state is
  139. when ANGLE_IDLE =>
  140. START <= '0';
  141. signal_write <= '0';
  142. when ANGLE_SET_SIGNALS =>
  143. angle = i
  144. when ANGLE_RUNNING =>
  145. START <= '1';
  146. when ANGLE_DONE =>
  147. START <= '0';
  148. signal_write <= '1';
  149. end case;
  150. end if;
  151. end process add;
  152. end architecture rtl;