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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. use IEEE.numeric_std.ALL;
  23. --use IEEE.STD_LOGIC_1164.ALL;
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx leaf cells in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31. entity pwm_test_db is
  32. -- Port ( );
  33. end pwm_test_db;
  34. architecture Behavioral of pwm_test_db is
  35. component regler is
  36. Port ( clk : in STD_LOGIC; --Clk -> Gibt abtastzeit vor
  37. w : in signed(63 downto 0) := (others => '0'); --Sollwert
  38. y : in signed(63 downto 0) := (others => '0'); --Istwert
  39. u : inout signed(63 downto 0) := (others => '0'); --Stellgöße
  40. KR : in signed(9 downto 0) := to_signed(1,10); -- Verstärkung
  41. T : in signed(9 downto 0) := to_signed(1000, 10); -- Abtastzeit in us 1000us
  42. TV : signed(9 downto 0) := (others => '0'); -- Vorhaltezeit für Differenzierer interesannt
  43. TN : in signed(9 downto 0) := to_signed(1,10)); -- Nachstellzeit
  44. end component;
  45. component pt1 is
  46. Port (
  47. clk : in STD_LOGIC;
  48. u : in signed(63 downto 0) := to_signed(1,64);
  49. y : inout signed(63 downto 0) := to_signed(1,64); -- muss vielleicht initalisiert werden vorher!?
  50. a : in signed(9 downto 0) := to_signed(1,10);
  51. k : in signed(9 downto 0) := to_signed(1,10);
  52. stepWidth : signed(9 downto 0) := to_signed(10,10)); --in us -> 10us
  53. end component;
  54. signal clk : std_logic := '0';
  55. signal clk_100 : std_logic := '0';
  56. signal w : signed(63 downto 0) := to_signed(1000000, 64);
  57. signal u : signed(63 downto 0) := to_signed(0, 64);
  58. signal y : signed(63 downto 0) := to_signed(0, 64);
  59. signal cnt : integer := 0;
  60. signal risingEdge : std_logic := '0';
  61. --Streckenparameter
  62. signal a : signed(9 downto 0) := to_signed(1, 10);
  63. signal k : signed(9 downto 0) := to_signed(1, 10);
  64. signal stepWidth : signed(9 downto 0) := to_signed(10, 10);
  65. --Reglerparameter
  66. signal KR : signed(9 downto 0) := to_signed(1, 10); -- Verstärkung
  67. signal T : signed(9 downto 0) := to_signed(1000, 10); -- Abtastzeit in ns = 1ms = 1000000ns
  68. signal TV : signed(9 downto 0) := to_signed(0, 10); -- Vorhaltezeit für Differenzierer interesannt
  69. signal TN : signed(9 downto 0) := to_signed(100000, 10); -- Nachstellzeit in us
  70. begin
  71. uut_regler: regler PORT MAP (
  72. clk => clk_100,
  73. w => w,
  74. y => y,
  75. u => u,
  76. KR => KR,
  77. T => T,
  78. TV => TV,
  79. TN => TN
  80. );
  81. uut_pt1: pt1 PORT MAP (
  82. clk => clk,
  83. u => u,
  84. y => y,
  85. a => a,
  86. k => k,
  87. stepWidth => stepWidth
  88. );
  89. --generate clock
  90. clk <= not clk after 5 us;
  91. process
  92. begin
  93. --w <= 100000000;
  94. w <= to_signed(1000000, 64); --muss >= 1000000 sein!
  95. -- if rising_edge(clk) and ( cnt >= 100) then
  96. -- clk_100 <= not clk_100;
  97. -- cnt <= 0;
  98. -- end if;
  99. if clk = '1' and risingEdge = '0' then
  100. cnt <= cnt+1;
  101. risingEdge <= '1';
  102. clk_100 <= '0';
  103. end if;
  104. if clk = '0' then
  105. risingEdge <= '0';
  106. end if;
  107. if cnt >= 99 then
  108. clk_100 <= '1';
  109. cnt <= 0;
  110. end if;
  111. wait for 1 us;
  112. -- cnt <= cnt+1;
  113. end process;
  114. end Behavioral;