2016-06-28 4 views
0

J'ai 9 bascules et une entrée de réinitialisation. J'ai besoin de régler les sorties de 8 flipflops à 0 lorsque la réinitialisation est 0. Et la sortie d'un flipflop à 1. Cette bascule unique et jamais changée. Comment faire?Différentes bascules - différentes sorties pour une entrée de réinitialisation

Code de flipflops:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity d_ff is 
    port 
    (
     clk : in std_logic; 
     rst : in std_logic;  
     d : in std_logic; 
     q : out std_logic 
    ); 
end entity d_ff; 

architecture logicFunc of d_ff is 
begin 
    process (clk) is 
    begin 
     if (rst='0') then 
      q <= '0'; 
     elsif (clk'event and clk = '1') then 
      q <= d; 
     end if; 
    end process; 
end architecture logicFunc; 

Maintenant, ce code définit tous flipflops à 0 lorsque la réinitialisation est 0 et je ne peux pas changer la sortie de la première bascule dans le programme principal

Répondre

1

Les 8 flipflops qui réinitialiser à '0' vous pouvez utiliser le code que vous avez présenté. Pour l'autre bascule vous pouvez créer une autre entité d_ff1:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity d_ff1 is 
    port 
    (
     clk : in std_logic; 
     rst : in std_logic;  
     d : in std_logic; 
     q : out std_logic 
    ); 
end entity d_ff1; 

architecture logicFunc of d_ff1 is 
begin 
    process (clk) is 
    begin 
     if (rst='0') then 
      q <= '1'; 
     elsif (clk'event and clk = '1') then 
      q <= d; 
     end if; 
    end process; 
end architecture logicFunc; 

De cette façon, est conforme à la façon dont vous vouliez avoir une bascule des entités séparées.

+0

Solution si facile. Comment je ne l'ai pas fait. Merci! – levshkatov

3

Une alternative consiste à utiliser des génériques. Cela vous permet d'utiliser exactement le même code pour toutes vos instances d_ff. Par exemple:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity d_ff is 
    generic 
    (
     RESET_VALUE : std_logic 
    ); 
    port 
    (
     clk : in std_logic; 
     rst : in std_logic;  
     d : in std_logic; 
     q : out std_logic 
    ); 
end entity d_ff; 

architecture logicFunc of d_ff is 
begin 
    process (clk) is 
    begin 
     if (rst='0') then 
      q <= RESET_VALUE; 
     elsif (clk'event and clk = '1') then 
      q <= d; 
     end if; 
    end process; 
end architecture logicFunc; 

Puis, quand vous en servez pour créer vos 8 FF de qui réinitialisent à un « 0 » et 1 FF qui remet à zéro à un « 1 »:

library ieee; 
use ieee.std_logic_1164.all; 

entity foo is 
    port map 
    (
    clk : in std_logic; 
    rst : in std_logic; 
    d : in std_logic_vector(8 downto 0); 
    q : out std_logic_vector(8 downto 0) 
) 
end entity foo; 

architecture structural of foo is 
begin 
    ff_gen : for i in 0 to 7 generate 
    begin 
    ff : entity work.d_ff 
    generic map 
    (
     RESET_VALUE => '0' 
    ) 
    port map 
    (
     clk => clk, 
     rst => rst, 
     d => d(i), 
     q => q(i) 
    ); 
    end generate ff_gen; 

    ff0_gen : entity work.d_ff 
    generic map 
    (
    RESET_VALUE => '1' 
) 
    port map 
    (
    clk => clk, 
    rst => rst, 
    d => d(8), 
    q => q(8) 
); 
end architecture structural; 
2

Pourquoi une d_ff entité du tout? Pourquoi avoir un niveau de hiérarchie séparé? Aucun utilisateur professionnel de VHDL ne le ferait à moins qu'il y ait une raison particulière pour cela. Au lieu de cela, il suffit de mettre en œuvre vos 9 bascules en tant que processus:

process (clk) is 
    begin 
     if rst='0' then 
      q < = "000000001"; 
     elsif rising_edge(clk) then 
      q <= d; 
     end if; 
    end process;