不,真的,我对你的问题的评论并不是在征求你接受答案,老实说,我对声誉积分并不那么苛刻。
我的意思是,潜在的问题回答者很难为您的问题付出任何努力,而且您的声誉也不会提高。
将时钟条件放在循环语句中似乎有点尴尬(与生成语句相反,所以让我们尝试一个单独的计数器:
library ieee;
use ieee.std_logic_1164.all;
entity shft_log_vec is
port (
rst: in std_logic;
clk: in std_logic;
Q: out std_logic
);
end entity;
architecture foo of shft_log_vec is
constant CR: std_logic_vector (7 downto 0) := "11000000";
signal bit_ctr: natural range CR'REVERSE_RANGE;
begin
Q <= CR(bit_ctr);
INDEX_CTR:
process (clk, rst)
-- uninitialized default value is 0
begin
if rst = '1' then -- will only run after a rst after the first time, use reset
bit_ctr <= 0;
elsif bit_ctr < CR'HIGH and rising_edge(clk) then -- you could add an enable
bit_ctr <= bit_ctr + 1; -- integer arithmetic and comparison.
else
end if;
-- because you need clock evaluation for sequential operation in there, no loop
-- statement. Reverse the bit order by using 'RANGE instead.
end process;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity tb_shft_log_vec is
end entity;
architecture foo of tb_shft_log_vec is
signal rst: std_logic := '0';
signal clk: std_logic := '0';
signal Q: std_logic;
begin
DUT:
entity work.shft_log_vec
port map (
rst => rst,
clk => clk,
Q => Q
);
CLOCK:
process
begin
wait for 20 ns;
clk <= not clk;
if Now > 360 ns then
wait;
end if;
end process;
STIMULUS:
process
begin
wait for 1 ns;
rst <= '1';
wait for 20 ns;
rst <= '0';
wait;
end process;
end architecture;
注意CR 的指针是bit_ctr,它是一个从0 计数到7 然后停止的受限整数。
如果您希望 CR 以相反的顺序出现(第 7 个),请使用 'RANGE 和 'LOW 而不是 'REVERSE_RANGE 和 'HIGH.
在模拟测试台时,我们看到 Q 的值在每个时钟上升沿出现 CR(0) 到 CR(7),并停止等待复位。
(图片是一个完整尺寸的链接)
使用复位,意味着生成器和接收器都知道要在哪些时钟边沿对Q 进行采样。在生成器和接收器之间切换到同步复位共享可能是谨慎的做法,具体取决于信号 Q 的路由距离(如跨越时钟树边界)。
请注意评论链接中您上一个问题的答案的异同。这种使用属性的方式可以让您轻松更改 CR 的大小。