在此代码中,当reset
等于 1 时,s
变为 1000 ,reset
等于 0 < / strong> s
变为 0100 然后 0010 然后 0001 并以 1000 作为起始值,仅在时钟到时。
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity clock_behav is
port (clock : in std_logic;
reset : in std_logic;
s : out std_logic_vector (3 downto 0));
end clock_behav;
architecture behav of clock_behav is
begin
process(clock,reset)
variable shift_counter: integer := 0;
begin
if (reset='1') then
s<="1000";
shift_counter := 1;
else
if(clock'event and clock='1') then
if(shift_counter =1) then
s<="0100";
shift_counter := 2;
elsif(shift_counter =2) then
s<="0010";
shift_counter := 3;
elsif(shift_counter =3) then
s<="0001";
shift_counter := 0;
else
s<="1000";
shift_counter := 1;
end if;
end if;
end if;
end process;
end behav;
我想创造这个
通过FlipFlops,您可以看到一个Set
和3 Reset
。但是,我很难从行为转向结构,因为在VHDL中我们不能拥有进程端口映射。当然,我尝试了很多东西,如下所示,但如果端口映射不在进程内,则无法使用触发器重新创建它。你可以清楚地理解,我对VHDL的了解并不是那么好。另外,我想告诉我,当我更改了触发器D
和Q
类型时,我是否做得正确,它是std_logic
,我将其更改为std_logic_vector
。我这样做是为了这个练习。
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity clock_structural is
port (clock : in std_logic;
reset : in std_logic;
s : out std_logic_vector (3 downto 0));
end clock_structural;
architecture behavior of clock_structural is
signal t,t1,t2,t3 : std_logic_vector (3 downto 0);
component flipflop_new
port
(D : in std_logic_vector (3 downto 0);
CLK : in std_logic;
CLR : in std_logic;
Q : out std_logic_vector (3 downto 0));
end component;
component flipflop_set
port
(D_s : in std_logic_vector (3 downto 0);
CLK_s : in std_logic;
CLR_s : in std_logic;
Q_s : out std_logic_vector (3 downto 0));
end component;
begin
process(clock,reset)
variable shift_counter: integer := 0;
begin
if (reset='1') then
t<="1000";
shift_counter := 1;
else
if(clock'event and clock='1') then
if(shift_counter =1) then
shift_counter := 2;
elsif(shift_counter =2) then
shift_counter := 3;
elsif(shift_counter =3) then
shift_counter := 0;
else
shift_counter := 1;
end if;
end if;
end if;
end process;
FFS1: flipflop_set port map(t,clock,reset,t1);
s<=t1;
FFR1: flipflop_new port map(t1,clock, reset,t2);
s<=t2;
FFR2: flipflop_new port map(t2,clock, reset,t3);
s<=t3;
FFR3: flipflop_new port map(t3,clock, reset,s);
end behavior ;
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity flipflop_new is
port ( D : in std_logic_vector (3 downto 0);
CLK : in std_logic;
CLR : in std_logic;
Q : out std_logic_vector (3 downto 0)
);
end flipflop_new;
architecture behavior of flipflop_new is
begin
process(CLK)
begin
if CLR='0' then null;
elsif RISING_EDGE(CLK) then
Q <= D;
end if;
end process ;
end behavior ;
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity flipflop_set is
port ( D_s : in std_logic_vector (3 downto 0);
CLK_s : in std_logic;
CLR_s : in std_logic;
Q_s : out std_logic_vector (3 downto 0)
);
end flipflop_set;
architecture behavior of flipflop_set is
begin
process(CLK_s)
begin
if CLR_s='1' then null;
elsif RISING_EDGE(CLK_s) then
Q_s <= D_s;
end if;
end process ;
end behavior ;
答案 0 :(得分:1)
有几件事需要改变或改进。结构VHDL模型应描述您的原理图,而您实际上并不这样做。
首先,为什么你的结构中有shift_counter
?你不需要这个过程。
其次,你实例化4个触发器实体,每个4位宽,而你的原理图有4个触发器。基本上,当您需要时,实例化总共16个寄存器4.为什么您的触发器模型是4位宽?它应该是一个位。
第三,看看你的触发器描述:
process(CLK)
begin
if CLR='0' then
null;
elsif RISING_EDGE(CLK) then
Q <= D;
end if;
end process ;
它似乎是一个触发器吗?时钟上升时的Q <= D
很好,但当触发器的clr
处于活动状态时,没有会发生吗?在这种情况下,您的输出应该重置/设置,这不是您的VHDL所描述的。
另一个错误是您将输出s
分配了3次。 s
必须分配一次,但您可以像s(0) <= t1
一样单独分配位。
最后,您没有描述反馈。最后一个触发器的输出为s
,而第一个触发器的输入为t
。从原理图中,它们应该连接在一起。