Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

some questions about Verilog from beginner:)

Hi everyone!

Just started to learn Verilog language. Meet the problem in my first more or less serious project. Can you explain me please what does -1:0 mean in:

input [input_width-1:0] x;

and what is the difference between this and, for example, input [input_width+2:0] x;

Also would be grateful if someone explains what does DLY_WIDTH means in this code:

(butterworth IIR example):

parameter INPUT_WIDTH = 12;

parameter COEF_WIDTH = 10;

parameter DLY_WIDTH = 18;

parameter F_BITS = 4; // fractional bits

parameter OUTPUT_WIDTH = 21;

parameter L_BIT = 10 ; // low bit

parameter H_BIT = 30; // high bit

// parameter L_BIT = COEF_WIDTH ; // low bit

// parameter H_BIT = L_BIT + OUTPUT_WIDTH - 1; // high bit

//Port Declaration

input clk;

input clken;

input reset;

// input [INPUT_WIDTH-1:0] x;

// output [OUTPUT_WIDTH-1:0] result; //SBF 17.4

input [11:0] x;

output [20:0] result; //SBF 17.4

//Wire Declaration

wire [OUTPUT_WIDTH-1:0] out_biquad1;

wire [F_BITS-1:0] pzeros;

wire [DLY_WIDTH-1:0] xn;

wire [OUTPUT_WIDTH-1:0] result_w;

wire [COEF_WIDTH-1:0] iir_gain;

wire [OUTPUT_WIDTH+COEF_WIDTH-1:0] gain_out;

//Reg Declaration

reg [DLY_WIDTH-1:0] xn_reg;

// reg [OUTPUT_WIDTH-1:0] result;

reg [20:0] result;

reg [DLY_WIDTH-1:0] in_biquad2;

assign pzeros = 0;

assign iir_gain = GAIN;

assign xn = {x[INPUT_WIDTH-1], x[INPUT_WIDTH-1], x[INPUT_WIDTH-1:0], pzeros[F_BITS-1:0]}; // SBF 14.4

Hope you can help me:)

Alex

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    INPUT_WIDTH and other parameters are simply constant definitions which allow you to easily manage code in case you need to change the value. If you are familiar with C programming, these are similar to a# define

    So, if you have defined INPUT_WIDTH = 12, like in your sample code,

    input [INPUT_WIDTH-1:0] x;

    is exactly the same as

    input [11:0] x;

    and [INPUT_WIDTH+2:0] x;

    is the same as input [14:0] x;

    If you want to change width from 12 to 16, you only modify the parameter line and

    you don't need to keep track of all the places where that value is involved.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    And just to be clear in case you are real new.

    "x" is the name of a signal that come into the chip and [] is telling the code that it is a group of signals, not one signal.

    The value 11:0 (as expalined before) means signals named;

    x11, x10, x9, ... x1, x0 (12 elements) - so this is a bus or signals into the design, a vector.

    You may already get that part - but I though I wold be real complete for you (and others who read this).