带 T 型触发器的 VHDL 3 位序列计数器
VHDL 3-bit sequence counter with T-Flip Flops
我是 VHDL 的新手,我看不到我的问题的解决方案。我想为我的带有 T Flip Flop 的 3 位序列计数器找到一个 VHDL 代码:..,0,4,5,7,6,2,3,1,0,... 我说了实话 table 和 T_FF 的最小化方程如下:
T0=Q2 xor Q1 xor Q0;
T1=(Q2 xor Q1) 和 Q0;
T2= 不是(Q2 xor Q1)和 Q0;
然后我画电路:
最后一个 VHDL:
人字拖
library ieee;
use ieee.std_logic_1164.all;
entity tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end tff;
architecture behave of tff is
-- signal q_reg: std_logic; --v registru
-- signal q_next: std_logic; --naslednje stanje
begin
process
variable x: std_logic:='0';
begin
wait on clk;
if (clk' event and clk = '1') then
if reset='1' then
x:='0';
else x:=t;
end if;
end if;
if (t = '1') then
q<=not x;
else
q<=x;
end if;
end process;
end behave;
-----------------------------------------------------------
灰度计数器
library ieee;
use ieee.std_logic_1164.all;
entity tff_gray is
port(
clk: in std_logic;
reset: in std_logic;
q: inout std_logic_vector (2 downto 0)
--q: out std_logic
);
end tff_gray;
architecture behave of tff_gray is
component tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end component;
signal i0,i1,i2: std_logic; --v registru
--signal q_next: std_logic; --naslednje stanje
begin
i0<=q(0) xor q(1) xor q(2);
i1<=q(0) and (q(1) xor q(2));
i2<=q(0) and not(q(1) xor q(2));
Tff0: tff port map(clk, reset, i0, Q(0));
Tff1: tff port map(clk, reset, i1, Q(1));
Tff2: tff port map(clk, reset, i2, Q(2));
end behave;
我写了这一堆我在互联网上找到的代码。当我编译我的代码时,一切都没有问题,但是模拟是错误的。我多次检查这段代码,但不知道哪里出了问题。如果有人有任何想法,请分享。
我大部分时间都是在 YouTube 上观看这个 altera 网站和 LBEbooks。
很多事情。第一:
T-FF 又名拨动触发器
您的 toggle flip-flop 描述有误。
如果 T='1'
,则切换触发器会翻转输出。所以:
signal q_int : std_logic := '0';
begin
tff_proc: process(clk) begin
if rising_edge(clk) then
if t='1' then
q_int <= not q_int;
end if;
-- reset statement
if reset='1' then
q_int <= '0';
end if;
end if;
end process;
q <= q_int;
冗余代码
不要合并 wait on clk
和 if (clk'event and clk='1')
因为它们做同样的事情。合并会导致问题。请参阅我上面的示例以获取正确的实例化。
组件实例化
您不需要在 tff_gray
实体中包含 component tff
代码。只需直接从库中实例化实体即可。例如
Tff0: entity work.tff port map(clk, reset, i0, q(0));
双向端口(inout
类型)
使用 inout
类型,您将其用于 tff_gray
的 q
可能会给模拟和实现带来问题。应该是 out
.
但是,您一定遇到了cannot read outputs
错误。这在 VHDL-2008 中不再是问题,因此您应该使用 VHDL-2008 模式进行编译。
或者,您需要使用中间信号,就像我在上面的示例中所做的那样。例如
signal q_int : std_logic_vector(2 downto 0) := (others => '0');
[...]
q <= q_int;
我是 VHDL 的新手,我看不到我的问题的解决方案。我想为我的带有 T Flip Flop 的 3 位序列计数器找到一个 VHDL 代码:..,0,4,5,7,6,2,3,1,0,... 我说了实话 table 和 T_FF 的最小化方程如下:
T0=Q2 xor Q1 xor Q0;
T1=(Q2 xor Q1) 和 Q0;
T2= 不是(Q2 xor Q1)和 Q0;
然后我画电路:
最后一个 VHDL:
人字拖
library ieee;
use ieee.std_logic_1164.all;
entity tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end tff;
architecture behave of tff is
-- signal q_reg: std_logic; --v registru
-- signal q_next: std_logic; --naslednje stanje
begin
process
variable x: std_logic:='0';
begin
wait on clk;
if (clk' event and clk = '1') then
if reset='1' then
x:='0';
else x:=t;
end if;
end if;
if (t = '1') then
q<=not x;
else
q<=x;
end if;
end process;
end behave;
-----------------------------------------------------------
灰度计数器
library ieee;
use ieee.std_logic_1164.all;
entity tff_gray is
port(
clk: in std_logic;
reset: in std_logic;
q: inout std_logic_vector (2 downto 0)
--q: out std_logic
);
end tff_gray;
architecture behave of tff_gray is
component tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end component;
signal i0,i1,i2: std_logic; --v registru
--signal q_next: std_logic; --naslednje stanje
begin
i0<=q(0) xor q(1) xor q(2);
i1<=q(0) and (q(1) xor q(2));
i2<=q(0) and not(q(1) xor q(2));
Tff0: tff port map(clk, reset, i0, Q(0));
Tff1: tff port map(clk, reset, i1, Q(1));
Tff2: tff port map(clk, reset, i2, Q(2));
end behave;
我写了这一堆我在互联网上找到的代码。当我编译我的代码时,一切都没有问题,但是模拟是错误的。我多次检查这段代码,但不知道哪里出了问题。如果有人有任何想法,请分享。 我大部分时间都是在 YouTube 上观看这个 altera 网站和 LBEbooks。
很多事情。第一:
T-FF 又名拨动触发器
您的 toggle flip-flop 描述有误。
如果 T='1'
,则切换触发器会翻转输出。所以:
signal q_int : std_logic := '0';
begin
tff_proc: process(clk) begin
if rising_edge(clk) then
if t='1' then
q_int <= not q_int;
end if;
-- reset statement
if reset='1' then
q_int <= '0';
end if;
end if;
end process;
q <= q_int;
冗余代码
不要合并 wait on clk
和 if (clk'event and clk='1')
因为它们做同样的事情。合并会导致问题。请参阅我上面的示例以获取正确的实例化。
组件实例化
您不需要在 tff_gray
实体中包含 component tff
代码。只需直接从库中实例化实体即可。例如
Tff0: entity work.tff port map(clk, reset, i0, q(0));
双向端口(inout
类型)
使用 inout
类型,您将其用于 tff_gray
的 q
可能会给模拟和实现带来问题。应该是 out
.
但是,您一定遇到了cannot read outputs
错误。这在 VHDL-2008 中不再是问题,因此您应该使用 VHDL-2008 模式进行编译。
或者,您需要使用中间信号,就像我在上面的示例中所做的那样。例如
signal q_int : std_logic_vector(2 downto 0) := (others => '0');
[...]
q <= q_int;