看板Electronics
标 题why?
发信站清华资讯(枫桥驿站) (Fri Apr 21 15:41:53 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!netnews.csie.nctu!news.cs.nthu!netne
下面是在做4-bit除法器的程式码,在11/2=5余1的测试中
在modelsim进行simulate Behavioral Model时,接近我想要的动作
但是,在r_reg=00101100时,下一动作居然是00001000,不是我想要的00001100或00011000
检查半天还是找不出来......
另外,不知为什麽用Simulate Post-Place&Route VHDL Model模拟时,又跟
simulate Behavioral Model有很大的不同,而且不是我想要的结果....
到底是哪边写错或观念错误呢?可否请高手指点,感谢...
=============================================================
entity sas is
Port ( CLK : in STD_LOGIC;
RST : in STD_LOGIC;
A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
R : out STD_LOGIC_VECTOR (3 downto 0);
Q : out STD_LOGIC_VECTOR (3 downto 0));
end sas;
architecture Behavioral of sas is
signal R_reg : std_logic_vector(7 downto 0);
signal Q_reg : std_logic_vector(3 downto 0);
signal A_reg : std_logic_vector(3 downto 0);
signal B_reg : std_logic_vector(3 downto 0);
signal sel : std_logic_vector(1 downto 0);
signal ent : std_logic;
signal cnt : integer range 0 to 3;
begin
process (CLK,RST)
begin
if (CLK'event and CLK = '1') then
if RST = '1' then
R_reg <= "00000000";
Q_reg <= "0000";
A_reg <= "0000";
B_reg <= "0000";
ent <='0';
cnt <= 0;
elsif (A /= A_reg) or (B /= B_reg) then
sel <= "00";
A_reg <= A;
B_reg <= B;
end if;
case sel is
when "00" =>
R_reg(3 downto 0) <= A;
sel <= "01";
cnt <= 0;
when "01" =>
R_reg(7 downto 0) <= R_reg(6 downto 0) & '0';
Q_reg(3 downto 1) <= Q_reg(2 downto 0);
if R_reg(7 downto 4) < B then
Q_reg(0) <= '0';
cnt <= cnt + 1;
else
Q_reg(0) <= '1';
R_reg(7 downto 4) <= R_reg(7 downto 4) - B;
end if;
if cnt = 3 then
sel <= "10";
else
sel <= "01";
end if;
when others =>
R <= R_reg(7 downto 4);
Q <= Q_reg;
end case;
end if;
end process;
end Behavioral;
--
※ Origin: 枫桥驿站<bbs.cs.nthu.edu.tw> ◆ From: 210-58-7-53.cm.dynamic.apol.com.tw