如何 "sample" VHDL 中的一个值?
How to "sample" a value in VHDL?
所以我有一个从 1 到 15 的模计数器,然后在一个单独的实体中不断循环。我想,在依赖于某些输出的 case 语句中,在时钟的 rising_edge 上对该值进行采样,但只执行一次,否则该值将不断变化。有没有办法做到这一点?分配信号并使其保持静态?
我已经发布了一些代码,希望它们能更好地展示我想说的内容。
process(all)
begin --sensitivity list?
if(reset) then
playerCards <= "0000000000000000";
dealerCards <= "0000000000000000";
elsif rising_edge(clock) then
case? deal & dealTo & dealToCardSlot is
when "1100" =>
playerCards(3 downto 0) <= singleCard;
playerCards(15 downto 4) <= (others => '0');
when "1101" =>
playerCards(7 downto 4) <= singleCard;
playerCards(15 downto 8) <= (others => '0');
when "1110" =>
playerCards(11 downto 8) <= singleCard;
playerCards(15 downto 12) <= (others => '0');
when "1111" =>
playerCards(15 downto 12) <= singleCard;
when "1000" =>
dealerCards(3 downto 0) <= singleCard; --dcard1
dealerCards( 15 downto 4) <= (others => '0');
when "1001" =>
dealerCards(7 downto 4) <= singleCard; --dcard2
dealerCards( 15 downto 8) <= (others => '0');
when "1010" =>
dealerCards(11 downto 8) <= singleCard; --dcard3
dealerCards( 15 downto 12) <= (others => '0');
when "1011" =>
dealerCards(15 downto 12) <= singleCard; --dcard4
when "0--0" => null; --do nothing when in win/end
when others => --this covers the start case --sets cards to 0
playerCards <= "0000000000000000";
dealerCards <= "0000000000000000";
end case?;
end if;
end process;
这里我将 singleCard 链接到我的计数器的输出,它在每个时钟边沿递增。所以基本上我希望我的案例陈述只更新一次 playerCards 的值,然后停止。
感谢您的帮助。
是的,您需要一个额外的内部信号来控制您的操作模式:更新和非更新.
它实际上是一种反馈信号。您根据输入条件生成它,然后您还可以在输入上使用它来修改行为。
你的需求可以表述为:流程可以有两种状态——采样,或者不采样,当你采样的时候过渡到不采样。
所以你可以用一个状态变量来做到这一点,在这种情况下它可以是一个布尔值——这会将你的进程变成一个状态机。正如另一个答案所说,您可以在此处使用信号而不是变量,但这会破坏封装,使进程内部工作可见。
有些人会坚持将状态机分成另外两个(甚至 3 个)进程,但我认为单个进程形式要小得多并且更容易理解。
process(reset,clock) -- original sens list is incorrect for a clocked process
variable sampling : boolean;
begin
if(reset) then
sampling <= true;
-- other reset actions
elsif rising_edge(clock) then
if sampling then -- add conditions here, or it'll sample on the first clock.
sampling := false;
case ... -- sampling process and program logic
end case;
else
-- if you need to turn sampling back on, set "sampling" here
end if;
end if;
end process;
所以我有一个从 1 到 15 的模计数器,然后在一个单独的实体中不断循环。我想,在依赖于某些输出的 case 语句中,在时钟的 rising_edge 上对该值进行采样,但只执行一次,否则该值将不断变化。有没有办法做到这一点?分配信号并使其保持静态? 我已经发布了一些代码,希望它们能更好地展示我想说的内容。
process(all)
begin --sensitivity list?
if(reset) then
playerCards <= "0000000000000000";
dealerCards <= "0000000000000000";
elsif rising_edge(clock) then
case? deal & dealTo & dealToCardSlot is
when "1100" =>
playerCards(3 downto 0) <= singleCard;
playerCards(15 downto 4) <= (others => '0');
when "1101" =>
playerCards(7 downto 4) <= singleCard;
playerCards(15 downto 8) <= (others => '0');
when "1110" =>
playerCards(11 downto 8) <= singleCard;
playerCards(15 downto 12) <= (others => '0');
when "1111" =>
playerCards(15 downto 12) <= singleCard;
when "1000" =>
dealerCards(3 downto 0) <= singleCard; --dcard1
dealerCards( 15 downto 4) <= (others => '0');
when "1001" =>
dealerCards(7 downto 4) <= singleCard; --dcard2
dealerCards( 15 downto 8) <= (others => '0');
when "1010" =>
dealerCards(11 downto 8) <= singleCard; --dcard3
dealerCards( 15 downto 12) <= (others => '0');
when "1011" =>
dealerCards(15 downto 12) <= singleCard; --dcard4
when "0--0" => null; --do nothing when in win/end
when others => --this covers the start case --sets cards to 0
playerCards <= "0000000000000000";
dealerCards <= "0000000000000000";
end case?;
end if;
end process;
这里我将 singleCard 链接到我的计数器的输出,它在每个时钟边沿递增。所以基本上我希望我的案例陈述只更新一次 playerCards 的值,然后停止。 感谢您的帮助。
是的,您需要一个额外的内部信号来控制您的操作模式:更新和非更新.
它实际上是一种反馈信号。您根据输入条件生成它,然后您还可以在输入上使用它来修改行为。
你的需求可以表述为:流程可以有两种状态——采样,或者不采样,当你采样的时候过渡到不采样。
所以你可以用一个状态变量来做到这一点,在这种情况下它可以是一个布尔值——这会将你的进程变成一个状态机。正如另一个答案所说,您可以在此处使用信号而不是变量,但这会破坏封装,使进程内部工作可见。
有些人会坚持将状态机分成另外两个(甚至 3 个)进程,但我认为单个进程形式要小得多并且更容易理解。
process(reset,clock) -- original sens list is incorrect for a clocked process
variable sampling : boolean;
begin
if(reset) then
sampling <= true;
-- other reset actions
elsif rising_edge(clock) then
if sampling then -- add conditions here, or it'll sample on the first clock.
sampling := false;
case ... -- sampling process and program logic
end case;
else
-- if you need to turn sampling back on, set "sampling" here
end if;
end if;
end process;