Lösung des Praktikums Systementwurf
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.

fixed_sine.vhd 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.math_real.all;
  5. library work;
  6. use work.cordic_pkg.all;
  7. entity fixed_sine is
  8. generic (
  9. SIZE : positive; -- Width of parameters
  10. ITERATIONS : positive; -- Number of CORDIC iterations
  11. FRAC_BITS : positive; -- Total fractional bits
  12. MAGNITUDE : real := 1.0;
  13. RESET_ACTIVE_LEVEL : std_ulogic := '1'
  14. );
  15. port (
  16. clock : in std_ulogic;
  17. reset : in std_ulogic;
  18. data_valid : in std_ulogic; --# load new input data
  19. busy : out std_ulogic; --# generating new result
  20. result_valid : out std_ulogic; --# flag when result is valid
  21. angle : in signed(size-1 downto 0); -- angle in brads (2**size brads = 2*pi radians)
  22. sine : out signed(size-1 downto 0)
  23. );
  24. end entity fixed_sine;
  25. architecture rtl of fixed_sine is
  26. signal xa, ya, za, x_result, y_result : signed(Angle'range);
  27. signal rv_loc : std_ulogic;
  28. begin
  29. adj: process(clock, reset) is
  30. constant Y : signed(Angle'range) := (others => '0');
  31. constant X : signed(Angle'range) := --to_signed(1, Angle'length);
  32. to_signed(integer(MAGNITUDE/cordic_gain(ITERATIONS) * 2.0 ** FRAC_BITS), Angle'length);
  33. begin
  34. if reset = RESET_ACTIVE_LEVEL then
  35. xa <= (others => '0');
  36. ya <= (others => '0');
  37. za <= (others => '0');
  38. elsif rising_edge(clock) then
  39. adjust_angle(X, Y, Angle, xa, ya, za);
  40. end if;
  41. end process;
  42. c: entity work.cordic
  43. generic map (
  44. SIZE => SIZE,
  45. ITERATIONS => ITERATIONS,
  46. RESET_ACTIVE_LEVEL => RESET_ACTIVE_LEVEL
  47. )
  48. port map (
  49. clock => clock,
  50. reset => reset,
  51. data_valid => data_valid,
  52. result_valid => rv_loc,
  53. busy => busy,
  54. Mode => cordic_rotate,
  55. X => xa,
  56. Y => ya,
  57. Z => za,
  58. X_result => x_result,
  59. Y_result => y_result,
  60. Z_result => open
  61. );
  62. reg: process(clock, reset) is
  63. begin
  64. if reset = RESET_ACTIVE_LEVEL then
  65. sine <= (others => '0');
  66. result_valid <= '0';
  67. elsif rising_edge(clock) then
  68. result_valid <= rv_loc;
  69. if rv_loc = '1' then -- Capture result
  70. sine <= y_result;
  71. end if;
  72. end if;
  73. end process;
  74. end architecture;