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

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