[Help] Lỗi code verilog viết bằng Quatus 9!!!

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • dinale
    Thành viên chính thức
    • Mar 2011
    • 41

    #1

    [Help] Lỗi code verilog viết bằng Quatus 9!!!

    Các bạn xem giúp mình sao dịch đoạn code này nó cứ báo lỗi hoài. Chả hiểu sao nữa
    PHP Code:
    // main module
    module hello(Clk, HEX0, HEX1, HEX2, HEX3);
    input Clk;
    output [6:0]HEX0,HEX1,HEX2,HEX3;
    reg[2:0] x;
    
      clock1Hz a(Clk, clock);
      always @(posedge clock)
       begin   
       x = x + 1; 
       if (x > 3'b111)  x = 0;
       always @(x)
        begin
         case(x)
          3'b000: state0 s0( HEX0, HEX1, HEX2, HEX3)
          3'b001: state1 s1( HEX0, HEX1, HEX2, HEX3)
          3'b010: state2 s2( HEX0, HEX1, HEX2, HEX3)
          3'b011: state3 s3( HEX0, HEX1, HEX2, HEX3)
          3'b100: state4 s4( HEX0, HEX1, HEX2, HEX3)
          3'b101: state5 s5( HEX0, HEX1, HEX2, HEX3)
          3'b110: state6 s6( HEX0, HEX1, HEX2, HEX3)
          3'b111: state7 s7( HEX0, HEX1, HEX2, HEX3)
         endcase
        end
      end
    endmodule
     
    
     // bo chia tan
    module clock1Hz(Clk, clock1);    
      input  Clk;
      output reg clock1; // xung 1 Hz
      reg [24:0]count ;
      
      always @(posedge Clk)
       begin
        count = count + 1;
        if (count==25000000) 
           begin clock1  = ~clock1;  
                 count = 0;
           end
       end
     endmodule 
    
    // state 0
     module state0( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b0001001;    //H
    endmodule
    // state 1
     module state1( HEX00, HEX11, HEX22, HEX33);
    
     output[6:0] HEX0, HEX1, HEX2, HEX3;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b0001001;    //H
        assign HEX00=7'b0000110;    //E
    endmodule
     // state 2
     module state2( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b0001001;    //H
        assign HEX11=7'b0000110;     //E
        assign HEX00=7'b1000111;    //L
    endmodule
     // state 3
     module state3(HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b0001001;    //H
        assign HEX22=7'b0000110;    //E
        assign HEX11=7'b1000111;    //L
        assign HEX00=7'b1000111;    //L
    endmodule
     // state 4
     module state4( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b0000110;     //E
        assign HEX22=7'b1000111;    //L
        assign HEX11=7'b1000111;    //L
        assign HEX00=7'b1000000;    //O
    endmodule
     // state 5
     module state5( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000111;    //L
        assign HEX22=7'b1000111;    //L
        assign HEX11=7'b1000000;    //O
        assign HEX00=7'b1111111;    //OFF
    endmodule
     // state 6
     module state6( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000111;    //L
        assign HEX22=7'b1000000;    //O
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b1111111;    //OFF
    endmodule
    // state 7
     module state7( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000000;    //O
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b1111111;    //OFF
    endmodule 
    
    nó báo lỗi như vầy nè:
    PHP Code:
    Error (10170): Verilog HDL syntax error at hello.v(12) near text "always";  expecting "end"
    Error (10170): Verilog HDL syntax error at hello.v(15) near text "s0";  expecting "<=", or "="
    Error (10170): Verilog HDL syntax error at hello.v(16) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(17) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(18) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(19) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(20) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(21) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(22) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(23) near text "endcase";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(46) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(48) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(55) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(57) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(64) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(66) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(73) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(75) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(82) near text ")";  expecting ":", or "," 
    
    Mong các bạn giúp đỡ. Cảm ơn trước.
  • phuongnhoc
    Thành viên tích cực
    • Mar 2006
    • 122

    #2
    Nguyên văn bởi dinale Xem bài viết
    Các bạn xem giúp mình sao dịch đoạn code này nó cứ báo lỗi hoài. Chả hiểu sao nữa
    PHP Code:
    // main module
    module hello(Clk, HEX0, HEX1, HEX2, HEX3);
    input Clk;
    output [6:0]HEX0,HEX1,HEX2,HEX3;
    reg[2:0] x;
    
      clock1Hz a(Clk, clock);
      always @(posedge clock)     
       begin   
       x = x + 1; 
       if (x > 3'b111)  x = 0;
       always @(x)      ==> Thứ nhất: Hai khối always lồng vào nhau = Lỗi
        begin
         case(x)
          3'b000: state0 s0( HEX0, HEX1, HEX2, HEX3)    ==> Thứ hai: Trong khối always gọi thể hiện của module = Lỗi
          3'b001: state1 s1( HEX0, HEX1, HEX2, HEX3)
          3'b010: state2 s2( HEX0, HEX1, HEX2, HEX3)
          3'b011: state3 s3( HEX0, HEX1, HEX2, HEX3)
          3'b100: state4 s4( HEX0, HEX1, HEX2, HEX3)
          3'b101: state5 s5( HEX0, HEX1, HEX2, HEX3)
          3'b110: state6 s6( HEX0, HEX1, HEX2, HEX3)
          3'b111: state7 s7( HEX0, HEX1, HEX2, HEX3)
         endcase
        end
      end
    endmodule
     
    
     // bo chia tan
    module clock1Hz(Clk, clock1);    
      input  Clk;
      output reg clock1; // xung 1 Hz
      reg [24:0]count ;
      
      always @(posedge Clk)
       begin
        count = count + 1;
        if (count==25000000) 
           begin clock1  = ~clock1;  
                 count = 0;
           end
       end
     endmodule 
    
    // state 0
     module state0( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b0001001;    //H
    endmodule
    // state 1
     module state1( HEX00, HEX11, HEX22, HEX33);
    
     output[6:0] HEX0, HEX1, HEX2, HEX3;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b0001001;    //H
        assign HEX00=7'b0000110;    //E
    endmodule
     // state 2
     module state2( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1111111;    //OFF
        assign HEX22=7'b0001001;    //H
        assign HEX11=7'b0000110;     //E
        assign HEX00=7'b1000111;    //L
    endmodule
     // state 3
     module state3(HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b0001001;    //H
        assign HEX22=7'b0000110;    //E
        assign HEX11=7'b1000111;    //L
        assign HEX00=7'b1000111;    //L
    endmodule
     // state 4
     module state4( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b0000110;     //E
        assign HEX22=7'b1000111;    //L
        assign HEX11=7'b1000111;    //L
        assign HEX00=7'b1000000;    //O
    endmodule
     // state 5
     module state5( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000111;    //L
        assign HEX22=7'b1000111;    //L
        assign HEX11=7'b1000000;    //O
        assign HEX00=7'b1111111;    //OFF
    endmodule
     // state 6
     module state6( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000111;    //L
        assign HEX22=7'b1000000;    //O
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b1111111;    //OFF
    endmodule
    // state 7
     module state7( HEX00, HEX11, HEX22, HEX33);
     
     output[6:0] HEX00, HEX11, HEX22, HEX33;
        assign HEX33=7'b1000000;    //O
        assign HEX22=7'b1111111;    //OFF
        assign HEX11=7'b1111111;    //OFF
        assign HEX00=7'b1111111;    //OFF
    endmodule 
    
    nó báo lỗi như vầy nè:
    PHP Code:
    Error (10170): Verilog HDL syntax error at hello.v(12) near text "always";  expecting "end"
    Error (10170): Verilog HDL syntax error at hello.v(15) near text "s0";  expecting "<=", or "="
    Error (10170): Verilog HDL syntax error at hello.v(16) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(17) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(18) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(19) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(20) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(21) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(22) near text "3";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(23) near text "endcase";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(46) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(48) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(55) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(57) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(64) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(66) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(73) near text ")";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(75) near text ";";  expecting ":", or ","
    Error (10170): Verilog HDL syntax error at hello.v(82) near text ")";  expecting ":", or "," 
    
    Mong các bạn giúp đỡ. Cảm ơn trước.
    Mình coi sơ qua và thấy 3 lỗi. 2 lỗi đã note ở trên, một lỗi là tín hiện được gán trong phép gán non-blocking thì cần được khai báo reg. ==> Các lỗi này phát sinh do chưa quen thiết kế phần cứng. cần hình dung thiết kế phần cứng không giống lập trình C. Bạn nên tham khảo code mẫu trước khi thiết kế

    Comment

    • thegioi21mas
      Thành viên chính thức
      • Oct 2009
      • 42

      #3
      theo mình thấy thì toàn là lỗi do cú pháp thôi. bạn có thể debug từ từ là ra.
      mây cái lỗi cơ bản nhất thì bạn phuongnhoc da chi ra roi.
      mình chỉ góp ý là nếu bạn muốn gọi module lại như vậy thì ko được, mà phải dùng task.
      còn cái khối always cho x thì không cần thiết đâu
      Thân

      Comment

      • phuongnhoc
        Thành viên tích cực
        • Mar 2006
        • 122

        #4
        Bài tập này giống bài tập xuất chữ HELLO lên Hex 7 segment trên Kit DE2. Bạn tham khảo theo link sau:

        Comment

        • dinale
          Thành viên chính thức
          • Mar 2011
          • 41

          #5
          Nguyên văn bởi thegioi21mas Xem bài viết
          mình chỉ góp ý là nếu bạn muốn gọi module lại như vậy thì ko được, mà phải dùng task.
          còn cái khối always cho x thì không cần thiết đâu
          Thân
          dùng task như thế nào hả bạn?
          Tại sao dùng alway cho x ko cần thiết?
          mình mới bập bẹ học verilog, bạn giúp nình với.

          Comment

          • thegioi21mas
            Thành viên chính thức
            • Oct 2009
            • 42

            #6
            Bạn có thể down các ebook về verilog sẽ có nói về cái này
            http://www.mediafire.com/?d9ma23q7r6m6wfc
            Dùng task sẽ cho phép bạn gọi lại trong khối always chứ nếu viết riêng 1 module rồi gọi lại trong always thì verilog không cho phép, khi tìm hiểu về task có lẽ bạn sẽ gặp thêm 1 cái nữa là function(khá thú vị). Lúc đó bạn cần phải biết phân biệt 2 cái task và function khi sử dụng. Còn về cái x, mình cho rằng không cần dùng always @(x) vì làm vậy không có ý nghĩa gì cả.
            Có vấn đề này mình muốn hỏi là, hình như bạn đang suy nghĩ là cứ dùng always thì sẽ là mạch tuần tự thì phải?
            Thân

            Comment

            • dinale
              Thành viên chính thức
              • Mar 2011
              • 41

              #7
              Mình đã hiểu. Cảm ơn các bạn rất nhiều.

              Comment

              Về tác giả

              Collapse

              dinale Tìm hiểu thêm về dinale

              Bài viết mới nhất

              Collapse

              Đang tải...