简体   繁体   English

带 D 触发器的结构 4 位环形计数器。 VHDL / GHDL

[英]Structural 4 bit ring counter with D flip flop. VHDL / GHDL

I don't know how to do this with structural programming...我不知道如何用结构化编程来做到这一点......

"A binary counter (with reset signal) of 4 bits made of 4 D flip flops." “一个由 4 个 D 触发器组成的 4 位二进制计数器(带有复位信号)。”

How to connect in/outs?如何连接输入/输出?

Here is the entity declarations.这是实体声明。 The core of the problem is at the last lines.问题的核心在最后几行。

                    --FFD
            entity FFD is
            port( CLK, D, reset : in STD_LOGIC;
                Q : out STD_LOGIC
               );
            end FFD;
            
            architecture behaviour of FFD is
            begin
                process(CLK, reset)
                begin
                if reset='1' then Q<='0';  
                elsif (clk'event and clk='1') then Q<=D;
                else null;
                end if;
                end process;
            end behaviour;
        ----------------------------------------------------------  
            
        --counter

        library IEEE;
        use IEEE.std_logic_1164.all;
        use IEEE.numeric_std.all;

            entity counter is
            port(clk : in std_logic;
               reset : in std_logic;
               count : out std_logic_vector(3 downto 0));
            end entity counter;

                architecture rtl of counter is
            
            --
            component FFD 
            port (CLK, D, reset : in STD_LOGIC;
                       Q : out STD_LOGIC);
            end component;
            
            signal q0,q1,q2: std_logic:='0';
            signal q3: std_logic:='1';
            
            begin
            -- 

            ---
            inst1: FFD port map (CLK=>clk, D=>q3, reset=>reset, Q=>q0);
            inst2: FFD port map (CLK=>clk, D=>q0, reset=>reset, Q=>q1);
            inst3: FFD port map (CLK=>clk, D=>q1, reset=>reset, Q=>q2);
            inst4: FFD port map (CLK=>clk, D=>q2, reset=>reset, Q=>q3);
            inst5: count<=q3&q2&q1&q0;
            end architecture rtl;

My problem is in this last lines.我的问题是在这最后几行。

There's no issue with your connections (they correctly form a ring counter), but you're not going to see much happen.你的连接没有问题(它们正确地形成了一个环形计数器),但你不会看到很多事情发生。 After reset, all of your flip-flops contain zero, which will get circulated around the ring with each clock pulse but never actually cause a change in the outputs.复位后,所有触发器都包含零,它会随着每个时钟脉冲在环上循环,但实际上不会导致输出发生变化。 The assignment of a default value of '1' for q3 when you declare the signal will be overridden by the actual output of the flip-flop as soon as your circuit starts operating (or simulating), and is generally the wrong way to initialize hardware.一旦您的电路开始运行(或模拟),当您声明信号时,为 q3 分配默认值“1”将被触发器的实际输出覆盖,并且通常是初始化硬件的错误方法.

You need to insure that when you assert the reset signal, your hardware transitions into an appropriate state (ie: one bit set, all others clear).您需要确保当您断言复位信号时,您的硬件会转换到适当的状态(即:设置一位,所有其他人都清除)。 One way to do this would be to use a FF with a set input for Q3.一种方法是使用带有 Q3 设置输入的 FF。 If you don't have a flip flop that with a set (instead of a reset) signal, you can simulate one by putting inverters on the input and output, which will provide a '1' to be clocked around your ring counter when you apply reset.如果您没有带有设置(而不是复位)信号的触发器,您可以通过在输入和输出端放置反相器来模拟一个触发器,当您应用重置。 You could also create some intermediate signals and craft a multiplexer for the D inputs to build a loadable counter, or any of a variety of other solutions...您还可以创建一些中间信号并为 D 输入制作多路复用器以构建可加载计数器,或任何其他解决方案...

I think the problem is somewhere else.我认为问题出在其他地方。

I think your D flip flop output Q should have port direction as inout(or buffer) and not out.我认为您的 D 触发器输出 Q 的端口方向应该为 inout(或缓冲区)而不是 out。 This is because the output is also acting as input.这是因为输出也充当输入。 i think this must be carefully watched while doing structural modeling.我认为在进行结构建模时必须仔细观察这一点。

port (CLK, D, reset : in STD_LOGIC; Q : inout STD_LOGIC);端口 (CLK, D, reset : in STD_LOGIC; Q : inout STD_LOGIC);

but please check i am not sure,但请检查我不确定,

johnson counter is also ring counter, see this VHDL code for Johnson Counter which is using structural modeling style 约翰逊计数器也是环形计数器,请参阅使用结构建模风格的约翰逊计数器的 VHDL 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM