top of page

Generics

In VHDL, generics are used in the same way as parameters in Verilog. They allow us to make a design flexible instead of hardcoding values. With generics, we can adjust things like data width, bus width, address size, integer limits, or any signal characteristic according to our requirement. This gives flexibility so that the same design can work for different values without rewriting the code.

 

Earlier this was only a 4-bit up/down counter, 

but now by using a generic it has been turned into an N-bit counter. 

The width of the counter can now be chosen freely through the generic N.

VHDL

The main idea of a generic is to make the design architecture generalized. In the code you can see that the counter has now been turned into an N-bit counter, which means it can work with different widths instead of being fixed. A generic is always written inside the entity, and its syntax looks like this:

​

generic (

  N : integer := <parameterized value>

);

​

Let’s assume we want to convert into 8 bit counter then what to do

VHDL

We’ve already covered the elaborated diagram, synthesis, and simulation in the first article. Here, I’m adding the testbench code, which I hadn’t included earlier.

Test Bench code:

VHDL

Simulation:

GAG1.png

For more Clarity:

You can see values of counter below of above diagram:

GAG2.png

Generate:

The generate statement in VHDL is used when we want to repeat the same logic many times inside a large design. Instead of writing the same code again and again for each replica of a component, we write it once inside a generate block, and the hardware is automatically created multiple times based on that logic.

​

In Verilog, the generate for loop is used to repeat the same logic multiple times, just like in VHDL. Instead of writing the same module instantiation or the same block of code again and again, we can write it once inside a generate–for loop, and the compiler automatically creates multiple copies of the hardware. This makes the design shorter, cleaner, and easier to scale for larger sizes.

​

In a large design, we can use a generate loop in two ways. We can either write the complete logic directly inside the generate block, or we can write that logic as a separate entity or component and then instantiate it inside the generate loop with port mapping. In both cases, the hardware will be created as many times as the loop runs.

First way:

VHDL

Elaborated Diagram:

GAG3.png

Second way:

​

​Entity:

VHDL

Multiple Counters in top

VHDL

Elaborated Diagram:

GAG4.png

Expanded :

GAG5.png

The single-counter expansion is RTL-equivalent to the first approach, but the first approach is more hardware-efficient. For the same functionality, the second approach uses four multiplexers, whereas the first uses only.

Package and library

Records in VHDL

© Copyright 2025 VLSI Mentor. All Rights Reserved.©

Connect with us

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
bottom of page