Search code examples
vhdlfpgaxilinx

VHDL Testbench code doesn't work for register


I want to simulate the register logic , but the test bench don't working , when affect the input signal "Si, ECi, Ri, Ci", all signal input fixed to "0000000001" when I run the simulation in Xlinix , and Output fixed to "ZZZZZZZZ0" I don't know why?

Here's the code vhdl of register

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all; 
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;

entity Registre is
    Generic ( N: positive :=10);
    Port ( R : in  STD_LOGIC_VECTOR (N downto 1);
           EC : in  STD_LOGIC_VECTOR (N downto 1); 
           C : in  STD_LOGIC_VECTOR (N downto 1);
           S : in  STD_LOGIC_VECTOR (N downto 1);
           Vss : in  STD_LOGIC_VECTOR (N downto 1);
           Vdd : in STD_LOGIC_VECTOR (N downto 1);
           DA : out  STD_LOGIC_VECTOR (N downto 1));
end Registre;

architecture Behavioral of Registre is

    component SA_REG 
        Port ( EC : in  STD_LOGIC;
               C : in  STD_LOGIC;
               R : in  STD_LOGIC;
               S : in  STD_LOGIC;
               Q : out  STD_LOGIC;
               Vss : in  STD_LOGIC;
               Vdd : in  STD_LOGIC);
    end component;

    Component SA_REGDR
        Port ( R : in  STD_LOGIC;
               C : in  STD_LOGIC;
               EC : in  STD_LOGIC;
               Q : out  STD_LOGIC;
               Vss: in STD_LOGIC;
               Vdd: in STD_LOGIC
           );
    end component;

begin

    DR : SA_REGDR port map ( R=> R(10) ,EC=> EC(10), C=> C(10), Vss=> Vss(10), Vdd=> Vdd(10), Q=> DA(10) );

    Mgen : for i in 1 to N-1 generate
        M : SA_REG port map (R=>R(i), EC=> EC(i), C=> C(i),S=> S(i), Vss=> Vss(i), Vdd=> Vdd(i), Q=> DA(i) ); 
    end generate;

end Behavioral;

Test bench :

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;

entity Registre_tb is
end Registre_tb;

architecture Behavioral of Registre_tb is
    component Registre
        generic( N : integer :=10);
        Port ( R : in  STD_LOGIC_VECTOR (10 downto 1);
               EC : in  STD_LOGIC_VECTOR (10 downto 1);
               C : in  STD_LOGIC_VECTOR (10 downto 1);
               S : in  STD_LOGIC_VECTOR (10 downto 1);
               Vss : in  STD_LOGIC_VECTOR (10 downto 1);
               Vdd : in STD_LOGIC_VECTOR (10 downto 1);
               DA : out  STD_LOGIC_VECTOR (10 downto 1));
    end component;

    signal  Ri  : STD_LOGIC_VECTOR (10 downto 1):= (others => '0');
    signal  Ci  : STD_LOGIC_VECTOR (10 downto 1):= (others => '0');
    signal  ECi : STD_LOGIC_VECTOR (10 downto 1):= (others => '0');
    signal  Si  : STD_LOGIC_VECTOR (10 downto 1):= (others => '0');
    signal  Vssi: STD_LOGIC_VECTOR (10 downto 1):= (others => '0');
    signal  Vddi: STD_LOGIC_VECTOR (10 downto 1):= (others => '1');
    signal  DAi : STD_LOGIC_VECTOR (10 downto 1);

    signal clk : std_logic := '0';
begin
    -- instanciate 
    component_in_test : Registre port map( --instantiation of the Registre component
        R => Ri,
        C => Ci,
        EC => ECi,
        S => Si,
        Vss => Vssi,
        Vdd => Vddi,
        DA => DAi
    );

    -- stimulis 
    clk <= not clk after 1ns; --creates 100MHz clock inside testbench

    Ri_gen : process(clk) is   --process which will check Ri with every possible value
    begin
        if clk'Event and clk = '1' then
            Ri <= Ri + 1;
        end if;
    end process;

    Ci_gen : process(clk) is   --process which will check Ci with every possible value
    begin
        if clk'Event and clk = '1' then
            Ci <= Ci + 1;
        end if;
    end process;

    ECi_gen : process(clk) is   --process which will check ECi with every possible value
    begin
        if clk'Event and clk = '1' then
            ECi <= ECi + 1;
        end if;
    end process;

    Si_gen : process(clk) is   --process which will check Si with every possible value
    begin
        if clk'Event and clk = '1' then
            Si <= Si + 1;
        end if;
    end process;

end Behavioral;

Simulation enter image description here


Solution

  • See the discussion of longest static prefix in the VHDL FAQ at: http://www.eda.org/comp.lang.vhdl/FAQ1.html#drivers

    For this reason, you need to re-write your instance as:

    Mgen  : for i in 1 to N generate  
      If_N : if i = N generate
        DR : SA_REGDR port map ( R=> R(10) ,EC=> EC(10), C=> C(10), Vss=> Vss(10), Vdd=> Vdd(10), Q=> DA(10) ); 
      end generate ; 
    
      if_OTHERS : if i /= N generate
        M : SA_REG port map (R=>R(i), EC=> EC(i), C=> C(i),S=> S(i), Vss=> Vss(i), Vdd=> Vdd(i), Q=> DA(i) ); 
      end generate ; 
    end generate;