"if" 块是否有可能超出 vhdl 中的给定选择?
is there any possibility for "if" block to go out of given choices in vhdl?
下面是使用IF块的VHDL代码。
在最后的"elsif"中,"my_choice"的值赋给了"ch4"。然后 "else" 块被执行,因为没有条件被满足。但是,"my_choice" 是否有可能获得除 (ch1,ch2,ch3,ch4) 之外的其他值,例如高阻抗(或其他任何值)?如果是这样,我该如何避免呢?由于这个赋值可以改变代码的操作。
entity entity_name
port
.....
.....
end entity_name;
architecture bhvr of entity_name
type choices is (ch1, ch2, ch3, ch4);
signal my_choice,next_choice : choices;
begin
process(clk, reset)
begin
if reset='1' tehn
--------reset
else
my_choice<=next_choice;
end if;
end process;
process(my_choice)
begin
if my_choice = ch1 then
next_choice <= ch2;
elsif my_choice = ch2 then
next_choice <= ch3;
elsif my_choice = ch3 then
next_choice <= ch4;
else ------------------------------------coming to ch4
---- task for ch4
end process;
end architecture;
由于my_choice
是类型choices
,是枚举类型,值为'ch1'、'ch2'、'ch3'、'ch4',那么my_choice
将始终具有这 4 个值之一,至少在模拟中是这样。
在硬件中,可用值 space 取决于实现,例如,值是单热的还是二进制的。启动后,重置是确保该值明确定义为 4 个值之一的好方法,如果电路随后符合时序要求,则该值将保持在定义值 space 的 4 个值。
下面是使用IF块的VHDL代码。 在最后的"elsif"中,"my_choice"的值赋给了"ch4"。然后 "else" 块被执行,因为没有条件被满足。但是,"my_choice" 是否有可能获得除 (ch1,ch2,ch3,ch4) 之外的其他值,例如高阻抗(或其他任何值)?如果是这样,我该如何避免呢?由于这个赋值可以改变代码的操作。
entity entity_name
port
.....
.....
end entity_name;
architecture bhvr of entity_name
type choices is (ch1, ch2, ch3, ch4);
signal my_choice,next_choice : choices;
begin
process(clk, reset)
begin
if reset='1' tehn
--------reset
else
my_choice<=next_choice;
end if;
end process;
process(my_choice)
begin
if my_choice = ch1 then
next_choice <= ch2;
elsif my_choice = ch2 then
next_choice <= ch3;
elsif my_choice = ch3 then
next_choice <= ch4;
else ------------------------------------coming to ch4
---- task for ch4
end process;
end architecture;
由于my_choice
是类型choices
,是枚举类型,值为'ch1'、'ch2'、'ch3'、'ch4',那么my_choice
将始终具有这 4 个值之一,至少在模拟中是这样。
在硬件中,可用值 space 取决于实现,例如,值是单热的还是二进制的。启动后,重置是确保该值明确定义为 4 个值之一的好方法,如果电路随后符合时序要求,则该值将保持在定义值 space 的 4 个值。