【问题标题】:VHDL record assignment through for loop通过 for 循环的 VHDL 记录分配
【发布时间】:2018-09-26 11:27:11
【问题描述】:

我在 process 中有一个 for 循环,它适用于 std_logic 数组,但不适用于 record数组。我使用 Xilinx ISE 和 ISIM,代码是 vhdl-93。目标将是 Spartan 3。

这是记录定义:

TYPE spi_rx_t IS RECORD
CS      : std_logic;
MOSI    : std_logic;
CLK     : std_logic;
END RECORD;
constant SYNC_LATCHES   : integer := 2;

这里是数组的定义和声明:

type spi_rx_array_t is array (0 to SYNC_LATCHES) of spi_rx_t;
signal spi_in_array : spi_rx_array_t;

流程如下:

    spi_in_array(0).MOSI <= SPI_MOSI;
    spi_in_array(0).CLK <= SPI_CLK;
    spi_in_array(0).CS <= SPI_CS;    

    sync_p: process (clk_100)
        begin
            if rising_edge(clk_100) then
--                for I in 1 to SYNC_LATCHES loop
--                  spi_in_array(I) <= spi_in_array(I - 1);
--                end loop;
                spi_in_array(1) <= spi_in_array(0);
                spi_in_array(2) <= spi_in_array(1);
            end if;
        end process;

注释代码下方的 2 行完全按预期工作(允许我将外部信号同步到 clk_100),但我宁愿将它们实现为 for 循环(例如注释的循环)。

但是,这些注释行在我的 ISIM 测试台中不会产生相同的结果(使用 for 循环 时,spi_in_array 保持未知状态)。为什么?

请帮我解决这个问题。

【问题讨论】:

  • 如果您使用注释掉的行,是否有任何警告或错误消息?
  • 我不知道它是否相关,但是您在模拟时使用的是什么 VHDL 标准?
  • 这是 VHDL-2002 的一个属性,在“12.6.1 驱动程序”一节中描述为VHDL concept "longest static prefix";因此不是 ISIM 中的错误。请参阅我的建议中对 SO answer 的引用,以将这个问题作为重复项关闭。
  • 我添加了一个答案。非常感谢 Morten Zilmer :)

标签: vhdl


【解决方案1】:

正如Morten Zilmer 所评论的,这是由于 VHDL 概念“最长静态前缀”。这个SO answer 与我的问题类似。

就我而言,解决问题的最简单方法是将数组的第一个元素的赋值移动到与 for 循环相同的进程中。我还必须将 SYNC_LATCHES 常量从 2 减少到 1,因为 spi_in_array(0) 现在被 clk_100 锁定。

sync_p: process (clk_100)
begin
    if rising_edge(clk_100) then
        spi_in_array(0).MOSI <= SPI_MOSI;
        spi_in_array(0).CLK <= SPI_CLK;
        spi_in_array(0).CS <= SPI_CS;
        for I in 1 to SYNC_LATCHES-1 loop
            spi_in_array(I) <= spi_in_array(I - 1);
        end loop;
    end if;
end process;

【讨论】:

    猜你喜欢
    • 2016-07-30
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多