未知原因未初始化的信号值

问题描述 投票:0回答:1

我尝试在主模块下使用 3 个相同类型的组件,但显示的输出值未初始化。似乎我编写的代码以某种方式强制执行某些与我想要的逻辑相矛盾的值。

问题出在 CLR 信号上。当所有计数器值与

TOP_COUNT
输入具有相同数字时,应该重置计数器值(下面屏幕截图中测试台中的值 2)。

组件:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity counter is
    Port ( EN : in STD_LOGIC;
           CLR : INOUT STD_LOGIC :='0'; -- WAS BUFFER
           clk_5 : in STD_LOGIC;
           RST : in STD_LOGIC;
           TOP_COUNT : in STD_LOGIC_VECTOR (3 downto 0);
           TOP_CNT_REACH : out STD_LOGIC;
           REACH_9 : out STD_LOGIC;
           Q : inout integer range 0 to 9); -- was buffer
end counter;

architecture Behavioral of counter is

signal top_cnt: integer range 0 to 9;
signal temp_CLR: std_logic:='0';

begin
top_cnt <= to_integer(unsigned(TOP_COUNT));

process (clk_5)
begin
    if rising_edge(clk_5) then
        if RST = '1' or CLR = '1' OR temp_CLR = '1' then  -- CLR should rise for 1 clk_5 cycle
            Q <= 0;
        elsif EN = '1' then
           Q <= Q + 1;
        end if;
    end if;
end process;         


OUTPUT_UPDATES:            
process(Q, top_cnt)
begin
    if Q = top_cnt then
        TOP_CNT_REACH <= '1';
    else
        TOP_CNT_REACH <= '0';        
    end if;
    
    if Q = 9 then
        REACH_9 <= '1';
        temp_CLR <= '1'; 
    else 
        REACH_9 <= '0';
        temp_CLR <= '0';
    end if;         
end process;

使用组件的逻辑部分:

LSD: counter port map (en=>en(0), clr =>clr(0), clk_5=>clk5, rst=>reset, top_count=>top_count, 
                       top_cnt_reach=>top_cnt_reach(0), reach_9=>reach_9(0), Q=>Q0);
ISD: counter port map (en=>en(1), clr =>clr(1), clk_5=>clk5, rst=>reset, top_count=>top_count, 
                       top_cnt_reach=>top_cnt_reach(1), reach_9=>reach_9(1), Q=>Q1);  
MSD: counter port map (en=>en(2), clr =>clr(2), clk_5=>clk5, rst=>reset, top_count=>top_count, 
                       top_cnt_reach=>top_cnt_reach(2), reach_9=>reach_9(2), Q=>Q2); 

LSD_LOGIC:
EN(0) <= '1';
process(clk5) -- REACH_9(0)
begin
    if clk5 = '1' then
        if REACH_9(0) = '1' then
            CLR(0) <= '1';
            EN(1) <= '1';    
        else 
            CLR(0) <= '0'; 
            EN(1) <= '0';   
        end if;  
    end if;     
end process;

ISD_LOGIC:
process(clk5)  -- REACH_9(1)
begin
    if clk5='1' then
        if REACH_9(1) = '1' then
            CLR(1) <= '1';
            EN(2) <= '1';    
        else 
            CLR(1) <= '0';
            EN(2) <= '0';    
        end if;  
     end if;      
end process;

MSD_LOGIC:
process(clk5) -- TOP_CNT_REACH(0)
begin
    if clk5 = '1' then
        if (top_cnt_reach = "111") then
            clr <= "111"; -- clr(2) <= '1';
        else
            clr(2) <= '0';    
        end if;
    end if;        
end process;

模拟结果:

enter image description here

我还用一个组件的测试台测试了该组件,结果很好。但是当我将主模块下的 3 个组件组合在一起时,出现了问题。

vhdl uninitialized-constant
1个回答
0
投票

TLDR:您的信号 CLR(2 到 0)上有多个驱动程序。

将您执行的每个独立分配视为硬件门的输出 - 在 VHDL 中,我们也将其称为驱动程序。

在下面的块中,您将在 if 分支的第一部分中驱动 CLR 的所有元素:

MSD_LOGIC:
process(clk5) -- TOP_CNT_REACH(0)
begin
    if clk5 = '1' then
        if (top_cnt_reach = "111") then
            clr <= "111"; -- clr(2) <= '1';
        else
            clr(2) <= '0';    
        end if;
    end if;        
end process;

您的每个组件都将 CLR 作为输入输出,其值初始化为“0”,因此它们将驱动“0”。 相反,您仅使用它作为输入,因此将其设为 IN。

entity counter is
    Port ( EN : in STD_LOGIC;
           CLR : in STD_LOGIC :='0'; -- WAS BUFFER
© www.soinside.com 2019 - 2024. All rights reserved.