gpt4 book ai didi

vhdl - 如何移动 std_logic_vector?

转载 作者:行者123 更新时间:2023-12-05 03:08:12 24 4
gpt4 key购买 nike

我想要移位 std_logic_vector

但是这段代码有一个错误:

architecture led_main of testing is
signal clk_cnt : std_logic_vector(64 DOWNTO 0) := (others => '0');
signal led_buf : std_logic_vector( 3 downto 0 ) := "0001";
begin
process(clk)
begin
if rising_edge(clk) then
clk_cnt <= clk_cnt + 1;
if clk_cnt >= 24999999 then
led_buf <= led_buf(0) & led_buf(3 downto 1);
end if;
end if;
end process;

ground <= '0';
end led_main;

我认为“0001”、“0010”、“0100”……

最佳答案

你的变速杆没问题。实际上,它是一个旋转器。

但是您的计数器太大(65 位)并且它不会在适当的时间翻转或重置为零。您当前的设计等待 25M 个周期,然后在每个周期中从 25M 转移到 2**64。

此外,您正在使用非标准 IEEE 包对 std_logic_vector 执行算术运算(加法)。请使用 numeric_std 包中的 unsigned 类型。

您的计数器所需的位数可以通过 log2 函数获得,如下所示:

function log2ceil(arg : positive) return natural is
variable tmp : positive;
variable log : natural;
begin
if arg = 1 then return 0; end if;
tmp := 1;
log := 0;
while arg > tmp loop
tmp := tmp * 2;
log := log + 1;
end loop;
return log;
end function;

来源:https://github.com/VLSI-EDA/PoC/blob/master/src/common/utils.vhdl

完整代码重写:

use IEEE.numeric_std.all;

architecture led_main of testing is
constant CNT_MAX : positive := 25000000;
signal clk_cnt : unsigned(log2ceil(CNT_MAX) - 1 downto 0) := (others => '0');
signal led_buf : std_logic_vector( 3 downto 0 ) := "0001";
begin
process(clk)
begin
if rising_edge(clk) then
clk_cnt <= clk_cnt + 1;
if clk_cnt = (CNT_MAX - 1) then
clk_cnt <= (others => '0');
led_buf <= led_buf(0) & led_buf(3 downto 1);
end if;
end if;
end process;
end led_main;

```

关于vhdl - 如何移动 std_logic_vector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com