Mudanças entre as edições de "Circuito Somador e Subtrator - Pedroni"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
Linha 1: Linha 1:
 
__NOTOC__
 
__NOTOC__
 
==Estrutura==
 
==Estrutura==
*Realiza a soma e subtração através de operadores lógicos.
+
*Realiza a soma simples através do operador '+'.
*Primeiro converte para sinal, realiza a soma e subtração e depois converte para std_logic_vector.
 
  
==Código VHDL==
+
==VHDL==
 +
{{Collapse top | Código}}
 
<syntaxhighlight lang=vhdl>
 
<syntaxhighlight lang=vhdl>
 
--Book: Pedroni/491
 
--Book: Pedroni/491
Linha 14: Linha 14:
 
entity add_sub is
 
entity add_sub is
 
 
generic (
+
generic (n: natural := 4);
n: natural := 8);
 
 
 
 
port(
 
port(
 
a,b: in std_logic_vector (n-1 downto 0);
 
a,b: in std_logic_vector (n-1 downto 0);
sum, sub: out std_logic_vector (n-1 downto 0));
+
--sub : out std_logic_vector (n-1 downto 0));
 +
sum : out std_logic_vector (n-1 downto 0));
 
end entity;
 
end entity;
  
 
architecture add_sub of add_sub is
 
architecture add_sub of add_sub is
signal sum_sig, sub_sig : signed (n-1 downto 0);
+
signal sum_sig : signed (n-1 downto 0);
 
+
--signal sub_sig : signed (n-1 downto 0);
 +
 
begin
 
begin
 +
--Convert to signed and add_sub
 
sum_sig <= signed(a) + signed(b);
 
sum_sig <= signed(a) + signed(b);
sub_sig <= signed(a) - signed(b);
+
--sub_sig <= signed(a) - signed(b);
 
+
--Return to std_logic_vector
 
sum <= std_logic_vector (sum_sig);
 
sum <= std_logic_vector (sum_sig);
sub <= std_logic_vector (sub_sig);
+
--sub <= std_logic_vector (sub_sig);
  
 
end architecture;  
 
end architecture;  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
{{Collapse bottom}}
  
==Testbench==
+
*Chip planner:
*Código
+
[[Arquivo: somador_chip.png | 200px]]
*Resultado (print)
 
  
 
==Simulações==
 
==Simulações==
Linha 43: Linha 45:
 
! colspan="1" style="background: #efefef;" | Nº Bits
 
! colspan="1" style="background: #efefef;" | Nº Bits
 
! colspan="1" style="background: #efefef;" | ALMs
 
! colspan="1" style="background: #efefef;" | ALMs
! colspan="1" style="background: #efefef;" | Delay
 
 
! colspan="1" style="background: #efefef;" | Potência (mW)
 
! colspan="1" style="background: #efefef;" | Potência (mW)
 +
! colspan="1" style="background: #efefef;" | Report Path
 +
! colspan="1" style="background: #efefef;" | Report Timing
 
|-
 
|-
| 8 || 16 || x || 133.13
+
| 4 || x || x || x || x
|-
 
| 16 || 32 || x || 156.04
 
 
|-
 
|-
| 32 || 64 || x || 162.81
+
| 32 || x || x ||x || x
 
|-
 
|-
| 128 || 256 || x || 280.09
+
| 128 || x || x || x || x
 
|-
 
|-
 
|}
 
|}

Edição das 18h49min de 9 de abril de 2016

Estrutura

  • Realiza a soma simples através do operador '+'.

VHDL

Código
--Book: Pedroni/491
--8 bits
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity add_sub is
	
	generic (n: natural := 4);
	
	port(
		a,b: in std_logic_vector (n-1 downto 0);
		--sub : out std_logic_vector (n-1 downto 0));
		sum : out std_logic_vector (n-1 downto 0));
end entity;

architecture add_sub of add_sub is
	signal sum_sig : signed (n-1 downto 0);
	--signal sub_sig : signed (n-1 downto 0);
 
	begin
		--Convert to signed and add_sub
		sum_sig <= signed(a) + signed(b);
		--sub_sig <= signed(a) - signed(b);
		--Return to std_logic_vector
		sum <= std_logic_vector (sum_sig);
		--sub <= std_logic_vector (sub_sig);

end architecture;
  • Chip planner:

Somador chip.png

Simulações

Nº Bits ALMs Potência (mW) Report Path Report Timing
4 x x x x
32 x x x x
128 x x x x