1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.std_logic_arith.all;
|
4 | |
5 | |
6 | |
7 | |
8 | entity PID_Regler is
|
9 | generic(
|
10 | data_width: integer:= 14;
|
11 | intern_data_width: integer:= 28;
|
12 | TA: integer:=1
|
13 | );
|
14 | port (
|
15 | w : in std_logic_vector(data_width-1 downto 0); --:= (others => '0');
|
16 | x : in std_logic_vector(data_width-1 downto 0); --:= (others => '0');
|
17 | y : out std_logic_vector(data_width-1 downto 0); --:= (others => '0');
|
18 | TP : in std_logic_vector(intern_data_width-1 downto 0);
|
19 | TI : in std_logic_vector(intern_data_width-1 downto 0);
|
20 | TD : in std_logic_vector(intern_data_width-1 downto 0);
|
21 | clk_i : in std_logic;
|
22 | rst_i : in std_logic
|
23 | );
|
24 | end PID_Regler;
|
25 | |
26 | architecture Behavioral of PID_Regler is
|
27 | |
28 | signal e1 : std_logic_vector(data_width-1 downto 0) := (others => '0');
|
29 | signal ealt : std_logic_vector(data_width-1 downto 0) := (others => '0');
|
30 | signal e2 : std_logic_vector(data_width-1 downto 0) := (others => '0');
|
31 | signal e3 : std_logic_vector(data_width-1 downto 0) := (others => '0');
|
32 | |
33 | begin
|
34 | |
35 | Regler1: process(clk_i, rst_i)
|
36 | --rst_i wurde hinzugefügt
|
37 | variable yp: std_logic_vector(intern_data_width-1 downto 0);
|
38 | variable yi: std_logic_vector(intern_data_width-1 downto 0);
|
39 | variable yi_alt: std_logic_vector(intern_data_width-1 downto 0);
|
40 | variable yd: std_logic_vector(intern_data_width-1 downto 0);
|
41 |
|
42 | begin
|
43 | if (rst_i = '1') then
|
44 | yp := (others => '0');
|
45 | yi := (others => '0');
|
46 | yi_alt:=(others => '0');
|
47 | yd := (others => '0');
|
48 | y <= (others => '0');
|
49 | elsif (clk_i='1') then
|
50 | e1 <= std_logic_vector(signed(w) - signed(x));
|
51 | yp := (signed(TP)*signed(e1));
|
52 | yi := yi_alt+(TI*e1*TA); -- yi_alt=yi
|
53 | yd := (TD*((e1-ealt)/TA)); -- ealt=e
|
54 | ealt <= e1;
|
55 | y <= (yp+yi+yd);
|
56 | |
57 | yi_alt := yi;
|
58 | end if;
|
59 | end process Regler1;
|
60 | |
61 | |
62 | |
63 | Regler2: process(clk_i, rst_i)
|
64 | --rst_i wurde hinzugefügt
|
65 | variable yp: std_logic_vector(intern_data_width-1 downto 0);
|
66 | variable yi: std_logic_vector(intern_data_width-1 downto 0);
|
67 | variable yi_alt: std_logic_vector(intern_data_width-1 downto 0);
|
68 | variable yd: std_logic_vector(intern_data_width-1 downto 0);
|
69 |
|
70 | begin
|
71 | if (rst_i = '1') then
|
72 | yp := (others => '0');
|
73 | yi := (others => '0');
|
74 | yd := (others => '0');
|
75 | ealt <= (others => '0');
|
76 | y <= (others => '0');
|
77 | elsif (clk_i='1') then
|
78 | e2 <= std_logic_vector(signed(w) - signed(x));
|
79 | yp := ((TP)*(e2));
|
80 | yi := ((yi_alt)+((TI)*(e2)*TA)); -- yi_alt=yi
|
81 | yd := ((TD)*(((e2)-(ealt))/TA)); -- ealt=e
|
82 | ealt <= e2;
|
83 | y <= ((yp)+(yi)+(yd));
|
84 | |
85 | yi_alt := yi;
|
86 | end if;
|
87 | end process Regler2;
|
88 | |
89 | |
90 | Regler3: process(clk_i, rst_i)
|
91 | --rst_i wurde hinzugefügt
|
92 | variable yp: std_logic_vector(intern_data_width-1 downto 0);
|
93 | variable yi: std_logic_vector(intern_data_width-1 downto 0);
|
94 | variable yi_alt: std_logic_vector(intern_data_width-1 downto 0);
|
95 | variable yd: std_logic_vector(intern_data_width-1 downto 0);
|
96 |
|
97 | begin
|
98 | if (rst_i = '1') then
|
99 | yp := (others => '0');
|
100 | yi := (others => '0');
|
101 | yd := (others => '0');
|
102 | y <= (others => '0');
|
103 | elsif(clk_i='1') then
|
104 | e3 <= std_logic_vector(signed(w) - signed(x));
|
105 | yp := ((TP)*e3);
|
106 | yi := ((yi_alt)+((TI)*(e3)*TA)); -- yi_alt=yi
|
107 | yd := ((TD)*(((e3)-(ealt))/TA)); -- ealt=e
|
108 | ealt <= (e3);
|
109 | y <= ((yp)+(yi)+(yd));
|
110 | |
111 | yi_alt := yi;
|
112 | end if;
|
113 | end process Regler3;
|
114 | end Behavioral;
|
115 | |
116 | •
|