【问题标题】:VHDL If Statement Syntax ErrorVHDL If 语句语法错误
【发布时间】:2013-01-25 14:29:38
【问题描述】:

我有以下代码:

process(value_counter, hex5_value)
    begin
        if(value_counter <= x"0F") then
            with value_counter select hex4 <=  --error on this line
            "0111111" when x"00", 
            "0000110" when x"01", 
            "1011011" when x"02", 
            "1001111" when x"03", 
            "1100110" when x"04", 
            "1101101" when x"05", 
            "1111101" when x"06", 
            "0000111" when x"07", 
            "1111111" when x"08", 
            "1101111" when x"09",
            "1110111" when x"0A", 
            "1111100" when x"0B",
            "0111001" when x"0C", 
            "1011110" when x"0D",
            "1111001" when x"0E", 
            "1110001" when x"0F";

            hex5<="0111111";
        elsif(value_counter > x"0F") then
            with value_counter mod 10 select hex4 <=
            "0111111" when x"00", 
            "0000110" when x"01", 
            "1011011" when x"02", 
            "1001111" when x"03", 
            "1100110" when x"04", 
            "1101101" when x"05", 
            "1111101" when x"06", 
            "0000111" when x"07", 
            "1111111" when x"08", 
            "1101111" when x"09",
            "1110111" when x"0A", 
            "1111100" when x"0B",
            "0111001" when x"0C", 
            "1011110" when x"0D",
            "1111001" when x"0E", 
            "1110001" when x"0F";

            with hex5_value select hex5 <=
            "0111111" when x"00", 
            "0000110" when x"01", 
            "1011011" when x"02", 
            "1001111" when x"03",
            "1100110" when x"04", 
            "1101101" when x"05", 
            "1111101" when x"06", 
            "0000111" when x"07", 
            "1111111" when x"08", 
            "1101111" when x"09",
            "1110111" when x"0A", 
            "1111100" when x"0B",
            "0111001" when x"0C", 
            "1011110" when x"0D",
            "1111001" when x"0E", 
            "1110001" when x"0F";
        end if;
end process;

但我在运行它时在指示的行上收到以下错误:Error (10500): VHDL syntax error at xxx near text "with"; expecting "end", or "(", or an identifier ("with" is a reserved keyword), or a sequential statement。任何人都知道是什么原因造成的,以及如何合法且等效地重写它?

【问题讨论】:

  • 您真的是指“mod 10”而不是“mod 16”吗?
  • IEEE Std 1076-2008 支持选定的信号分配,请参阅 10.5.4 选定的信号分配。假设使用minimal reproducible example,您的代码在使用-2008 兼容工具时不会产生语法错误(一些 FPGA 供应商提出的高要求,指出错误号)。

标签: syntax syntax-error vhdl


【解决方案1】:

“正确”答案是进程内的 CASE 语句或组合区域(即进程外)中的“with ... select”。

但是,如果您创建一个包含 16 个 7 段显示值的常量数组,并简单地为该数组编制索引,您将拥有更好的 VHDL:

subtype seven_seg is std_logic_vector(6 downto 0);

constant decode : array 0 to 15 of seven_seg := (
            "0111111", "0000110", "1011011", "1001111", 
            "1100110", "1101101", "1111101", "0000111", 
            "1111111", "1101111", "1110111", "1111100",
            "0111001", "1011110", "1111001", "1110001");

    process(value_counter, hex5_value)
        begin
            if value_counter <= x"0F" then
                hex4 <= decode(to_integer(value_counter(3 downto 0)));
                hex5 <= decode(0);
            -- elsif value_counter > x"0F" then  
            -- surely this "elsif" is unnecessary!
            else 
                hex4 <= decode(to_integer(value_counter(7 downto 4)));
                hex5 <= decode(to_integer(hex5_value(3 downto 0)));
            end if;
    end process;

【讨论】:

    【解决方案2】:

    'with' 的信号赋值是一个并发语句。所以它在进程内无效。 一个“案例”可以做到。但是当情况变得安静时,请检查时序分析的结果。

    有关更多语法信息,请参阅this link。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 2016-08-22
      相关资源
      最近更新 更多