带 D 触发器的结构 4 位环形计数器。 VHDL / GHDL
我不知道如何用结构编程来做到这一点......
“由 4 个 D 触发器组成的 4 位二进制计数器(带有复位信号)。”
如何连接输入/输出?
这是实体声明。问题的核心在于最后几行。
--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;
我的问题出在最后几行。
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."
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的连接没有问题(它们正确地形成了环形计数器),但您不会看到太多情况发生。复位后,所有触发器都包含零,它将随着每个时钟脉冲在环上循环,但实际上不会导致输出发生变化。当您声明信号时,为 q3 指定的默认值“1”将在电路开始运行(或模拟)后立即被触发器的实际输出覆盖,这通常是初始化硬件的错误方法。
您需要确保当您置位复位信号时,您的硬件会转换到适当的状态(即:设置一位,清除所有其他位)。实现此目的的一种方法是使用具有 Q3 设置输入的 FF。如果您没有带有置位(而不是复位)信号的触发器,您可以通过在输入和输出上放置反相器来模拟触发器,这将在您的环形计数器周围提供一个“1”。应用重置。您还可以创建一些中间信号并为 D 输入制作一个多路复用器以构建可加载计数器,或任何其他各种解决方案......
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.
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. 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 触发器输出 Q 应该将端口方向设置为 inout(或缓冲区)而不是 out。这是因为输出也充当输入。我认为在进行结构建模时必须仔细观察这一点。
端口(CLK、D、复位:在 STD_LOGIC 中;
问:输入输出 STD_LOGIC);
但请检查我不确定,
约翰逊计数器也是环形计数器,请参阅此 约翰逊计数器的VHDL代码,采用结构建模风格
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. 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);
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