我是VHDL的新手。我正在用VHDL在串行输出72位移位寄存器中实现串行。当启用信号较高时,我希望移位寄存器移动72次,无论启用是高还是低。我编写了以下代码,该代码仅在启用高时才能工作。谁能帮我转换数据,一旦启用高,然后不依赖于启用,以转移数据?
library ieee;
use ieee.std_logic_1164.all;
entity SR is
port(clk, din, rst, enable : in std_logic;
sr_out : inout std_logic_vector(71 downto 0));
end SR;
architecture behavioral of SR is
signal shift_reg: std_logic_vector(71 downto 0);
begin
process (clk, rst)
begin
if (rst = '0') then
shift_reg <= (others => '0');
elsif (clk'event and clk = '1') then
if enable= '1' then
shift_reg(70 downto 0) <= shift_reg(71 downto 1);
shift_reg(71) <= din;
end if;
end if;
end process;
sr_out <= shift_reg;
end behavioral; 非常感谢!
发布于 2013-06-11 18:07:32
要做到这一点,您需要两台状态机。这是一个很好的方法。我很确定它能满足你的需要或者非常接近。
library ieee;
use ieee.std_logic_1164.all;
entity SR is
port(
clk : in std_logic;
din : in std_logic;
rst : in std_logic;
enable : in std_logic;
sr_out : inout std_logic_vector(71 downto 0)
);
end SR;
architecture behavioral of SR is
signal shift_reg : std_logic_vector(71 downto 0);
signal shift_cnt : integer range 0 to 72 := 0;
type T_STATE_TYPE is (IDLE, COUNTING);
signal current_state : T_STATE_TYPE;
begin
p_shift_counter : process(clk,rst)
begin
if rst = '1' then
current_state <= IDLE;
shift_cnt <= 0;
elsif rising_edge(clk) then
if (current_state = IDLE) then --no enable detected yet
shift_cnt <= 0;
if enable = '1' then
current_state <= COUNTING;
end if;
elsif (current_state = COUNTING) then --will stay in that state until it finishes counting
if (shift_cnt < 72) then
shift_reg(0) <= din;
for i in 0 to 71 loop shift_reg(i+1) <= shift_reg(i); end loop; --shifting register
shift_cnt <= shift_cnt + 1;
else
current_state <= IDLE; --finished counting
end if;
end if;
end if;
end process;
sr_out <= shift_reg;
end behavioral; 发布于 2013-06-07 11:34:30
我想你需要一个由启动信号设置的。它的输出是您的启用信号。启动信号还启动72个时钟周期计数器。当计数器翻滚(或达到零,视其方向而定)时,您将重置FlipFlop,这将导致禁用移位寄存器。
编辑:,此外,您还可以向开始信号中添加一个门,当计数器处于活动状态时,该门会阻止新的开始脉冲。因此,您可以确保您的数据仅以72位的倍数移动。
https://stackoverflow.com/questions/16982775
复制相似问题