Select VHDL:具有多值选择功能
我有以下代码(它对按下的按钮进行编码):Select VHDL:具有多值选择功能,select,vhdl,Select,Vhdl,我有以下代码(它对按下的按钮进行编码): 不使用select,您可以使用以下用例: my_process_name : process(buttons) begin case buttons is when x"1" => error <= '0'; code <= "00"; when x"2" => error <= '0'; code <= "01"; when x"4" =
不使用select,您可以使用以下用例:
my_process_name : process(buttons)
begin
case buttons is
when x"1" =>
error <= '0';
code <= "00";
when x"2" =>
error <= '0';
code <= "01";
when x"4" =>
error <= '0';
code <= "10";
when x"8" =>
error <= '0';
code <= "11";
when others =>
error <= '1';
code <= "00";
end case;
end process;
my_进程\u名称:进程(按钮)
开始
箱子按钮是
当x“1”=>
错误或者您可以将其写成两个单独的with/when语句:
with buttons select
error <= '0' when x"1",
'0' when x"2",
'0' when x"4",
'0' when x"8",
'1' when others;
with buttons select
code <= "00" when x"1",
"01" when x"2",
"10" when x"4",
"11" when x"8",
"00" when others;
使用按钮选择
错误它只在进程中工作:您不想把它放在进程中有什么特别的原因吗?我只是在学习VHDL,我在寻找最简单、最优雅的解决方案。如果我把组合代码放在一个进程中,会有语义上的区别吗?编辑以显示进程中的组合代码。通常在process()的括号内,您会将信号添加到灵敏度列表中,即组合逻辑的输入或时钟和重置的顺序。灵敏度列表通常不需要用于合成,但对于模拟,它告诉模拟器仅当灵敏度列表中的信号发生变化时才查看此过程。如果你只是把它放在架构中,我相信模拟器每一次都会评估这一行。
my_process_name : process(buttons)
begin
case buttons is
when x"1" =>
error <= '0';
code <= "00";
when x"2" =>
error <= '0';
code <= "01";
when x"4" =>
error <= '0';
code <= "10";
when x"8" =>
error <= '0';
code <= "11";
when others =>
error <= '1';
code <= "00";
end case;
end process;
with buttons select
error <= '0' when x"1",
'0' when x"2",
'0' when x"4",
'0' when x"8",
'1' when others;
with buttons select
code <= "00" when x"1",
"01" when x"2",
"10" when x"4",
"11" when x"8",
"00" when others;
error <= '0' when (buttons = X"1" or buttons = X"2" buttons = X"4" buttons = X"8") else '1';
code <= "00" when buttons = X"1" else "01" when buttons = X"2" else "10" when buttons = X"4" else "11" when buttons = X"8" else "00";