If statement verilogif-else语句

If statement verilogif-else语句,if-statement,verilog,hdl,If Statement,Verilog,Hdl,我正在尝试为BCD计数秒表编写一个模块。当我检查语法时,会出现如下错误: ERROR:HDLCompilers:26 - "../counter.v" line 24 expecting 'end', found 'else' ERROR:HDLCompilers:26 - "../counter.v" line 25 unexpected token: '=' ERROR:HDLCompilers:26 - "../counter.v" line 25 unexpected token: '+

我正在尝试为BCD计数秒表编写一个模块。当我检查语法时,会出现如下错误:

ERROR:HDLCompilers:26 - "../counter.v" line 24 expecting 'end', found 'else'
ERROR:HDLCompilers:26 - "../counter.v" line 25 unexpected token: '='
ERROR:HDLCompilers:26 - "../counter.v" line 25 unexpected token: '+'
ERROR:HDLCompilers:26 - "../counter.v" line 25 expecting 'endmodule', found '1'
在我的代码中间。我不太确定错误来自何处,并尝试实现更多的begin/end,但这并没有掩盖问题。这是我目前的代码:

module BCDCount(en, clk, rst, direction, cTenths, cSec, cTS, cMin);
    input en, clk, rst, direction;
    output [3:0] cTenths, cSec, cTS, cMin;
    reg [3:0] cTenths, cSec, cTS, cMin;

always @(posedge clk)
if(en)
begin

    if(direction == 0)

        if(cMin== 4'b 1001)
                cMin <= 4'b 0000;
            if(cTS == 4'b 0101)
                cTS <= 4'b 0000;
                cMin = cMin +1;

                if(cSec == 4'b 1001)
                    cSec <= 4'b 0000;
                    cTS = cTS +1;
                    if(cTenths == 4'b 1001)
                        cTenths <= 4'b 0000;
                        cSec = cSec+1;
                    else 
                        cTenths = cTenths +1;
                else
                    cSec = cSec+1;
            else
                cTS = cTS + 1;

    if(direction == 1)

        if(cMin== 4'b 0000)
            cMin <= 4'b 1001;
            if(cTS == 4'b 0000)
                cTS <= 4'b 1001;
                cMin = cMin -1;
                if(cSec == 4'b  0000)
                    cSec <= 4'b 1001;
                    cTS = cTS -1;
                        if(cTenths == 4'b 0000)
                            cTenths <= 4'b 1001;
                            cSec = cSec-1;
                        else
                            cTenths = cTenths -1;
                else
                    cSec = cSec-1;
            else
                cTS = cTS - 1;

end
    always @(posedge rst)
        begin
            cMin <= 0;
            cTS <= 0;
            cSec <= 0;
            cTenths <= 0;
        end
endmodule 
模块BCD计数(en、clk、rst、方向、cTenths、cSec、cTS、cMin);
输入en、clk、rst、方向;
输出[3:0]cTenths,cSec,cTS,cMin;
注册号[3:0]cTenths、cSec、cTS、cMin;
始终@(posedge clk)
如果(英文)
开始
如果(方向==0)
如果(cMin==4'b 1001)

cMin根据您的缩进结构,这段代码看起来应该是这样的

  ...
        if(cTS == 4'b 0101)
            cTS <= 4'b 0000;
            cMin = cMin +1;
                if(cTenths == 4'b 1001)
  ...
编辑:
同样值得注意的是,您正在混合阻塞(
=
)和非阻塞(
您需要围绕每个if-else开始结束)。查看此链接中的最后一个示例:SO还将重置逻辑放在一个单独的always块中,这对RTL来说是一个很大的禁忌。它应该移动到一个always块中:
always@(posedge clk,posedge rst)begin if(rst)开始/*在此重置代码*/end else begin/*此处顺序代码*/end end
  ...
        if(cTS == 4'b 0101)
        begin
            cTS <= 4'b 0000;
            cMin = cMin +1;
                if(cTenths == 4'b 1001)
            ...
        end
        else
  ...