Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use generic parameters that depend on other generic parameters for entities?

Tags:

syntax

vhdl

I am trying to convert some Verilog code that produces a slower clock from a faster clock for a UART module. The original verilog code is based on the module over at fpga4fun.com, and this is my attempt to translate it for my VHDL-based design.

entity baud_generator is
generic(
    f_clk : integer := 50000000;  -- default: 50 MHz
    baud  : integer := 115200;    -- default: 115,200 baud
    accum_width : integer := 16;
    accum_inc : integer := (baud sll accum_width) / f_clk
);
port(
    clock : in std_logic;
    reset_n : in std_logic;
    enable : in std_logic;
    baud_clock : out std_logic
);  
end entity baud_generator;

However, my compiler, Aldec-HDL, doesn't like the following line:

 accum_inc : natural := (baud sll accum_width) / f_clk

Here is the exact error message:

 # Error: COMP96_0300: baud_generator.vhd : (20, 52): Cannot reference "f_clk" until the interface list is complete.
 # Error: COMP96_0300: baud_generator.vhd : (20, 28): Cannot reference "baud" until the interface list is complete.
 # Error: COMP96_0071: baud_generator.vhd : (20, 28): Operator "sll" is not defined for such operands.
 # Error: COMP96_0104: baud_generator.vhd : (20, 27): Undefined type of expression.
 # Error: COMP96_0077: baud_generator.vhd : (20, 27): Assignment target incompatible with right side. Expected type 'INTEGER'.

In verilog, I have something like this:

module baud_generator(
  input clock,
  input reset_n,
  input enable,
  output baud_clock
);
parameter f_clock = 50000000;
parameter baud    = 115200;
parameter accum_width = 16;
parameter accum_inc = (baud << accum_width) / f_clock;
//...
endmodule

What is it that I need to modify in that line to make the compiler happy? Is it possible to use generics chained together like that?

like image 827
Dr. Watson Avatar asked May 24 '11 01:05

Dr. Watson


People also ask

What command can be used to change a generic parameter during?

Synopsys Synplify can set generics from a Tcl command or from the GUI. Go to the menu Options > Configure VHDL Compiler. This menu has an Extract Generics button which will identify the generics and add them to the form, so you can fill in the values.

What command can be used to change a generic parameter during instantiation?

Parameter values can be modified using # delay specification with module instantiation. In Verilog, there are two methods to override a module parameter value during a module instantiation. By using the defparam keyword. And module instance parameter value assignment.

What is type parameters in generics?

In a generic type or method definition, a type parameter is a placeholder for a specific type that a client specifies when they create an instance of the generic type.

What is generic type parameter in c#?

Parameters. The type parameter is a placeholder for a specific type that the client specifies when they create an instance of the generic type. A generic class cannot be used as-is because it is simply a blueprint for that type.


1 Answers

This basically says you cannot do computations with the generic values to caluclate (default values for) other generics.

Just use accum_inc as a constant, not as a generic.

Also, the SLL (shift logic left) operator is meant for bit patterns (unsigned and signed datatypes in the ieee.numeric_std and ieee.numeric_bit packages), not for integers. You can do the same by multiplying by a power of two.

like image 68
Philippe Avatar answered Oct 23 '22 09:10

Philippe