if语句使用vhdl

时间:2015-03-07 07:58:54

标签: if-statement vhdl fpga xilinx

我正在使用planahead软件使用vhdl设计计数器,无论如何我正在使用if statment但它给了很多错误。计数器的目的是从1到10计算升序/降序,反之亦然。在升序的情况下,当它从9变为9时重置out,从0开始重新计数。如果Descending在0变为0时重置out并将9作为新值。我正在使用电路板上的开关按钮在升序/降序计数之间切换。低于if语句和错误。我不知道我是否在写表上使用它。如果有人有想法,那将是完美的。

 Line:27-   if(inc_dec='1') then
 Line:28    if (r_reg=M-1) then
            r_next<=(others=>'0')
 Line:30    else r_reg+1;
 Line: 31   elsif (inc_dec='0')then
 Line:32    if (r_reg=M-10) then
            r_next<=(others=>'9')
 Line:34    else
            r_reg-1;

           end if;
           end if;
           end if;

错误:

 Line:27 [HDLCompiler 806] Syntax error near "if". 
 Line:28[HDLCompiler 806] Syntax error near "then". 
 Line:30[HDLCompiler 806] Syntax error near "else". 
 Line:31[HDLCompiler 806] Syntax error near "then". 

 Line:32[HDLCompiler 806] Syntax error near "then". 
 Line:34[HDLCompiler 806] Syntax error near "else". 

1 个答案:

答案 0 :(得分:1)

正如Morten Zilmer指出的那样,你需要终止if / else和if。还有一些丢失的分号。下面的代码应该有效。

if (inc_dec='1') then
   if (r_reg=(M-1)) then
        r_next <= (others=>'0');
   else 
        r_reg+1;
   end if; 
elsif (inc_dec='0') then
   if (r_reg=(M-10)) then
        r_next <=  to_unsigned(9, r_next'length);
   else
        r_reg-1;
   end if;
end if;

更新:Jonathan Drolet是对的。改变

r_next <= (others=>'9');

r_next <=  to_unsigned(9, r_next'length)
代码中的

相关问题