Hm ... keine Ahnung was flasch war, Testbench lief natürlich auch nicht
also hab ich mal ein Minimalbeispiel aufgemacht und das funktioniert
prima. Edit: Aber wenn ich das in mein erweitertes Signalgeneratormodul
einbaue gibt es wieder diese Fehler. Also zuerst das funktionierende
Minimalbeispiel, dann die Testbench dazu und danach das was nicht
funktioniert.
Der Sinusgenerator als Minimalbeispiel. (1024 Punkte je 10 Bit):
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.numeric_std.all;
|
4 | use ieee.math_real.all;
|
5 |
|
6 | entity sin_minimal is Port(
|
7 | clk : in std_logic;
|
8 | output : out std_logic_vector(9 downto 0));
|
9 | end sin_minimal;
|
10 |
|
11 | architecture Behavioral of sin_minimal is
|
12 |
|
13 | signal pointer: unsigned(9 downto 0):=(others => '0');
|
14 | type Rom512x9 is array (0 to 511) of unsigned(8 downto 0);
|
15 | signal Sinus_Rom : Rom512x9;
|
16 |
|
17 | begin
|
18 |
|
19 | tabel : for I in 0 to 511 generate
|
20 | Sinus_Rom(I) <= to_unsigned(integer( sin(2.0*MATH_PI*(real(I)+0.5)/1024.0) *511.5),9);
|
21 | end generate;
|
22 |
|
23 | process begin
|
24 | wait until rising_edge(clk);
|
25 | pointer <= pointer +1;
|
26 |
|
27 | if pointer(9) = '0' then
|
28 | output <= std_logic_vector(to_unsigned(511 + to_integer(Sinus_Rom(to_integer(pointer(8 downto 0)))),10));
|
29 | else
|
30 | output <= std_logic_vector(to_unsigned(511 - to_integer(Sinus_Rom(to_integer(pointer(8 downto 0)))),10));
|
31 | end if;
|
32 |
|
33 | end process;
|
34 |
|
35 | end Behavioral;
|
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | entity sin_minimal_bench is
|
5 | end sin_minimal_bench;
|
6 |
|
7 | architecture Behavioral of sin_minimal_bench is
|
8 |
|
9 | component sin_minimal is Port(
|
10 | clk : in STD_LOGIC;
|
11 | output : out std_logic_vector(9 downto 0));
|
12 | end component;
|
13 |
|
14 | signal clk_in: std_logic:='0';
|
15 | signal output_out: std_logic_vector(9 downto 0):=(others => '0');
|
16 | constant clk_in_half_period : time := 5 ns;
|
17 |
|
18 | begin
|
19 |
|
20 | s0: sin_minimal port map(
|
21 | clk => clk_in,
|
22 | output => output_out);
|
23 |
|
24 | clk_in <= not clk_in after clk_in_half_period;
|
25 |
|
26 | end Behavioral;
|
Und hier das was nicht funktioniert:
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 | use ieee.math_real.all;
|
5 |
|
6 | entity siggen is port(
|
7 | clk : in std_logic;
|
8 | sigtype : in std_logic_vector(12 downto 10);
|
9 | freq : in std_logic_vector(9 downto 0);
|
10 | output : out std_logic_vector(15 downto 0));
|
11 | end siggen;
|
12 |
|
13 | architecture Behavioral of siggen is
|
14 |
|
15 | signal signalart: integer range 0 to 63:=0;
|
16 | signal freq_counter: unsigned(9 downto 0):=(others => '0');
|
17 | signal pointer: integer range 0 to 1023:=0;
|
18 | signal sin: unsigned(9 downto 0):=(others => '0');
|
19 | signal output_buff: std_logic_vector(15 downto 0):=(others => '0');
|
20 | type Rom512x9 is array (0 to 511) of unsigned(8 downto 0);
|
21 | signal Sinus_Rom : Rom512x9;
|
22 |
|
23 | begin
|
24 |
|
25 | tabel : for I in 0 to 511 generate
|
26 | Sinus_Rom(I) <= to_unsigned(integer( sin(2.0*MATH_PI*(real(I)+0.5)/1024.0)*511.5),9);
|
27 | end generate;
|
28 |
|
29 | process begin
|
30 | wait until rising_edge(clk);
|
31 | freq_counter <= freq_counter +1;
|
32 | output <= output_buff;
|
33 |
|
34 | if freq_counter >= unsigned(freq) then
|
35 | freq_counter <= (others => '0');
|
36 | end if;
|
37 |
|
38 | if freq_counter = 0 then
|
39 | pointer <= pointer +1;
|
40 | end if;
|
41 |
|
42 | if sigtype = "000" then
|
43 | if pointer < 512 then
|
44 | output_buff <= (others => '0');
|
45 | else
|
46 | output_buff <= std_logic_vector(to_unsigned(1023*19,16));
|
47 | end if;
|
48 | elsif sigtype = "001" then
|
49 | if pointer < 512 then
|
50 | output_buff <= std_logic_vector(to_unsigned(pointer*38,16));
|
51 | else
|
52 | output_buff <= std_logic_vector(to_unsigned(1023*38 - pointer*38,16));
|
53 | end if;
|
54 | elsif sigtype = "010" then
|
55 | output_buff <= std_logic_vector(to_unsigned(pointer*19,16));
|
56 | elsif sigtype = "011" then
|
57 | if pointer < 512 then
|
58 | sin <= to_unsigned(511 + to_integer(Sinus_Rom(pointer)),10);
|
59 | else
|
60 | sin <= to_unsigned(511 - to_integer(Sinus_Rom(pointer - 512)),10);
|
61 | end if;
|
62 | output_buff <= std_logic_vector(to_unsigned(to_integer(sin)*19,16));
|
63 | end if;
|
64 |
|
65 | end process;
|
66 |
|
67 | end Behavioral;
|
Und hier die Testbench dazu, läuft aber nicht die Simulation weil die
Fehler vorher auftreten.
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | entity siggen_bench is
|
5 | end siggen_bench;
|
6 |
|
7 | architecture Behavioral of siggen_bench is
|
8 |
|
9 | component siggen is port(
|
10 | clk : in std_logic;
|
11 | sigtype : in std_logic_vector(12 downto 10);
|
12 | freq : in std_logic_vector(9 downto 0);
|
13 | output : out std_logic_vector(15 downto 0));
|
14 | end component;
|
15 |
|
16 | signal clk_in: std_logic:='0';
|
17 | signal output_out: std_logic_vector(9 downto 0):=(others => '0');
|
18 | constant clk_in_half_period : time := 5 ns;
|
19 |
|
20 | begin
|
21 |
|
22 | s0: siggen port map(
|
23 | clk => clk_in,
|
24 | sigtype => "011",
|
25 | freq => "0000000001",
|
26 | output => output_out);
|
27 |
|
28 | clk_in <= not clk_in after clk_in_half_period;
|
29 |
|
30 | end Behavioral;
|