Vhdl 添加无符号信号

Vhdl 添加无符号信号,vhdl,Vhdl,我得照顾你 SIGNAL sum,sumsq1,sumsq2,res,m: signed(31 downto 0):=(others => '0'); 当我在烟灰缸内执行以下操作时 sum <= TO_SIGNED(pass(4)*try(4),32); sum“0”)--输入到加法器/sub.r-余数。 变量i:整数:=0; 开始 对于0到15循环中的i 右(0):='1'; 右(1):=r(17); 右(17至2):=q; 左(1向下至0):=a(31向下至30); 左(

我得照顾你

SIGNAL sum,sumsq1,sumsq2,res,m: signed(31 downto 0):=(others => '0');
当我在烟灰缸内执行以下操作时

sum   <= TO_SIGNED(pass(4)*try(4),32);
sum“0”)--输入到加法器/sub.r-余数。
变量i:整数:=0;
开始
对于0到15循环中的i
右(0):='1';
右(1):=r(17);
右(17至2):=q;
左(1向下至0):=a(31向下至30);
左(17向下到2):=r(15向下到0);
a(31降到2):=a(29降到0)--移位2位。
如果(r(17)=“1”),则
r:=左+右;
其他的
r:=左-右;
如果结束;
q(15降到1):=q(14降到0);
q(0):=不是r(17);
端环;
返回q;
结束sqrt;
末端相关性;
相关性的架构行为是
类型数据_数组是整数数组(1到10);
信号通过,尝试:数据_阵列;
信号s:无符号(15到0):=(其他=>'0');
信号和,sumsq1,sumsq2,res,m:signed(31向下到0):=(其他=>'0');
共享变量e:unsigned(31到0):=(其他=>'0');
开始

传递我将您的示例提炼为一个MVCe,并添加了
sum1
以显示乘法本身:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity correlation is
end correlation;

architecture behavior of correlation is
    type data_array is array(1 to 10) of integer;

    signal pass,try  : data_array;
    signal sum: signed(31 downto 0) := (others => '0');
    signal sum1: signed(31 downto 0) := (others => '0');
    signal clock_50:  std_logic := '0';

begin

