8 ビットの被除数、3 ビットの除数を取り、5 ビットの商 (3 ビットの剰余) を与える 2 進除算器のコードを作成しました。誤った結果をもたらすバグを修正するために文字通り何時間も費やしましたが、それを特定できませんでした。どんな助けでも大歓迎です!入力に対して基本的に間違った答えが得られますが、その理由がわかりません。値を取り込むバスがあり、st が 1 である最初のクロック サイクルで、被除数レジスタがロードされます。2 番目のクロック サイクルで除数レジスタがロードされ、次の 3 クロック サイクルの計算が行われます。
V 信号は、オーバーフローが発生したことを示す出力です (結果は商の 5 ビットに収まりません)。my st はプロセスを開始する開始信号です。sh はシフト レジスタのシフト信号です。 、su は減算器の減算信号です。
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity Divider is
Port (bus_in: in std_logic_vector(8 downto 0);
St, Clk, reset: in std_logic;
Quotient: out std_logic_vector(4 downto 0);
Remainder: out std_logic_vector(2 downto 0);
v: out std_logic);
end Divider;
architecture Behavioral of Divider is
signal State, NextState: integer range 0 to 5;
signal C, Ld1, Ld2, Su, Sh: std_logic;
signal Divisor: std_logic_vector(2 downto 0);
signal Subout: std_logic_vector(3 downto 0);
signal Dividend: std_logic_vector(8 downto 0);
begin
Subout <= Dividend(8 downto 5) - ('0' & divisor);
C <= not Subout (3);
Remainder <= Dividend(7 downto 5);
Quotient <= Dividend(4 downto 0);
State_Graph: process (State, St, C)
begin
Ld1 <= '0';
Ld2<='0';
v <= '0';
Sh <= '0';
Su <= '0';
case State is
when 0 =>
if (St = '1') then
Ld1 <= '1';
NextState <= 1;
else
NextState <= 0;
end if;
when 1 =>
if (St = '1') then
Ld2 <= '1';
NextState <= 2;
else
Ld2<='1';
NextState <= 2;
end if;
when 2 =>
if (C = '1') then
v <= '1';
NextState <= 0;
else
Sh <= '1';
NextState <= 3;
end if;
when 3 | 4 =>
if (C = '1') then
Su <= '1';
NextState <= State;
else
Sh <= '1';
NextState <= State + 1;
end if;
when 5 =>
if (C = '1') then
Su <= '1';
end if;
NextState <= 0;
end case;
end process State_Graph;
Update: process (Clk)
begin
if Clk'event and Clk = '1' then
State <= NextState;
--if Load = '1' then
-- Dividend <= '0' & bus_in;
--end if;
if Ld1 = '1' then
Dividend <= '0'&Bus_in(7 downto 0);
end if;
if Ld2 = '1' then
Divisor <= Bus_in(2 downto 0);
end if;
if Su = '1' then
Dividend(8 downto 5) <= Subout;
Dividend(0) <= '1';
end if;
if Sh = '1' then --94
Dividend <= Dividend(7 downto 0) & '0';
end if;
end if;
end process update;
end Behavioral;
ここに私の入力と出力があります: [シグナル]: http://imgur.com/fqfiYJZ 1
写真は、除数と被除数のレジスタが正しくロードされていることを示しています。したがって、問題は実際の部門コードにあると思います。ステート マシンも正常に動作しているようです。