【问题标题】:change signal inside a process with if statement - VHDL使用 if 语句更改进程内的信号 - VHDL
【发布时间】:2013-12-08 22:51:48
【问题描述】:

我有这个 VHDL 代码。我想要的是在 sw'event 时首先上升,然后,首先是自行下降。但是当我模拟这个时,rst 永远不会下降!

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;

【问题讨论】:

  • 此代码是否也可用于 FPGA(综合代码),还是仅用于仿真(测试台)?

标签: vhdl


【解决方案1】:

sw'event 不太可能与 clk'event 完全相同。

这是因为信号通常由另一个也在执行 clk' 事件的进程驱动,因此信号将在 clk 事件之后更新。

如果要检测 sw 何时从 '0' 变为 '1'(反之亦然),则必须跟踪其先前的值:

if sw /= last_sw then
  -- do what you need to do when it changes
end if;
last_sw := sw;

【讨论】:

    【解决方案2】:

    我终于这样解决了

    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;    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多