Цитата
На 40 МГц даже 40-разрядный сумматор будет работать без проблем. Сдаётся мне, что вы сумматор этот криво описываете. В общем, код - в студию!
Я даже попробовал сделать 2 сумматора.
1) "обычный", складываем два unsigned
Код
entity adder_simple is
port(
DataA : in std_logic_vector(31 downto 0);
Aclr : in std_logic;
Clock : in std_logic;
Sum : out std_logic_vector(39 downto 0);
Cout : out std_logic);
end adder_simple;
architecture behavioral of adder_simple is
signal DataA_unsigned : UNSIGNED(39 downto 0);
signal SumAPlusB_unsigned : UNSIGNED(39 downto 0);
signal SumOut_unsigned : UNSIGNED(39 downto 0);
begin
DataA_unsigned <= resize(UNSIGNED(DataA),40);
process (DataA_unsigned, SumOut_unsigned)
variable sumAux_unsigned : UNSIGNED(40 downto 0);
begin
sumAux_unsigned := ('0' & DataA_unsigned) + ('0' & SumOut_unsigned);
SumAPlusB_unsigned <= sumAux_unsigned(39 downto 0);
Cout <= not(std_logic(sumAux_unsigned (40)));
end process;
process (AClr, Clock)
begin
if (Aclr = '1') then
SumOut_unsigned <= TO_UNSIGNED(0, 40);
elsif (Clock'event and Clock = '1')then
SumOut_unsigned <= SumAPlusB_unsigned;
end if;
end process;
Sum <= std_logic_vector(SumOut_unsigned(39 downto 0));
end behavioral;
2) с ускоренным переносом. За основу взят код ускоренного сумматора из книжки
VHDL: Справочное пособие по основам языка:
Код
entity adder_fast is
port(
DataA : in std_logic_vector(31 downto 0);
Aclr : in std_logic;
Clock : in std_logic;
Sum : out std_logic_vector(39 downto 0);
carry_out : out std_logic);
end adder_fast;
architecture behavioral of adder_fast is
signal h_sum : unsigned(39 downto 0);
signal carry_generate : unsigned(39 downto 0);
signal carry_propogate : unsigned(39 downto 0);
signal carry_in_internal : unsigned(39 downto 1);
signal sumout : unsigned(39 downto 0);
signal dataA_unsigned : unsigned(39 downto 0);
begin
dataA_unsigned <= resize(UNSIGNED(DataA),40);
h_sum <= dataA_unsigned xor sumout;
carry_generate <= dataA_unsigned and sumout;
carry_propogate <= dataA_unsigned or sumout;
process(carry_generate,carry_propogate,carry_in_internal)
begin
carry_in_internal(1) <= carry_generate(0);
inst: for i in 1 to 38 loop
carry_in_internal(i+1) <= carry_generate(i) or (carry_propogate(i) and carry_in_internal(i));
end loop;
carry_out <= carry_generate(39) or (carry_propogate(39) and carry_in_internal(39));
end process;
process(AClr, Clock)
begin
if(Aclr = '1') then
sumout <= TO_UNSIGNED(0, 40);
elsif (Clock'event and Clock = '1')then
sumout(0) <= h_sum(0) xor '0';
sumout(39 downto 1) <= h_sum(39 downto 1) xor carry_in_internal(39 downto 1);
end if;
end process;
Sum <= std_logic_vector(sumout);
end behavioral;
Позже выложу графики из modelsim.
Цитата
always @(posedge clk)
begin
sum[39:20] <= sum[39:20] + adder[39:20] + co;
{co,sum[19:0]} <= {1'b0,sum[19:0]} + adder[19:0];
end
эммм, я vhdl учу. verilog воспринимаю пока что с трудом... Не могли бы переконвертировать? суть, в принципе, ясна. но вот эти {} ???