Search code examples
verilogquartus

7-segment display with hex output


I am trying to utilize a 7-segment display. I have written a module which I want to take 4 inputs and change the hex output. There seems to be an issue with unpacked/packed arrays. Any help is appreciated.

module hexDisplay (hex, c0, c1, c2, c3);
    input c0;
    input c1;
    input c2;
    input c3;      
    output hex [6:0];       
    reg out [6:0];
 
    always@(*)
    begin
        case({c3, c2, c1, c0})
            4'b0000:out [5:0] = 1;
            // 0001-1111 go here
            //...
            default:out [6:0] = 0;
         endcase
      assign hex = out;
     end
endmodule

Errors:

Error (10773): Verilog HDL error at lab2pre.v(55): declaring module ports or function arguments with unpacked array types requires SystemVerilog extensions Error (10133): Verilog HDL Expression error at lab2pre.v(61): illegal part select of unpacked array "out"

Error (10133): Verilog HDL Expression error at lab2pre.v(62): illegal part select of unpacked array "out"

Error (10048): Verilog HDL error at lab2pre.v(64): values cannot be assigned directly to all or part of array "hex" - assignments must be made to individual elements only

Error (10137): Verilog HDL Procedural Assignment error at lab2pre.v(64): object "hex" on left-hand side of assignment must have a variable data type

Error (10044): Verilog HDL error at lab2pre.v(64): expression cannot reference entire array "out"

Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 6 errors, 1 warning Error: Peak virtual memory: 959 megabytes Error: Processing ended: Tue Feb 2 17:33:35 2016 Error: Elapsed time: 00:00:15 Error: Total CPU time (on all processors): 00:00:46

Error (293001): Quartus II Full Compilation was unsuccessful. 8 errors, 1 warning


Solution

  • 2 Errors :

    • You need to have "packed" array rather than an "unpacked" array for "out" & "hex" nets.

      SystemVerilog supports both packed arrays and unpacked arrays of data. The term packed array is used to refer to the dimensions declared before the data identifier name. The term unpacked array is used to refer to the dimensions declared after the data identifier name.

      bit [7:0] c1; // packed array of scalar bit types real u [7:0]; // unpacked array of real types

      A packed array is a mechanism for subdividing a vector into subfields, which can be conveniently accessed as array elements. Consequently, a packed array is guaranteed to be represented as a contiguous set of bits.

      An unpacked array may or may not be so represented. A packed array differs from an unpacked array in that, when a packed array appears as a primary, it is treated as a single vector.

      So in the code, you require, out & hex to be used as a continuous bit vector, then it should be packed array, instead of unpacked array.

      Refer to topic 7.4 of the Systemverilog LRM.

    • assign statement to hex, cannot be with in always block. Because an assign statement is used for modeling only combinational logic and it is executed continuously. So the assign statement is called 'continuous assignment statement' as there is no sensitive list.

      So it can't be within always block, which is executed as per sensitivity list.

    So your final working code is as below:

    module hexDisplay(hex, c0, c1, c2, c3);
        input c0;
        input c1;
        input c2;
        input c3;      
        output [6:0] hex;       
        reg [6:0] out;
    
        always@(*)
        begin
            case({c3, c2, c1, c0})
                4'b0000:out [5:0] = 1;
                // 0001-1111 go here
                //...
                default:out [6:0] = 0;
             endcase
         end
    
        assign hex = out;
    endmodule