VHDL 如何在一段时间后将输出从 1 切换为 0?
VHDL How to switch output from 1 to 0 after a period of time?
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;
因此,该代码适用于线跟随器,如果它从其中一个传感器读取“1”,它应该将“1”(即 5v.)传递到它的一个轮子。从 "sensorDisp" 读取“1”后,汽车应该停下来一会儿,此时 "disp" 的值为“1”。在那之后,它应该继续它的快乐之路。我很难实现这种延迟。感谢您的帮助!
我在Atlys上做过类似的事情。
在 .ucf 文件(映射文件)中有 clk counters.Know 时钟的频率。
有一个等待状态的布尔值,isWait。当 sensorDisp 为 1 时,isWait = true
我在下面提到了伪代码。
您可以使用输入 clk 和 sensordisp 为此创建一个单独的进程。
请记住,如果任何 variable/signal 未在代码的任何 运行 中分配任何值,if 将推断一个锁存器,因为它需要先前的值,因为它未分配。
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;
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;
因此,该代码适用于线跟随器,如果它从其中一个传感器读取“1”,它应该将“1”(即 5v.)传递到它的一个轮子。从 "sensorDisp" 读取“1”后,汽车应该停下来一会儿,此时 "disp" 的值为“1”。在那之后,它应该继续它的快乐之路。我很难实现这种延迟。感谢您的帮助!
我在Atlys上做过类似的事情。 在 .ucf 文件(映射文件)中有 clk counters.Know 时钟的频率。 有一个等待状态的布尔值,isWait。当 sensorDisp 为 1 时,isWait = true 我在下面提到了伪代码。
您可以使用输入 clk 和 sensordisp 为此创建一个单独的进程。 请记住,如果任何 variable/signal 未在代码的任何 运行 中分配任何值,if 将推断一个锁存器,因为它需要先前的值,因为它未分配。
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;