我在VHDL中有这段代码。我想要的是在sw'event和之后崛起,第一个是自己堕落。但是当我模拟这个时,第一次永远不会倒下!
process(rst,clk,sw)
begin
if (clk'EVENT and clk='1') then
if (rst='1') then
rst<='0';
elsif (sw'event) then
rst<='1';
elsif (my_counter="11") then
deb_sw<=sw;
end if;
end if;
end process;
答案 0 :(得分:1)
这是因为信号通常由另一个正在执行clk'event的进程驱动,因此信号将在 clk事件之后更新。
如果要检测sw何时从“0”变为“1”(反之亦然),则必须跟踪其先前的值:
if sw /= last_sw then
-- do what you need to do when it changes
end if;
last_sw := sw;
答案 1 :(得分:0)
最后我像这样解决了它
process(rst,clk,sw)
begin
if (clk'EVENT and clk='1') then
if (rst='1' and rst'last_value='0') then
rst<='0';
elsif (sw='1') then
rst<='1';
deb_sw<=sw;
elsif (my_counter="1010") then -- clock cycles=10*f
deb_sw<=sw;
end if;
end if;
end process;