Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Configurable case loop in verilog

Status
Not open for further replies.

pawangupta

Junior Member level 1
Joined
Jul 10, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
bangalore
Activity points
1,399
Hi all,

I want to write a configurable verilog code of case statement....please help me, if any idea...

Example_1:
In this simple example, i know how many case expressions may exist in my case loop...4:

parameter COUNT_WIDTH = 4

case (COUNT_WIDTH)
4'b0001: something;
4'b0010: something;
4'b0100: something;
4'b1000: something;
default: something;
endcase

But at latter time, user defined COUNT_WIDTH = 15, how can i write this configurable requirement in verilog HDL so that i need not to modify my RTL when user requirements changes.

CONFIGURABLE CASE LOOP ?????
 

Hi,

I'm not quite sure, whether I understand your question correct or not.

I think you could generate different case statements depending on your parameter

e.g.

Code:
  generate
    if ( COUNT_WIDTH == 1 )
     begin : GEN_CW_1
        case (counter)
        1'b1: something;
        1'b0: something;
        default: something;
        endcase
     end
    else if ( COUNT_WIDTH == 4 )
     begin : GEN_CW_4
        case (counter)
        4'b0001: something;
        4'b0010: something;
        4'b0100: something;
        4'b1000: something;
        default: something;
        endcase
     end
...
    else if ( COUNT_WIDTH == 15 )
     begin : GEN_CW_15
        case (counter)
        15'h0001: something;
        15'h0002: something;
        15'h0003: something;
        15'h0004: something;
        ...
        15'h7fff: something;
        default: something;
        endcase
     end
    else
     begin : GEN_DEFAULT
     end
  endgenerate

or you could extend to your maximum case with and do something like this

Code:
parameter COUNT_WIDTH = 4

reg [COUNT_WIDTH-1:0] counter;

wire [15:0] extended_counter;

assign extended_counter = {{(16-COUNT_WIDTH){1'b0}},counter}

case (extended_counter)
16'h0001: something;
16'h0002: something;
16'h0003: something;
16'h0004: something;
...
16'hffff: something;
default: something;
endcase

regards
 

the first solution pointed out by qieda works. yet, i really couldnt understand what you were actually trying to do. please ttry to explain better what u are trying to do, perhaps a better solution exists.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top