VHDL如何在一段时间后将输出从1切换到0?

时间:2018-06-06 00:25:19

标签: vhdl

entity seguidor is
    port(
        clk, sensorIzq, sensorDer, sensorDisp : in std_logic;
        llantaIzq, llantaDer, disp: out std_logic);
end;

architecture comportamiento of seguidor is

begin

    movimiento: process (sensorIzq, sensorDer, sensorDisp,clk)
     begin
        if(sensorIzq='1' and sensorDer='0' and sensorDisp = '0') then
            llantaIzq<='1';
            llantaDer<='0';
        elsif(sensorIzq='0' and sensorDer='1'and sensorDisp = '0') then
            llantaIzq<='0';
            llantaDer<='1';
        elsif(sensorIzq = '1' and sensorDer = '1' and sensorDisp = '0') then
            llantaIzq <= '1';
            llantaDer <= '1';
        elsif(sensorIzq = '1' and sensorDer = '1' and sensorDisp = '1') then
            llantaIzq <= '0';
            llantaDer <= '0';

        end if;
    end process movimiento;
    end comportamiento;

因此,代码适用于行跟随者,如果它读取&#39; 1&#39;从其中一个传感器,它应该通过&#39; 1&#39; (即5v。)其中一个轮子。阅读&#39; 1&#39;来自&#34; sensorDisp&#34;,汽车应停一会儿,给出#34; disp&#34;价值为&#39; 1&#39;在此期间。在那之后,它应该继续它的快乐方式。我很难尝试实现这种延迟。谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我在Atlys做过类似的事情。 有clk counter.Know .ucf文件(映射文件)中的时钟频率。 有等待状态的布尔值,isWait。当sensorDisp为1时,则isWait = true 我在下面提到了伪代码。

您可以使用输入clk和sensordisp为此创建单独的进程。 并且记住,如果在任何代码运行中没有为任何变量/信号分配任何值,如果将推断锁存器,因为它需要先前的值,因为它未被分配。

movimiento: process (clk,sensorIzq, sensorDer, sensorDisp,clk)
     begin
     if(clk edge ) then 
        if (isWait) then 
            if(wait_counter < "frequency")) then 
              wait_couter++;
             else 
              isWait = False;
              Disp = '0';
            end if;
        else 
          if(sensorDisp = '1') then 
             wait_counter = 0;
             isWait = True;
              Disp <= '1';
          end if;

          if(sensorIzq='1' and sensorDer='0' and sensorDisp = '0') then
              llantaIzq<='1';
              llantaDer<='0';
          elsif(sensorIzq='0' and sensorDer='1'and sensorDisp = '0') then
              llantaIzq<='0';
              llantaDer<='1';
          elsif(sensorIzq = '1' and sensorDer = '1' and sensorDisp = '0') then
              llantaIzq <= '1';
              llantaDer <= '1';
          elsif(sensorIzq = '1' and sensorDer = '1' and sensorDisp = '1') then
              llantaIzq <= '0';
              llantaDer <= '0';
          end if;
      end if;
    end if;
    end process movimiento;
    end comportamiento;