Loesung des Praktikums Systementwurf - Bjarne Hoesch - Bernhard Schoeffel
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 2.9KB

1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. type CalcState is (
  26. CALC_IDLE,
  27. CALC_READ,
  28. CALC_PROCESS,
  29. CALC_WRITE
  30. );
  31. signal Calc_State : CalcState;
  32. signal data_valid_ipcore : std_logic;
  33. signal busy_ipcore : std_logic;
  34. signal result_valid_ipcore : std_logic;
  35. signal phase_ipcore : signed(31 downto 0);
  36. signal sine_ipcore : signed(31 downto 0);
  37. begin
  38. u_float_sine: entity work.float_sine
  39. generic map(
  40. ITERATIONS => 8
  41. )
  42. port map(
  43. clk => clk,
  44. reset => reset,
  45. data_valid => data_valid_ipcore,
  46. busy => busy_ipcore,
  47. result_valid => result_valid_ipcore,
  48. -- " TODO Check if this is allowed (direkt access to maped signal)"
  49. angle => phase_ipcore,
  50. sine => sine_ipcore
  51. );
  52. task_state_transitions : process ( current_task_state, task_start, index ) is
  53. begin
  54. next_task_state <= current_task_state;
  55. case current_task_state is
  56. when work.task.TASK_IDLE =>
  57. if ( task_start = '1' ) then
  58. next_task_state <= work.task.TASK_RUNNING;
  59. end if;
  60. when work.task.TASK_RUNNING =>
  61. if ( index = work.task.STREAM_LEN - 1 ) then
  62. next_task_state <= work.task.TASK_DONE;
  63. end if;
  64. when work.task.TASK_DONE =>
  65. if ( task_start = '1' ) then
  66. next_task_state <= work.task.TASK_RUNNING;
  67. end if;
  68. end case;
  69. end process task_state_transitions;
  70. sync : process ( clk, reset ) is
  71. begin
  72. if ( reset = '1' ) then
  73. current_task_state <= work.task.TASK_IDLE;
  74. index <= 0;
  75. elsif ( rising_edge( clk ) ) then
  76. current_task_state <= next_task_state;
  77. case next_task_state is
  78. when work.task.TASK_IDLE =>
  79. index <= 0;
  80. signal_write <= '0';
  81. when work.task.TASK_RUNNING =>
  82. index <= index + 1;
  83. signal_write <= '1';
  84. signal_writedata <= ( others => '0' );
  85. when work.task.TASK_DONE =>
  86. index <= 0;
  87. signal_write <= '0';
  88. end case;
  89. end if;
  90. end process sync;
  91. task_state <= current_task_state;
  92. phase_ipcore <= (SIGNED(phase));
  93. end architecture rtl;