Dynamic signal creation in VHDL and solution of VHDL error: Syntax error near "process"

Dynamic signal creation in VHDL and solution of VHDL error: Syntax error near "process"

我是 VHDL 世界的新手,我收到此错误消息,提示进程附近出现语法错误。我检查了解决方案,发现可能缺少 end if 语句,但在我的代码中我没有遇到那个问题。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.ALL;
USE ieee.std_logic_arith.ALL;
use STD.textio.all;

entity Main_Architecture is
port(
    SEN: out std_logic;
    reset: in std_logic;
    clk: in std_logic
    );
end Main_Architecture;

architecture Behavioral of Main_Architecture is
signal main_counter : std_logic_vector(7 downto 0)  := "00000000";
signal mux: std_logic_vector(1 downto 0) := "00";
signal output  : std_logic_vector(7 downto 0);
signal main_counter_int : integer range 0 to 127:=0;
signal main_generator : std_logic_vector(7 downto 0);


begin
process(main_counter,reset,clk)
    variable x: std_logic;
    variable y: std_logic;
    variable z: integer;
begin
    if(reset = '1') then
        main_counter <= (others => '0');
    end if;

    if(clk'event and clk='1') then

        if(mux="00") then                               --load main counter
            y:= main_counter(0);
            x:= (main_counter(0)XOR main_counter(6) XOR main_counter(7));
            main_counter(7 downto 1) <= main_counter(6 downto 0);
            main_counter(0)<=x;
            main_counter <= main_counter+'1';
            output(0)<=y;
            output(1)<=main_counter(0);
            output(2)<=main_counter(1);
            output(3)<=main_counter(2);
            output(4)<=main_counter(3);
            output(5)<=main_counter(4);
            output(6)<=main_counter(5);
            main_counter_int<=conv_integer(output);
            if(main_counter >= "11111111") then
                mux <= "01";
            end if;
        end if;

        if(mux="01") then
            if(main_counter_int < 2) then
                z:=1;
            else if(main_counter_int < 4) then
                z:=2;
            else if(main_counter_int < 8) then
                z:=3;
            else if(main_counter_int < 16) then
                z:=4;
            else if(main_counter_int < 32) then
                z:=5;
            else if(main_counter_int < 64) then
                z:=6;
            else if(main_counter_int < 128) then
                z:=7;
            end if;


        end if;

    end if;

end process;    -------- LINE 104  -------

end Behavioral;

我还想创建一个大小从 z 到 0 的 std_logic_vector。即大小为 z+1 的向量。我怎样才能做到?

问题第 1 部分

在不查看代码中的任何其他问题的情况下,我认为问题出在这一部分,我已重新格式化以显示您缺少多少 'end if' 语句:

    if(mux="01") then
        if(main_counter_int < 2) then
            z:=1;
        else
            if(main_counter_int < 4) then
                z:=2;
            else
                if(main_counter_int < 8) then
                    z:=3;
                else
                    if(main_counter_int < 16) then
                        z:=4;
                    else
                        if(main_counter_int < 32) then
                            z:=5;
                        else
                            if(main_counter_int < 64) then
                                z:=6;
                            else
                                if(main_counter_int < 128) then
                                    z:=7;
                                end if;


    end if;

我认为您可能想使用 elsif 而不是 else if

问题第 2 部分

对于问题的第二部分,假设您想生成可以在硬件中实现的代码,没有 运行 时间大小的 std_logic_vector 这样的东西。你能做的最好的事情就是让你的向量具有它可能需要的最大大小,然后根据 'z'.

的值只分配或使用它的一部分

其他几点:

USE ieee.std_logic_arith.ALL;

这不是 'true' 标准库,还有许多其他答案建议不要使用此库。如果您需要执行数学函数(例如 +)、USE ieee.numeric_std.all;,则创建有符号或无符号类型的信号。在您的示例中,main_counter 将被声明为 signal main_counter : unsigned(7 downto 0) := "00000000";。然后可以在这个信号上执行像 + 这样的操作,对于它是否应该被签名没有歧义。

最后一节:

        output(0)<=y;
        output(1)<=main_counter(0);
        output(2)<=main_counter(1);
        output(3)<=main_counter(2);
        output(4)<=main_counter(3);
        output(5)<=main_counter(4);
        output(6)<=main_counter(5);

可以使用连接运算符 & 更紧凑地写成

        output(6 downto 0) <= main_counter(5 downto 0) & y;

旁注:output(7) 似乎从未被分配。