Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment enumeration type in VHDL

In vhdl I can define my own enumeration type and create a signal of this type:

type tp is (red,green,blue,yellow);
signal sg: tp := red;

But now I want a for loop to run over all of these states. Something like

for i in sg'min to sg'max loop
   <something>
end loop;

In c++ there are iterators for this purpose. But in VHDL all I can find is sg'pos that converts the signal to a number that I can increment. But I cannot seem to find a way to convert the number back to a signal.

like image 740
Gunter Königsmann Avatar asked Oct 31 '25 09:10

Gunter Königsmann


1 Answers

This is what you need:

for i in tp'left to tp'right loop
   <something>
end loop;

`left and `right are called type attributes. They are useful in your testbench, but not recommended for your design. This is because you the synthesiser may change the order of the enumerations, which might cause you problems.

like image 111
Matthew Taylor Avatar answered Nov 03 '25 11:11

Matthew Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!