VHDL中的中断处理
我们在项目中使用OR1200,我们希望为FPGA板的第8个按钮分配一个中断。以下是生成中断的代码:VHDL中的中断处理,vhdl,opencore,Vhdl,Opencore,我们在项目中使用OR1200,我们希望为FPGA板的第8个按钮分配一个中断。以下是生成中断的代码: inrpt: process(CLK_I, RST_I) begin if RST_I = '1' then butt_int_pul <= '0'; butt_int_tmp <= '0'; elsif rising_edge(CLK_I) then if(DATA_I(8) = '1' and
inrpt: process(CLK_I, RST_I)
begin
if RST_I = '1' then
butt_int_pul <= '0';
butt_int_tmp <= '0';
elsif rising_edge(CLK_I) then
if(DATA_I(8) = '1' and butt_int_tmp = '0') then
butt_int_pul <= '1';
else
butt_int_pul <= '0';
end if;
butt_int_tmp <= DATA_I(8);
end if;
end process inrpt;
process(CLK_I, RST_I)
begin
if RST_I = '1' then
butt_int <= '0';
elsif butt_int_pul = '1' then
butt_int <= '1';
elsif clear_int = '1' then
butt_int <= '0';
end if;
end process;
inrpt:过程(CLK_I,RST_I)
开始
如果RST_I='1',则
首先,第二个过程没有正确编写。它应该具有与第一个进程等效的结构(即,if(上升沿(CLK_i))
围绕除重置逻辑之外的所有进程)。您当前描述的闩锁具有多个启用信号和错误的灵敏度列表
接下来,你根本没有理由需要第二个过程。您只需要一个寄存器作为中断(butt\u int
),一个寄存器跟踪按钮的上一个状态(butt\u prev
)。当数据I(8)
为'1'
而butt\u prev
为'0'
(即按钮从未按下变为按下)时,中断被触发一个周期
过程(CLK\u I,RST\u I)开始
如果(RST_I='1'),则
但是,最好不要考虑中断。当您以FPGA为目标时,您所描述的是数字逻辑,而不是软件处理器
有很多方法可以建立一个具有你想要的行为的电路。
最简单的可能是重新计时的锁存器
signal latched_button : std_logic;
signal meta_chain : std_logic_vector(2 downto 0);
p_async_latch: process(rst_i,data(8))
begin
if rst_i = '1' then
latched_button <= '0';
elsif data(8) = '1' then
latched_button <= '1';
end if;
end process;
p_meta_chain: process(rst_i,clk_i)
begin
if rst_i = '1' then
meta_chain <= (others => '0');
elsif rising_edge(clk_i) then
meta_chain <= meta_chain(1 downto 0) & latched_button;
end if;
end process;
button_int <= '1' when meta_chain(2 downto 1) = "01" else '0';
信号锁存按钮:标准逻辑;
信号元链:标准逻辑向量(2到0);
p_异步锁存器:进程(rst_i,数据(8))
开始
如果rst_i='1',则
锁定按钮我尝试了两种解决方案,但仍然不稳定。我需要做非常短和快速的按压才能使它工作。@www你使用的时钟频率是多少?考虑到典型的时钟频率为几至数百MHz,您执行的任何物理操作都是“长的”(约100000个时钟周期),您按下按钮的速度应该不会有什么不同。你确定你的钮扣没扣吗?按钮是否处于低激活状态(即按下按钮时信号为0)?
signal latched_button : std_logic;
signal meta_chain : std_logic_vector(2 downto 0);
p_async_latch: process(rst_i,data(8))
begin
if rst_i = '1' then
latched_button <= '0';
elsif data(8) = '1' then
latched_button <= '1';
end if;
end process;
p_meta_chain: process(rst_i,clk_i)
begin
if rst_i = '1' then
meta_chain <= (others => '0');
elsif rising_edge(clk_i) then
meta_chain <= meta_chain(1 downto 0) & latched_button;
end if;
end process;
button_int <= '1' when meta_chain(2 downto 1) = "01" else '0';