clock:
    process
    begin
        wait for 10 ns;
        clock_50 <= not clock_50;
        if now > 60 ns then
            wait;
        end if;
    end process;

    pass<=(0,0, 1, 2, 4, 7, 4, 5, 3,0);
    try <=(0,0,-1,-2,-4,-7,-4,-5,-3,0); 

    process (clock_50)
    begin
        if (clock_50'event and clock_50 = '1') then
            sum   <= sum + to_signed(pass(4)*try(4),32);
            sum1  <= to_signed(pass(4)*try(4),32);
        end if;
    end process;
end behavior;
首先要注意的是,您正在对同一信号执行连续的顺序信号分配,分配位于同一进程中。每个流程只有一组驱动程序,在同一模拟周期中暂停之前,流程将一直执行。作为敏感度列表上等待的最后一条语句,被隐含的wait语句挂起

这些分配作为循环的连续迭代发生,并且因为在任何特定的模拟时间内,任何驱动器只有一个投影波形,所以实际上只有最后一个信号分配才会发生。基本上,您正在为每个信号分配安排一个信号更新,并且它们的投影值将被下一个覆盖,直到只剩下最后一个信号分配

当当前模拟周期中的任何进程仍在执行或挂起时,无信号分配将更新值

具有无延迟元素的波形的信号分配将导致增量周期,并且在当前模拟周期完成后和增量模拟周期开始执行之前,下一个排队模拟时间的所有未决信号分配将更新。另请参见此答案-了解模拟周期中发生的情况的大图视图

如果我们对其进行模拟,我们会得到预期的结果:

(可点击)

sum
sum2
增量,就像它们不在循环中一样
sum3
使用最后一个
try
值,该值恰好为0

因为你有一个时钟,所以你期望这三组十次乘法和加法在一个时钟周期内发生。这是不实际的,或者您可以简单地切换到在loop语句中使用变量作为赋值目标

变量分配会立即生效—它是无时间限制的,而信号分配则是在当前时间(无时间等)或未来某个时间(如10 ns后)安排未来事件


您可以使用
i
作为计数器,而不是使用循环,使用最后一个值生成指定已发生10个时钟的信号。您仍然可以使用
i
作为
try
索引。假设CLOCK_50是FPGA的50 MHz时钟,想法是不能在一个时钟中执行10次乘法和累加运算。

最终代码如下

LIBRARY IEEE;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.all;


ENTITY correlation IS
    PORT (
            CLOCK_50                                        :IN STD_LOGIC);
end correlation;

architecture behavior of correlation is
     type data_array is array(1 to 10) of integer;

     signal pass,try : data_array;
     signal sum      : signed(31 downto 0) := (others => '0');
     signal sum2     : unsigned(31 downto 0) := (others => '0');
     signal sum3     : unsigned(31 downto 0) := (others => '0');

begin

     pass<=(0,0, 1, 2, 4, 7, 4, 5, 3,0);
     try <=(0,0,-1,-2,4,-7,-4,-5,-3,0); 

     PROCESS (clock_50)
         variable i  :integer:=0;
     BEGIN
        if (clock_50'event and clock_50 = '1') then
            IF i<10 THEN
                i:=i+1;      
                sum  <= sum + TO_SIGNED(pass(i)*try(i),32);
                sum2 <= sum2+ TO_UNSIGNED(pass(i)*pass(i),32);
                sum3 <= sum3+ TO_UNSIGNED(try(i) *try(i),32);
             END IF;
         END IF;
     END PROCESS;
END Behavior;
IEEE库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
实体关联是
港口(
时钟50:在标准逻辑中);
末端相关性;
相关性的架构行为是
类型数据_数组是整数数组(1到10);
信号通过,尝试:数据_阵列;
信号和:有符号(31到0):=(其他=>“0”);
信号sum2:无符号(31到0):=(其他=>0');
信号sum3:无符号(31到0):=(其他=>0');
开始

“疯狂数字”不是一个科学或工程术语。很可能你的肚子已经满了。如果您提供操作数的值,就可以给出更精确的答案。事实上,疯狂的数字并没有帮助。请同时提供完整的声明。如果在一个过程中求和?这是一个同步过程吗?很抱歉,我现在会更专业一些。我希望更新有助于澄清我的问题,但这还不够。
sum
的上一个值是多少?什么是
pass(4)
try(4)
?sum先前的值是零,因为它是声明的,我也尝试将其分配给所有零,但没有更改答案。Pass和TRY是整数向量,因此我在Modelsim中模拟了回复的signedThanks的类型更改(MCV示例中提供),它运行起来没有问题。我做了一些更改来扫描数组:if(clock_50'event和clock_50='1'),然后对于I in 1到10循环和,让我看看是否理解,评估循环内部内容的最佳方法是使用变量,因为它们可以异步执行,而不是信号。我无法像您那样添加代码,因此无法向您显示更改。我所做的是在进程内移动除1以外的所有信号,并使它们成为变量,在离开进程之前,我分配给一个信号。您还提到sqrt存在一些问题。我应该限制无符号输入/输出的大小吗。你将如何使它与代码一起工作。“我所做的是在进程内移动除1以外的所有信号,并使它们变为变量,在离开进程之前,我分配给一个信号。”这可能是不切实际的,你能在硅中的一个时钟中进行10次多重和累积操作吗?2.“…sqrt有一些问题。我应该限制输入/输出的大小吗?无符号。”,这还没有
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity correlation is
end correlation;

architecture behavior of correlation is
    type data_array is array(1 to 10) of integer;

    signal pass,try  : data_array;
    signal sum: signed(31 downto 0) := (others => '0');
    signal sum1: signed(31 downto 0) := (others => '0');
    signal clock_50:  std_logic := '0';

begin

clock:
    process
    begin
        wait for 10 ns;
        clock_50 <= not clock_50;
        if now > 60 ns then
            wait;
        end if;
    end process;

    pass<=(0,0, 1, 2, 4, 7, 4, 5, 3,0);
    try <=(0,0,-1,-2,-4,-7,-4,-5,-3,0); 

    process (clock_50)
    begin
        if (clock_50'event and clock_50 = '1') then
            sum   <= sum + to_signed(pass(4)*try(4),32);
            sum1  <= to_signed(pass(4)*try(4),32);
        end if;
    end process;
end behavior;
architecture different of correlation is
    type data_array is array(1 to 10) of integer;

    signal pass,try  : data_array;
    signal sum, sum2, sum3: signed(31 downto 0) := (others => '0');
    signal clock_50:  std_logic := '0';

begin

clock:
    process
    begin
        wait for 10 ns;
        clock_50 <= not clock_50;
        if now > 60 ns then
            wait;
        end if;
    end process;

    pass<=(0,0, 1, 2, 4, 7, 4, 5, 3,0);
    try <=(0,0,-1,-2,-4,-7,-4,-5,-3,0); 

    process (clock_50)
    begin
     if clock_50'event and clock_50 = '1' then 
         for i in 1 to 10 loop 
             sum  <= sum  + to_signed(pass(4)*try(4),  32);
             sum2 <= sum2 + to_signed(pass(4)*pass(4), 32); 
             sum3 <= sum3 + to_signed(try(i) *try(i),  32); 
         end loop; 
     end if;
    end process;
end architecture;
LIBRARY IEEE;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.all;


ENTITY correlation IS
    PORT (
            CLOCK_50                                        :IN STD_LOGIC);
end correlation;

architecture behavior of correlation is
     type data_array is array(1 to 10) of integer;

     signal pass,try : data_array;
     signal sum      : signed(31 downto 0) := (others => '0');
     signal sum2     : unsigned(31 downto 0) := (others => '0');
     signal sum3     : unsigned(31 downto 0) := (others => '0');

begin

     pass<=(0,0, 1, 2, 4, 7, 4, 5, 3,0);
     try <=(0,0,-1,-2,4,-7,-4,-5,-3,0); 

     PROCESS (clock_50)
         variable i  :integer:=0;
     BEGIN
        if (clock_50'event and clock_50 = '1') then
            IF i<10 THEN
                i:=i+1;      
                sum  <= sum + TO_SIGNED(pass(i)*try(i),32);
                sum2 <= sum2+ TO_UNSIGNED(pass(i)*pass(i),32);
                sum3 <= sum3+ TO_UNSIGNED(try(i) *try(i),32);
             END IF;
         END IF;
     END PROCESS;
END Behavior;