2014-04-28 3 views
1

8 비트 배수, 3 비트 제수를 취하고 5 비트 몫 (3 비트 나머지)을 제공하는 이진 디바이더 코드를 작성했습니다. 나는 문자 그대로 잘못된 결과를주는 버그를 고치려고 몇 시간을 보냈지 만 그것을 식별하지 못했습니다. 어떤 도움 이라든지 대단히 감사 할 것입니다! 기본적으로 입력에 대해 잘못된 대답을 얻지 만 이유를 파악할 수 없습니다. 값을 취하는 버스가 있고 st가 1 인 첫 번째 클럭 사이클에서 배당 레지스터가로드됩니다. 이후 두 번째 클럭 사이클에서 제수 레지스터가로드되고 다음 세 클럭 사이클 동안 계산이 수행됩니다.바이너리 나누기 VHDL 코드

V 신호는 오버플로가 발생했음을 나타내는 출력입니다 (결과는 몫의 5 비트에 맞지 않습니다). my st는 프로세스를 시작하는 시작 신호이고, sh는 시프트 신호입니다 시프트 레지스터의 경우, su는 감산기의 감산 신호입니다. http://imgur.com/fqfiYJZ1 uploaded image

영상의 제수 배당 내 레지스터 정확하게 로딩되었는지 보여준다 [신호]

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; 

여기에 내 입력과 출력이있다. 그래서 문제는 실제 부서 코드에 있다고 생각합니다. 상태 머신도 제대로 작동하는 것 같습니다.

+0

잘못된 결과는 무엇입니까? 우리는 문제의 위치를 ​​알아 내고 추측 할 수있는 코드의 벽을 읽지 않을 것입니다. –

+0

구문 오류가 없습니다. 내 코드가 기본적으로 잘못된 입력 결과를 뱉어내는 것을 발견했습니다. – user3582919

+1

. 입력과 잘못된 출력을 보면 우리에게 많은 것을 알릴 수 있습니다. –

답변

-1

직접 쓰지 마십시오. 당신은 바퀴를 다시 발명하고 있습니다.

어느 q <= a/b;

쓰기 또는 FPGA 공급 업체에서 IP 코어를 사용합니다.