If statement 将逻辑向量移位到位
我有一个8位的逻辑向量,它应该被转移到一个输出If statement 将逻辑向量移位到位,if-statement,vhdl,clock,fpga,bit-shift,If Statement,Vhdl,Clock,Fpga,Bit Shift,我有一个8位的逻辑向量,它应该被转移到一个输出 constant CR:std_logic_vector:(7 downto 0):="11000000"; 我正在尝试使用CR的索引和属于指定索引的每个值 Q<=CR(i); Q不,真的,我对你的问题的评论并不是要你接受答案,老实说,我没有那么难获得声誉积分 我的意思是,潜在的问题回答者很难对你的问题做出任何努力,而且你的声誉也不会提高 将时钟条件放在循环语句中似乎有点尴尬(与generate语句相反,因此让我们尝试使用单独的计数器:
constant CR:std_logic_vector:(7 downto 0):="11000000";
我正在尝试使用CR的索引和属于指定索引的每个值
Q<=CR(i);
Q不,真的,我对你的问题的评论并不是要你接受答案,老实说,我没有那么难获得声誉积分
我的意思是,潜在的问题回答者很难对你的问题做出任何努力,而且你的声誉也不会提高
将时钟条件放在循环语句中似乎有点尴尬(与generate语句相反,因此让我们尝试使用单独的计数器:
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;
ieee库;
使用ieee.std_logic_1164.all;
实体shft_log_vec为
港口(
rst:标准逻辑中;
clk:标准逻辑中;
Q:输出标准逻辑
);
终端实体;
shft_log_vec的体系结构foo是
常数CR:std_逻辑_向量(7到0):=“11000000”;
信号位ctr:自然范围CR'反向范围;
开始
Q clk,
Q=>Q
);
时钟:
过程
开始
等待20纳秒;
时钟360纳秒
等待
如果结束;
结束过程;
刺激:
过程
开始
等待1ns;
rst您的案例似乎证明了stack exchange站点上声誉的价值。你还没有接受你之前任何问题的一个答案。您可以从CR
的声明中导出循环的迭代范围,如果需要反转顺序,请使用属性“REVERSE\u range”。否则,请看我对你问题的回答,对此表示抱歉。我不知道我能接受答案,因为我的代表性很低。我喜欢头脑风暴,一个问题可能会被问到不同的方式,一个问题的解决方案也可能不同。我想这对stack exchange站点来说无关紧要,这是一种很好的理解方式。感谢您的回复。同时请注意,在您的CR声明中,std_logic_向量后面有冒号。