Last active
December 18, 2015 17:59
-
-
Save tonussi/5822655 to your computer and use it in GitHub Desktop.
projeto vhd multiplicador
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
ENTITY bc IS | |
PORT (Reset, clk, inicio : IN STD_LOGIC; | |
Az, Bz : IN STD_LOGIC; | |
pronto : OUT STD_LOGIC; | |
ini, CA, dec, CP: OUT STD_LOGIC ); | |
END bc; | |
-- Sinais de comando | |
-- ini = RstP = mA = CB => ini=1 somente em S1 | |
-- CA=1 em S1 e em S4 | |
-- dec = op = m1 = m2 => dec=1 somente em S4 (estado no qual ocorre A <= A - 1 ) | |
-- CP=1 somente em S3 (estado no qual ocorre P <= P + B ) | |
ARCHITECTURE estrutura OF bc IS | |
TYPE state_type IS (S0, S1, S2, S3, S4, S5 ); | |
SIGNAL state: state_type; | |
BEGIN | |
-- Logica de proximo estado (e registrador de estado) | |
PROCESS (clk, Reset) | |
BEGIN | |
if(Reset = '1') THEN | |
state <= S0 ; | |
ELSIF (clk'EVENT AND clk = '1') THEN | |
CASE state IS | |
WHEN S0 => | |
IF (inicio = '1') THEN | |
state <= S1; | |
ELSE | |
state <= S0; | |
END IF; | |
WHEN S1 => | |
state <= S2; | |
WHEN S2 => | |
IF (Az = '0'AND Bz = '0') THEN | |
state <= S3; | |
ELSE | |
state <= S5; | |
END IF; | |
WHEN S3 => | |
state <= S4; | |
WHEN S4 => | |
state <= S2; | |
WHEN S5 => | |
state <= S0; | |
END CASE; | |
END IF; | |
END PROCESS; | |
-- Logica de saida | |
PROCESS (state) | |
BEGIN | |
CASE state IS | |
WHEN S0 => | |
ini <= '0'; | |
CA <= '0'; | |
dec <= '0'; | |
CP <= '0'; | |
pronto <= '0'; | |
WHEN S1 => | |
ini <= '1'; | |
CA <= '1'; | |
dec <= '0'; | |
CP <= '0'; | |
pronto <= '0'; | |
WHEN S2 => | |
ini <= '0'; | |
CA <= '0'; | |
dec <= '0'; | |
CP <= '0'; | |
pronto <= '0'; | |
WHEN S3 => | |
ini <= '0'; | |
CA <= '0'; | |
dec <= '0'; | |
CP <= '1'; | |
pronto <= '0'; | |
WHEN S4 => | |
ini <= '0'; | |
CA <= '1'; | |
dec <= '1'; | |
CP <= '0'; | |
pronto <= '0'; | |
WHEN S5 => | |
ini <= '0'; | |
CA <= '0'; | |
dec <= '0'; | |
CP <= '0'; | |
pronto <= '1'; | |
END CASE; | |
END PROCESS; | |
END estrutura; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
USE ieee.std_logic_unsigned.all; | |
ENTITY bo IS | |
PORT (clk : IN STD_LOGIC; | |
ini, CP, CA, dec : IN STD_LOGIC; | |
entA, entB : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
Az, Bz : OUT STD_LOGIC; | |
saida, conteudoA, conteudoB : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END bo; | |
-- Sinais de comando | |
-- ini = RstP = mA = CB => ini=1 somente em S1 | |
-- CA=1 em S1 e em S4 | |
-- dec = op = m1 = m2 => dec=1 somente em S4 (estado no qual ocorre A <= A - 1 ) | |
-- CP=1 somente em S3 (estado no qual ocorre P <= P + B ) | |
-- OBS: as saidas conteudoA e conteudoB so servem para inspecionar o conteudos de regA e regB | |
-- Assim que o codigo VHDL estiver depurado, elas deveriam ser retiradas para nao utilizar recursos | |
ARCHITECTURE estrutura OF bo IS | |
COMPONENT registrador_r IS | |
PORT (clk, reset, carga : IN STD_LOGIC; | |
d : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END COMPONENT; | |
COMPONENT registrador IS | |
PORT (clk, carga : IN STD_LOGIC; | |
d : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END COMPONENT; | |
COMPONENT mux2para1 IS | |
PORT ( a, b : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
sel: IN STD_LOGIC; | |
y : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END COMPONENT; | |
COMPONENT somadorsubtrator IS | |
PORT (a, b : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
op: IN STD_LOGIC; | |
s : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END COMPONENT; | |
COMPONENT igualazero IS | |
PORT (a : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
igual : OUT STD_LOGIC); | |
END COMPONENT; | |
SIGNAL saimux1, saimux2, saimux3, sairegP, sairegA, sairegB, saisomasub: STD_LOGIC_VECTOR (3 DOWNTO 0); | |
BEGIN | |
mux1: mux2para1 PORT MAP ( saisomasub, entA, ini, saimux1 ); | |
regP: registrador_r PORT MAP (clk, ini, CP, saisomasub, sairegP); | |
regA: registrador PORT MAP (clk, CA, saimux1, sairegA ); | |
regB: registrador PORT MAP (clk, ini, entB, sairegB ); | |
mux2: mux2para1 PORT MAP ( sairegP, sairegA, dec, saimux2 ); | |
mux3: mux2para1 PORT MAP ( sairegB, "0001", dec, saimux3 ); | |
somasub: somadorsubtrator PORT MAP (saimux2, saimux3, dec, saisomasub); | |
geraAz: igualazero PORT MAP ( sairegA, Az ); | |
geraBz: igualazero PORT MAP ( sairegB, Bz ); | |
saida <= sairegP; | |
conteudoA <= sairegA; | |
conteudoB <= sairegB; | |
END estrutura; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
force /clk 0 0ns, 1 10ns -r 20ns | |
force /entA 0011 0ns | |
force /entB 0100 0ns | |
force /ini 0 0ns, 1 20ns, 0 40ns | |
force /cA 0 0ns, 1 20ns, 0 40ns, 1 80ns, 0 100ns, 1 140ns, 0 160ns, 1 200ns, 0 220ns | |
force /cP 0 0ns, 1 60ns, 0 80ns, 1 120ns, 0 140ns, 1 180ns, 0 200ns | |
force /dec 0 0ns, 1 80ns, 0 100ns, 1 140ns, 0 160ns, 1 200ns, 0 220ns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
USE ieee.std_logic_unsigned.all; | |
ENTITY igualazero IS | |
PORT (a : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
igual : OUT STD_LOGIC); | |
END igualazero; | |
ARCHITECTURE estrutura OF igualazero IS | |
BEGIN | |
igual <= '1' WHEN A = "0000" ELSE '0'; | |
END estrutura; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
ENTITY multiplicador IS | |
port( | |
clk, Reset, inicio: in std_logic; | |
entA, entB: in std_logic_vector(3 downto 0); | |
saida: out std_logic_vector(3 downto 0); | |
pronto: out std_logic | |
); | |
end entity; | |
architecture estrutura of multiplicador is | |
component bc IS | |
PORT (Reset, clk, inicio : IN STD_LOGIC; | |
Az, Bz : IN STD_LOGIC; | |
pronto : OUT STD_LOGIC; | |
ini, CA, dec, CP: OUT STD_LOGIC ); | |
END component; | |
component bo IS | |
PORT (clk : IN STD_LOGIC; | |
ini, CP, CA, dec : IN STD_LOGIC; | |
entA, entB : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
Az, Bz : OUT STD_LOGIC; | |
saida, conteudoA, conteudoB : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END component; | |
signal ini, CP, CA, dec, Az, Bz: std_logic; | |
begin | |
bc0: bc port map(Reset, clk, inicio,Az, Bz,pronto,ini, CA, dec, CP); | |
bo0: bo port map(clk,ini, CP, CA, dec,entA, entB,Az, Bz,saida, open, open); | |
end architecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
ENTITY multiplicador IS | |
port( | |
clk, Reset, inicio: in std_logic; | |
entA, entB: in std_logic_vector(3 downto 0); | |
saida: out std_logic_vector(3 downto 0); | |
pronto: out std_logic | |
); | |
end entity; | |
architecture estrutura of multiplicador is | |
component bc IS | |
PORT (Reset, clk, inicio : IN STD_LOGIC; | |
Az, Bz : IN STD_LOGIC; | |
pronto : OUT STD_LOGIC; | |
ini, CA, dec, CP: OUT STD_LOGIC ); | |
END component; | |
component bo IS | |
PORT (clk : IN STD_LOGIC; | |
ini, CP, CA, dec : IN STD_LOGIC; | |
entA, entB : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
Az, Bz : OUT STD_LOGIC; | |
saida, conteudoA, conteudoB : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END component; | |
signal ini, CP, CA, dec, Az, Bz: std_logic; | |
begin | |
bc0: bc port map(Reset, clk, inicio,Az, Bz,pronto,ini, CA, dec, CP); | |
bo0: bo port map(clk,ini, CP, CA, dec,entA, entB,Az, Bz,saida, open, open); | |
end architecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
ENTITY mux2para1 IS | |
PORT ( a, b : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
sel: IN STD_LOGIC; | |
y : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END mux2para1 ; | |
ARCHITECTURE comportamento OF mux2para1 IS | |
BEGIN | |
WITH sel SELECT | |
y <= a WHEN '0', | |
b WHEN OTHERS; | |
END comportamento; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
USE ieee.std_logic_unsigned.all; | |
ENTITY registrador IS | |
PORT (clk, carga : IN STD_LOGIC; | |
d : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END registrador; | |
ARCHITECTURE estrutura OF registrador IS | |
BEGIN | |
PROCESS(clk) | |
BEGIN | |
IF (clk'EVENT AND clk = '1' AND carga = '1') THEN | |
q <= d; | |
END IF; | |
END PROCESS; | |
END estrutura; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
USE ieee.std_logic_unsigned.all; | |
ENTITY registrador_r IS | |
PORT (clk, reset, carga : IN STD_LOGIC; | |
d : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END registrador_r; | |
ARCHITECTURE estrutura OF registrador_r IS | |
BEGIN | |
PROCESS(clk, reset) | |
BEGIN | |
IF(reset = '1') THEN | |
q <= "0000"; | |
ELSIF(clk'EVENT AND clk = '1' AND carga = '1') THEN | |
q <= d; | |
END IF; | |
END PROCESS; | |
END estrutura; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY ieee; | |
USE ieee.std_logic_1164.all; | |
USE ieee.std_logic_unsigned.all; | |
ENTITY somadorsubtrator IS | |
PORT (a, b : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | |
op: IN STD_LOGIC; | |
s : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); | |
END somadorsubtrator; | |
ARCHITECTURE estrutura OF somadorsubtrator IS | |
BEGIN | |
WITH op SELECT | |
s <= a + b WHEN '0', | |
a - b WHEN OTHERS; | |
END estrutura; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment