Events VHDL:Std_逻辑输入存储在整数中

Events VHDL:Std_逻辑输入存储在整数中,events,vector,integer,vhdl,bit,Events,Vector,Integer,Vhdl,Bit,我有以下问题: 我有一台PC,它为我的SPARTAN 3AN FPGA提供输入,我希望获取这些输入,将它们放入std_逻辑_向量中,然后将它们转换为整数。这些指令被分成“n”个指令,每个指令有32位。我需要将前三位放在一个整数中,接下来的28位放在另一个整数中,最后一位是“最后一个指令标志”。所以,我有两个100个整数的数组,我将把指令放在其中(100是极限)。如果“最后一个指令标志”为一,则整个操作应停止 程序合成不正确,所以我做了一个模拟。我发现了问题,但我不知道如何解决,所以我需要你的帮助

我有以下问题:

我有一台PC,它为我的SPARTAN 3AN FPGA提供输入,我希望获取这些输入,将它们放入std_逻辑_向量中,然后将它们转换为整数。这些指令被分成“n”个指令,每个指令有32位。我需要将前三位放在一个整数中,接下来的28位放在另一个整数中,最后一位是“最后一个指令标志”。所以,我有两个100个整数的数组,我将把指令放在其中(100是极限)。如果“最后一个指令标志”为一,则整个操作应停止

程序合成不正确,所以我做了一个模拟。我发现了问题,但我不知道如何解决,所以我需要你的帮助。以下是代码和模拟输出:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.all;


entity BinaryDecimalConv is
end BinaryDecimalConv;

architecture Behavioral of BinaryDecimalConv is

    type int_array is array (100 downto 0) of integer;

    signal clkcnt: integer :=0;
    signal fbaud: integer;
    signal lastnumflag: std_logic:='0';
    signal clk: std_logic;
    signal PLCinput: std_logic;
    signal init: std_logic;
    signal BusyIN: std_logic;
    signal BusyOutSignal: std_logic;
    signal InnerBusyOut: std_logic;
    signal cnt: integer :=0;
    signal fbaut: integer :=0;
    signal pre_int: std_logic_vector (31 downto 0) := (others => '0');
    signal pre_spec_num: int_array := (others =>0);
    signal cylinder: int_array := (others => 0);
    signal InnerNumLength: integer:=0;
    signal num_length: integer:=0;

begin

CLOCKK: Process is
begin
    clk<='0';
    wait for 10 ns;
    clk<='1';
    wait for 10 ns;
end process CLOCKK;

fbaud <=5208;
BusyIN <='0';
init <='0';

PLC: Process is
    variable PrePLC: std_logic_vector(159 downto 0):="1010101010101010101010101001010010101010101010101010101010010100101010101010101010101010100101001010101010101010101010101001010010101010101010101010101010010101"; -- 1 with 100, 5 with 200, 5 2ith 200, 3 with 300, 4 with 750
begin
    PLCinput<=PrePLC(159);
    PrePLC:= PrePLC(158 downto 1) & '0';
    wait for 104166 ns;
end process;    


LastNum: process (LastNumFlag) is
    begin
    if LastNumFlag = '1' then
        BusyOutSignal <='1';
        InnerBusyOut <='1';
    else
        BusyOutSignal <='0';
        InnerBusyOut <='0';
    end if;
    end process LastNum;

