我在做一个简单的钟分频器。在测试时,我注意到一个if语句从未被执行。知道为什么吗?如果计数>3,则为语句。Modelsim给出了计数器整数(4、5、6等)的正确值,但永远不会进入if语句。
------------------------------------------------
-------- CLOCK DIVIDER
------------------------------------------------
entity clock_divider is
port ( clk,reset: in std_logic;
clock_out: out std_logic);
end clock_divider;
architecture bhv of clock_divider is
signal tmp : std_logic:='0';
begin
process(clk,reset,tmp)
variable count: integer:=1;
begin
if(reset='1') then
count := 0;
tmp <= '0';
elsif rising_edge(clk) then
count := count + 1;
if count > 3 then
tmp <= not(tmp);
count := 0;
end if;
end if;
clock_out <= tmp;
end process;
end bhv;发布于 2022-10-05 09:35:03
这是因为您为count使用了一个变量。应该是个信号。
每次在仿真中执行该过程时,count都将被设置为1。
变量有时被错误地视为“本地信号”,就像软件中的局部变量,而它们不是。使用这样的变量的设计在模拟过程中将与编译器在综合过程中产生的内容不同。编译器会将变量提升到信号,但隐藏起来,并在其他警告中给出警告。
相反,为count使用一个信号。硬件描述语言的设计实际上必须暗示实际的电路,这是用于count的DFF。
变量在可综合设计的时钟过程中是有用的,用于(a)重塑信号值,例如形成总线,或(b)沿着组合树命名节点。它们不是用来暗示DFF的。
https://stackoverflow.com/questions/73946859
复制相似问题