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.

pwm_test_db.vhd 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 16.03.2022 20:07:22
  6. -- Design Name:
  7. -- Module Name: pwm_test_db - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. library ieee_proposed;
  23. use ieee_proposed.fixed_pkg.all;
  24. --use IEEE.STD_LOGIC_1164.ALL;
  25. -- Uncomment the following library declaration if using
  26. -- arithmetic functions with Signed or Unsigned values
  27. --use IEEE.NUMERIC_STD.ALL;
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx leaf cells in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32. entity pwm_test_db is
  33. -- Port ( );
  34. end pwm_test_db;
  35. architecture Behavioral of pwm_test_db is
  36. component regler is
  37. Port ( clk : in STD_LOGIC; --Clk -> Gibt Abtastzeit vor
  38. w : in integer := 0; --Sollwert
  39. y : in integer := 0; --Istwert
  40. u : inout integer := 0); --Stellgöße
  41. end component;
  42. component pt1 is
  43. Port ( clk : in STD_LOGIC;
  44. u : in integer;
  45. y : inout integer);
  46. end component;
  47. component wendeTangente is
  48. Port ( a : in sfixed (7 downto -6); -- 14 Bit breit, 6 Nachkommastellen
  49. b : in sfixed (7 downto -6);
  50. c : out sfixed (7 downto -6));
  51. end component;
  52. signal clk : std_logic := '0';
  53. signal clk_100 : std_logic := '0';
  54. signal w : integer := 1000000;
  55. signal u : integer := 0;
  56. signal y : integer := 0;
  57. signal cnt : integer := 0;
  58. signal risingEdge : std_logic := '0';
  59. --wendetangenten test
  60. signal a : sfixed(7 downto -6) := to_sfixed (-3.125, 7, -6);
  61. signal b : sfixed(7 downto -6) := to_sfixed (5.1111, 7, -6);
  62. signal c : sfixed(7 downto -6);
  63. begin
  64. uut_regler: regler PORT MAP (
  65. clk => clk,
  66. w => w,
  67. y => y,
  68. u => u
  69. );
  70. uut_pt1: pt1 PORT MAP (
  71. clk => clk,
  72. u => u,
  73. y => y
  74. );
  75. uutWendeTangente: wendeTangente PORT MAP(
  76. a => a,
  77. b => b,
  78. c => c
  79. );
  80. --generate clock
  81. clk <= not clk after 5 us;
  82. process
  83. begin
  84. w <= 1000000;
  85. -- if rising_edge(clk) and ( cnt >= 100) then
  86. -- clk_100 <= not clk_100;
  87. -- cnt <= 0;
  88. -- end if;
  89. if clk = '1' and risingEdge = '0' then
  90. cnt <= cnt+1;
  91. risingEdge <= '1';
  92. clk_100 <= '0';
  93. a <= a + to_sfixed(1.111, 7, -6);
  94. end if;
  95. if clk = '0' then
  96. risingEdge <= '0';
  97. end if;
  98. if cnt >= 99 then
  99. clk_100 <= '1';
  100. cnt <= 0;
  101. end if;
  102. wait for 1 us;
  103. -- cnt <= cnt+1;
  104. end process;
  105. end Behavioral;