DecoderAndAcquirer: process (PLCinput, BusyIN, InnerBusyOut,clk) is
begin

    if (clk'event and clk='1') then                                                         -- If rising edge on clock
        if ((BusyIN='0') and (InnerBusyOut='0') and (init='0')) then                        -- Check if FPGA and PLC are ready to exchange information and if init is done
            if (clkcnt = fbaud/2)                    then                                   --  If clkcnt is equal to half of the duration of the input bit then
                pre_int(31) <= PLCinput;                                                    -- Initialize the last digit of pre_int
                cnt <= cnt+1;                                                               -- Incrementing cnt => going towards bit 2
                clkcnt <=clkcnt+1;                                                          -- Incrementing clkcnt so you can exit this block
                if (cnt<32) then                                                            -- Checking if not last bit
                    pre_int <= '0' & pre_int(31 downto 1);                                  -- If not last bit, shift number to right
                else                                                                        -- else
                    cnt <=0;                                                                -- reset cnt to start with next instruction
                    if (pre_int(0)='1') then                                                -- Check if last digit is one
                        LastNumFlag <= '1';                                                 -- If last digit is one, stop acquiring instructions
                    else
                        LastNumFlag <='0';
                    end if;
                    pre_spec_num(InnerNumLength) <= to_integer(unsigned(pre_int(28 downto 1))); -- Conversion from binary to decimal for instruction
                    cylinder(InnerNumLength) <= to_integer(unsigned(pre_int(31 downto 29)));    -- Conversion from binary to decimal for the number of cylinder
                    InnerNumLength <= InnerNumLength +1;                                            -- Incrementing the number of instructions
                    num_length <= InnerNumLength;
                end if;
            elsif (clkcnt = fbaud) then                                                     -- If clkcnt has reached the entire length of the input bit
                clkcnt <= 0;                                                                -- set clkcnt to zero so the process can start from beginning.
            else                                                                            -- If clkcnt is less than or more than half of the entire duration, but surely
                clkcnt <= clkcnt +1;                                                        -- less than the entire duration, then increment the value of the clkcnt.
            end if;
        end if;
    end if;
end process DecoderAndAcquirer;

end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.NUMERIC_STD.all;
实体BinaryDecimalConv为
结束二进制小数conv;
BinaryDecimalConv的体系结构是
int_数组类型是整数数组(100到0);
信号clkcnt:整数:=0;
信号fbaud:整数;
信号lastnumflag:std_逻辑:='0';
信号时钟:标准逻辑;
信号PLCinput:std_逻辑;
信号初始化:标准逻辑;
信号总线:标准逻辑;
信号总线信号:标准逻辑;
信号内部总线:标准逻辑;
信号cnt:整数:=0;
信号fbaut:整数:=0;
信号前置:标准逻辑向量(31到0):=(其他=>'0');
信号前置规格编号:int\u数组:=(其他=>0);
信号缸:int_数组=(其他=>0);
信号InnerNumLength:整数:=0;
信号数长度:整数:=0;
开始
时钟:过程是
开始

clkFirst
PrePLC:=PrePLC(158向下至1)和'0'长度不匹配,所以我假设
这是
PrePLC:=PrePLC(158到0)和'0'相反,因此作为
移位寄存器

在代码收单机构的过程中,有:

...
pre_int(31) <= PLCinput;
...
if (cnt<32) then
  pre_int <= '0' & pre_int(31 downto 1);
...
波形图如下图所示


是的,对于第一个问题,你是对的。我错过了一点(但它怎么会模拟呢?)。第二点:我确实希望覆盖它。因为plcinput将每104166 ns到达一次,我希望它们向右移动,所以即使它在获取值时没有显示它的值,它也应该将preint(30)显示为1,因为我在第一次使用pre_int时实际做了pre_int(30):ModelSim报告由于长度不匹配而导致的错误,听起来你的模拟器不够挑剔。对于第二个:我添加了一个图,在更长的模拟之后,将pre_int(31)显示为'1',因此cnt达到32。最后一点意见:不,第一个
pre_int(31)是第二个:我的模拟器也在32次迭代后显示一次,但这不是我愿意得到的行为。我需要它立即改变,一旦PLCinput得到一个新的值。在最初的项目(不是模拟项目)中,我之所以使用变量,是因为信号在增量周期后改变了值。我在这里使用信号是因为我的模拟器不允许我模拟变量,但在编写模拟项目时,我完全忘记了信号及其赋值。但是,我的观点是,我甚至尝试了变量。它在退出时仍然会给出一些奇怪的数字”,因此即使分配了pre_int(31),它也会在pre_int中被覆盖
DecoderAndAcquirer: process (PLCinput, BusyIN, InnerBusyOut,clk) is
  variable pre_int_v : std_logic_vector(pre_int'range);
begin

    if (clk'event and clk='1') then                                                         -- If rising edge on clock
        pre_int_v := pre_int;  -- Variable update from signal
        if ((BusyIN='0') and (InnerBusyOut='0') and (init='0')) then                        -- Check if FPGA and PLC are ready to exchange information and if init is done
            if (clkcnt = fbaud/2)                    then                                   --  If clkcnt is equal to half of the duration of the input bit then
                pre_int_v(31) := PLCinput;                                                    -- Initialize the last digit of pre_int
                cnt <= cnt+1;                                                               -- Incrementing cnt => going towards bit 2
                clkcnt <=clkcnt+1;                                                          -- Incrementing clkcnt so you can exit this block
                if (cnt<32) then                                                            -- Checking if not last bit
                    pre_int_v := '0' & pre_int_v(31 downto 1);                                  -- If not last bit, shift number to right
                else                                                                        -- else
                    cnt <=0;                                                                -- reset cnt to start with next instruction
                    if (pre_int_v(0)='1') then                                                -- Check if last digit is one
                        LastNumFlag <= '1';                                                 -- If last digit is one, stop acquiring instructions
                    else
                        LastNumFlag <='0';
                    end if;
                    pre_spec_num(InnerNumLength) <= to_integer(unsigned(pre_int_v(28 downto 1))); -- Conversion from binary to decimal for instruction
                    cylinder(InnerNumLength) <= to_integer(unsigned(pre_int_v(31 downto 29)));    -- Conversion from binary to decimal for the number of cylinder
                    InnerNumLength <= InnerNumLength +1;                                            -- Incrementing the number of instructions
                    num_length <= InnerNumLength;
                end if;
            elsif (clkcnt = fbaud) then                                                     -- If clkcnt has reached the entire length of the input bit
                clkcnt <= 0;                                                                -- set clkcnt to zero so the process can start from beginning.
            else                                                                            -- If clkcnt is less than or more than half of the entire duration, but surely
                clkcnt <= clkcnt +1;                                                        -- less than the entire duration, then increment the value of the clkcnt.
            end if;
        end if;
        pre_int <= pre_int_v;  -- Signals update from variable
    end if;
end process DecoderAndAcquirer;