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.

autoTuning.vhd 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 31.05.2022 08:04:28
  6. -- Design Name:
  7. -- Module Name: autoTuning - 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. -- 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. -- Sollwert/Startsignal (CTRL-Unit) -> AutoTuning -> Regler -> Strecke
  31. entity autoTuning is
  32. Port ( clk : in STD_LOGIC;
  33. prescaler : in signed(63 downto 0) := to_signed(1000000, 64); -- prescaler für Zeit 1000000
  34. duration : in signed(63 downto 0) := to_signed(5000000, 64); -- Zeit in Microsekunden/ oder Clk-Ticks?
  35. start_Tuning : inout std_logic := '0';
  36. regler_bruecken : out STD_LOGIC := '0';
  37. w : in signed(63 downto 0) := (others => '0'); --Sollwert für Regler -> während Outotuing konst!
  38. y : in signed(63 downto 0) := (others => '0'); --Istwert
  39. --u : inout signed(63 downto 0) := (others => '0'); --Stellgöße
  40. KR : out 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 : out signed(9 downto 0) := (others => '0'); -- Vorhaltezeit für Differenzierer interesannt
  43. TN : out signed(9 downto 0) := to_signed(1, 10)); -- Nachstellzeit); -- u <= w);
  44. end autoTuning;
  45. architecture Behavioral of autoTuning is
  46. --signal prescaler : signed(63 downto 0) := to_signed(1000000, 64); -- prescaler für Zeit 1000000
  47. type data_array is array (0 to 2000) of signed(63 downto 0);
  48. begin
  49. process(clk)
  50. variable counter : signed(63 downto 0) := to_signed(0, 64);
  51. variable counter_us : signed(63 downto 0) := to_signed(0, 64); --Prescaler für Clk-Ticks
  52. variable dt : signed(63 downto 0) := to_signed(0, 64); -- Zeit zwischen Messwerte Scrhittweite (us/Wert)
  53. variable data : data_array; --Array mit Messwerten
  54. variable data_pos : integer := 0; --iterator für Array
  55. variable steigung : signed(63 downto 0) := to_signed(0, 64);
  56. variable steigung_last : signed(63 downto 0) := to_signed(0, 64);
  57. variable data_pos_wendetangente : integer := 0;
  58. --Hilfsgerade Wendetangente
  59. variable b : signed(63 downto 0) := to_signed(0, 64);
  60. --Messwerte aus Sprungantwort
  61. variable Tu : signed(63 downto 0) := to_signed(0, 64); -- Verzugszeit us
  62. variable Tg : signed(63 downto 0) := to_signed(0, 64); -- Ausgleichstzeit us
  63. variable Ks : signed(63 downto 0) := to_signed(0, 64); -- Verstärkungsfaktor us
  64. begin
  65. if(rising_edge(clk)) then
  66. if(start_Tuning = '1') then
  67. --Messvorgang starten
  68. regler_bruecken <= '1';
  69. counter_us := counter_us + 1;
  70. --125 MHZ CLK !!! -> 125 Ticks = 1 us
  71. if(counter_us >= 125) then
  72. counter_us := to_signed(0, 64);
  73. counter := counter + 1;
  74. --Messwerte aufzeichnen:
  75. dt := duration / to_signed(2000, 64); --schrittweite
  76. if(counter >= dt * to_signed(data_pos,64)) then
  77. --Wert abspeichern -> nicht rdy
  78. data(data_pos) := y;
  79. end if;
  80. if(counter >= duration) then
  81. counter := to_signed(0, 64);
  82. start_Tuning <= '0'; --Messvorgang beenden
  83. end if;
  84. end if;
  85. else
  86. if (falling_edge(start_Tuning)) then
  87. -- autoTuning beenden
  88. regler_bruecken <= '0';
  89. counter := to_signed(0, 64);
  90. counter_us := to_signed(0, 64);
  91. data_pos := 0;
  92. --Parameter berechnen/setzen:
  93. dt := duration / to_signed(2000, 64); --schrittweite
  94. for i in 1 to 1999 loop
  95. steigung_last := steigung;
  96. --steigung := (data(i) - data(i-1)) / dt; --"Richtig"
  97. steigung := (data(i) - data(i-1));
  98. if (steigung < steigung_last) then
  99. data_pos_wendetangente := i;
  100. exit;
  101. end if;
  102. end loop;
  103. -- y = mx + b
  104. b := data(data_pos_wendetangente) - steigung * to_signed(data_pos_wendetangente, 32);
  105. Ks := data(1999);
  106. Tu := -b * dt / steigung;
  107. Tg := (Ks - b) * dt / steigung - Tu;
  108. --PI-Regler berechnen:
  109. --chien, hrones Reswick aperiodischer Verlauf Störung
  110. KR <= 6*Tg/Tu/Ks/10;
  111. TV <= to_signed(0, 10);
  112. TN <= 4 * Tu;
  113. end if;
  114. end if;
  115. end if;
  116. end process;
  117. end Behavioral;