FPGA 三态输入与输出
时间:10-02
整理:3721RD
点击:
ENTITY Test_FPGA Is
port(
sys_clk : instd_logic;
addr: instd_logic_vector(4downto 0);
data: inoutstd_logic_vector(15 downto 0);
cs: instd_logic;
wr: instd_logic;
Pin1: out std_logic;
Pin2: out std_logic
);
--Register Address
CONSTANT CTRL_WORD_ADDR: std_logic_vector(4 downto 0) := "00100";
End Test_FPGA;
Architecture bhv of Test_FPGA is
signal reg: std_logic_vector(15 downto 0);
begin
process(wr)
begin
if (cs='0') then
elsif wr'event and wr='1' then--posedge
if (addr=CTRL_WORD_ADDR) then
reg<=data;
end if;
end if;
end process;
process(rd)
begin
if (cs='0') then
elsif rd'event and rd='1' then--posedge
if (addr=CTRL_WORD_ADDR) then
data<=reg;
end if;
end if;
end process;
process(reg)
begin
Pin1<=reg(0);
Pin2<=reg(1);
end process;
End bhv;
data 为三态信号,如何定义它的三态状态?高手指教!
port(
sys_clk : instd_logic;
addr: instd_logic_vector(4downto 0);
data: inoutstd_logic_vector(15 downto 0);
cs: instd_logic;
wr: instd_logic;
Pin1: out std_logic;
Pin2: out std_logic
);
--Register Address
CONSTANT CTRL_WORD_ADDR: std_logic_vector(4 downto 0) := "00100";
End Test_FPGA;
Architecture bhv of Test_FPGA is
signal reg: std_logic_vector(15 downto 0);
begin
process(wr)
begin
if (cs='0') then
elsif wr'event and wr='1' then--posedge
if (addr=CTRL_WORD_ADDR) then
reg<=data;
end if;
end if;
end process;
process(rd)
begin
if (cs='0') then
elsif rd'event and rd='1' then--posedge
if (addr=CTRL_WORD_ADDR) then
data<=reg;
end if;
end if;
end process;
process(reg)
begin
Pin1<=reg(0);
Pin2<=reg(1);
end process;
End bhv;
data 为三态信号,如何定义它的三态状态?高手指教!
FPGA 三态输入与输出
process(rd)
begin
if (cs='0') then
elsif rd'event and rd='1' then--posedge
if (addr=CTRL_WORD_ADDR) then
data<=reg;
end if;
else data <= 'Z';--还请高手来回答吧
end if;
end process;
FPGA 三态输入与输出
我觉得做成同步接口比异步好,你现在的程序可能会生成latch,用上sys_clk吧。
三态用法:定义两个signal datain 和 dataout
两个process 里面分别改为:
reg<=datain;
dataout<=reg;
process外加上
datain<=data;
dataout<= dataout when cs='0' and rd='1' else
(others=>'Z');
FPGA 三态输入与输出
生成latch是什么意思?有害吗?
FPGA 三态输入与输出
latch就是锁存器,电平触发,而不是寄存器的边沿触发,害处在于初始状态不定,分析很困难,所以一般都禁止生成latch。
FPGA 三态输入与输出
verilog里有这样写的,你可以参考一下,也是定义成两个变量
assign io = oen ? o : 1'bz;
assign i= oen ? 1'bz : io;
FPGA 三态输入与输出
谢谢指教