2017-12-14 3 views
1

내가 * 4 VHDL에 RAM (16)에 대한 코드를 작성하려고하고 코드는 다음과 같습니다이오고있다 오류입니다요구 도움

entity RAM_16_4 is 
Port (clk : in STD_LOGIC; 
     WR : in STD_LOGIC; 
     add : in STD_LOGIC_VECTOR (3 downto 0); 
     Di : in STD_LOGIC_VECTOR (3 downto 0); 
     Do : out STD_LOGIC_VECTOR (3 downto 0)); 
end RAM_16_4; 

architecture Behavioral of RAM_16_4 is 

type RAM is array (15 downto 0) of std_logic_vector (3 downto 0); 
signal int : STD_LOGIC_VECTOR (3 downto 0); 
signal x : STD_LOGIC_VECTOR (3 downto 0); 
begin 

process (clk,WR) 
begin 

if (clk'event and clk='1') then 
if (WR='1') then 
int<= conv_integer (add); 
int<= Di; 
end if; 
x<=add; 
end if; 
end process; 

x<= conv_integer (add); 
Do<= x; 

end Behavioral; 

: INT의 유형은 유형과 호환되지 않습니다 conv_integer의

이 오류를 제거하려면 어떻게해야합니까?

+0

'때문에 conv_integer'합니다. 재미있게도'int'와'add'를 같은 타입으로 선언 했으므로 변환하지 않고 할당하십시오. 또는 텍스트 줄이 쓸모 없게 만들었으므로이 줄을 모두 삭제하십시오. –

+0

코드를 읽고 이해할 수 있도록 코드를 들여 씁니다. – Paebbels

답변

2

conv_integerstd_logic_vectorinteger으로 변환합니다. 해당 integerstd_logic_vector에 할당 할 수 없습니다. addint 또는 x을 할당하려는 경우 왜 conv_integer을 사용 하시겠습니까? conv_integer은 사용하지 않아야 비 표준화 된 패키지 std_logic_arith 또는 std_logic_unsigned의 일부임을 유의하시기 바랍니다 : 그들은

더 중요한 것은 ... 모두 같은 유형입니다. 대신 표준 패키지 numeric_std에서 to_integer(unsigned(...))을 사용해야합니다.

FPGA 용 RAM을 구현할 때는 FPGA 제조업체 안내서를 참조해야합니다. Xilinx Synthesis User Guide

-- Single-Port RAM with Asynchronous Read (Distributed RAM) 
-- File: rams_dist.vhd 
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 

entity rams_dist is 
    port(
     clk : in std_logic; 
     we : in std_logic; 
     a : in std_logic_vector(5 downto 0); 
     di : in std_logic_vector(15 downto 0); 
     do : out std_logic_vector(15 downto 0) 
    ); 
end rams_dist; 

architecture syn of rams_dist is 
    type ram_type is array (63 downto 0) of std_logic_vector(15 downto 0); 
    signal RAM : ram_type; 
begin 
    process(clk) 
    begin 
     if (clk'event and clk = '1') then 
      if (we = '1') then 
       RAM(conv_integer(a)) <= di; 
      end if; 
     end if; 
    end process; 
    do <= RAM(conv_integer(a)); 
end syn; 

에서 예를 들어 ... 음, 쓰레기 .... 자일링스는 또한 잘못된 변환 기능을 사용하고 있습니다. 의 표준화 된 코드에 그것을 다시 보자 (비 표준 라이브러리에서 제공) int``당신의 선언과 호환되지 않는 뭔가를 반환

-- Single-Port RAM with Asynchronous Read (Distributed RAM) 
-- File: rams_dist.vhd 
library ieee; 
use ieee.std_logic_1164.all; 

entity rams_dist is 
    port(
     clk : in std_logic; 
     we : in std_logic; 
     a : in std_logic_vector(5 downto 0); 
     di : in std_logic_vector(15 downto 0); 
     do : out std_logic_vector(15 downto 0) 
    ); 
end rams_dist; 

architecture syn of rams_dist is 
    use ieee.numeric_std.all; 
    type ram_type is array (2**a'length-1 downto 0) of std_logic_vector(di'length-1 downto 0); 
    signal RAM : ram_type := (others => (others => '0')); -- let's initialize it at zeros 
begin 
    ram_proc: process(clk) 
    begin 
     if rising_edge(clk) then 
      if we = '1' then 
       RAM(to_integer(unsigned(a))) <= di; 
      end if; 
     end if; 
    end process; 
    do <= RAM(to_integer(unsigned(a))); 
end syn; 
+0

더 나은 ... 실제로 싸우는 대신 입력 체계를 사용하십시오 ... 주소가 부호없는 번호 인 경우 그 사실을 설계에 전달하십시오. 'a'를'unsigned' (numeric_std) 또는'natural'으로 선언하십시오. 불필요한 유형 변환을 정리하고 코드를 단순하게 만드는 것은 보너스입니다. 나는 더 나아가서 너무 많은 타입 변환이 (뭔가 std_logic_vector를 숫자로 사용하는 것과 같은) 디자인에 문제가 있다는 표시라고 말합니다. –

+0

@BrianDrummond True이지만 Building Block을 개발할 때 (예 : Vivado IP Integrator의 경우), (최상위 레벨) 포트에'std_logic' 타입이 필요할 때가 있습니다 ... – JHBonarius