빈도가 높은 부품에 대한 HDL 설명 예제 - 내부 RAM -
내부 램은 FPGA 내부에서 전용 모듈로 구현되기 때문에 도구로 자주 생성되지만, 아래 기재를 통해 도구 측 추론은 내부 램으로 대체할 수 있다.(굳이 말하자면, 나는 Xilinx가 비교적 잘한다고 생각한다.)
예1
간단한 단일 포트 RAM 예제읽기 주소가 같으면 we=1로 데이터를 씁니다.
VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram is
port(
clk : in std_logic;
we : in std_logic;
addr : in std_logic_vector(5 downto 0);
din : in std_logic_vector(7 downto 0);
dout : out std_logic_vector(7 downto 0)
);
end ram;
architecture rtl of ram is
type mem_type is array (63 downto 0) of std_logic_vector(7 downto 0);
signal mem : mem_type;
begin
process(clk)
begin
if (clk'event and clk = '1') then
if (we = '1') then
mem(conv_integer(addr)) <= din;
end if;
dout <= mem(conv_integer(addr));
end if;
end process;
end rtl;
verilogmodule ram
(
input wire clk,
input wire we,
input wire [5:0] addr,
input wire [7:0] din,
output reg [7:0] dout
);
reg [7:0] mem [63:0];
always @(posedge clk) begin
if (we) begin
mem[addr] <= din;
end
dout <= mem[addr];
end
endmodule
예2
간단한 듀얼 포트 RAM의 예.쓰기 측과 읽기 측으로 나뉘어 시계 동작 1개를 사용합니다.
VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram is
port(
clk : in std_logic;
wea : in std_logic;
addra : in std_logic_vector(5 downto 0);
addrb : in std_logic_vector(5 downto 0);
dina : in std_logic_vector(7 downto 0);
doutb : out std_logic_vector(7 downto 0)
);
end ram;
architecture rtl of ram is
type mem_type is array (63 downto 0) of std_logic_vector(7 downto 0);
signal mem : mem_type;
begin
process(clk)
begin
if (clk'event and clk = '1') then
if (wea = '1') then
mem(conv_integer(addra)) <= dina;
end if;
doutb <= mem(conv_integer(addrb));
end if;
end process;
end rtl;
verilogmodule ram
(
input wire clk,
input wire wea,
input wire [5:0] addra,
input wire [5:0] addrb,
input wire [7:0] dina,
output reg [7:0] doutb
);
reg [7:0] mem [63:0];
always @(posedge clk) begin
if (wea) begin
mem[addra] <= dina;
end
doutb <= mem[addrb];
end
endmodule
예3
이것은 양쪽의 다른 시계로 읽을 수 있는 이중 포트 램의 예이다.2곳에서 Mem을 업데이트했기 때문에 시뮬레이션할 때 Warning이 있을 수 있지만 논리적 합성이 가능하다고 생각합니다.
VHDL
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity ram is
port(
clka : in std_logic;
clkb : in std_logic;
wea : in std_logic;
web : in std_logic;
addra : in std_logic_vector(5 downto 0);
addrb : in std_logic_vector(5 downto 0);
dina : in std_logic_vector(7 downto 0);
dinb : in std_logic_vector(7 downto 0);
douta : out std_logic_vector(7 downto 0);
doutb : out std_logic_vector(7 downto 0)
);
end ram;
architecture rtl of ram is
type ram_type is array (63 downto 0) of std_logic_vector(7 downto 0);
shared variable mem : ram_type;
begin
process(clka)
begin
if (clka'event and clka = '1') then
if wea = '1' then
mem(conv_integer(ADDRA)) := dina;
end if;
douta <= mem(conv_integer(ADDRA));
end if;
end process;
process(clkb)
begin
if (clkb'event and clkb = '1') then
if (web = '1') then
mem(conv_integer(ADDRB)) := dinb;
end if;
doutb <= mem(conv_integer(ADDRB));
end if;
end process;
end rtl;
verilogmodule ram
(
input wire clka,
input wire clkb,
input wire wea,
input wire web,
input wire [5:0] addra,
input wire [5:0] addrb,
input wire [7:0] dina,
input wire [7:0] dinb,
output reg [7:0] douta,
output reg [7:0] doutb
);
reg [7:0] mem [63:0];
always @(posedge clka) begin
if (wea) begin
mem[addra] <= dina;
end
douta <= mem[addra];
end
always @(posedge clkb) begin
if (web) begin
mem[addrb] <= dinb;
end
doutb <= mem[addrb];
end
endmodule
상기 예에서 비트의 폭은 고정되어 있지만 주소와 데이터의 비트의 폭을 매개 변수화하면 곳곳에서 사용하기 쉬우므로 적당히 조정하십시오.
Reference
이 문제에 관하여(빈도가 높은 부품에 대한 HDL 설명 예제 - 내부 RAM -), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/sk6labo/articles/291e1da7c91041텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)