0

I need to define parameter values which are dependent on some other input . I tried the following way but it doen't work . any other alternative methods ?

 module (...)
...
input sel ;
..
case (sel)
0: parameter data1 =5;
1: parameter data1 =5;
endcase
...

Thanks

vlsi2013
  • 169
  • 1
  • 2
  • 5
  • Can you post your complete code? It's not clear why you're using a parameter(which is constant) that is dependent on an input port. –  Feb 26 '13 at 14:13

1 Answers1

3

Parameters are constants, therefore can not be changed at runtime and will not work with dynamic structures.

If you need to set values based on inputs, which change during execution and you just need to define a wire or reg of the correct width.

Alternatively for constants you can use hierarchical parameters where you pass values down but they must all be based on parameters or constants.

module top();
  localparam DATA_WIDTH = 32;

  middle #(
    .DATA_WIDTH( DATA_WIDTH )
  ) middle_0();

endmodule

module middle #(
  parameter DATA_WIDTH = -1

  //DO NOT MODIFY
  parameter DATA_OUT_WIDTH = DATA_WIDTH + 10;
)(
  output [DATA_OUT_WIDTH-1:0] data_tx
);
endmodule

For your case:

module (...)
...
input sel ;
..
  reg [3:0] data1;
  always @*
    case (sel)
      0: data1 =5;
      1: data1 =5;
    endcase
  end

endmodule
Morgan
  • 19,934
  • 8
  • 58
  • 84
  • thanks for the help . but i need to define parameter as i have the module written already using parameter . If i change parameter into reg , I would perhaps have to change the whole code ? I tried overloading parameter , But this gives an error as the module being instantiated is not expecting the parameter . Please suggest – vlsi2013 Feb 26 '13 at 12:53
  • If it is being used to define datapath widths then it would not work, if just being used for constants on right hand of assignments then it should work. – Morgan Feb 26 '13 at 12:56
  • Ya, My requirement is just for constants and not to define datapath width – vlsi2013 Feb 26 '13 at 13:02
  • reg will work but if i change to reg , i would have to change other aspects of the code . Anyways will trying out – vlsi2013 Feb 26 '13 at 13:28
  • @ Adam12 - The parameter is dependent on another module . So this constant value is defined from another module . I am restricted to post the code due to ip issues , Also the code is big enough and cannot be posted . So i just gave a sample code. – vlsi2013 Feb 27 '13 at 06:49