Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using names to refer to bits in unsigned types - VHDL

Status
Not open for further replies.

kureigu

Member level 2
Joined
Jan 14, 2013
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Scotland
Activity points
1,779
I was wondering if it was possible to set up a type in which I can address particular bits of an Unsigned signal using pre-defined names, like you might do with a type when setting up a state machine.

For example, If I had..
Code:
signal my_sig: unsigned(0 to 2)
Is it possible to set something up to enable me to do my_sig(X) <= value; to assign a value to my_sig(0)? And similarly for bit 1 and 2 using Y and Z respectively?

I was hoping doing this would just make it easier for me to keep track of signals that apply to certain buses, but I want grouped.
 

I dont quite understand what you mean - my_sig(0) is pretty clear. Otherwise you can just set up a constant to do it:

constant INDEX_X : integer := 0;

my_sig(INDEX_X) <= value;

or if you want to completly diversify, use an alias:

alias bit_0 : std_logic is my_sig(0);

bit_0 <= value;

Another point to note is if you're doing this, why are you using the unsigned type. Are you doing arithmatic on it later? also, unsigned types should always be decalred (N downto 0) to ensure arithmatic is done correctly.
 

You have at least two ways to do this:


Code VHDL - [expand]
1
2
3
constant X : integer := 0;
...
my_sig(X) <= value;




Code VHDL - [expand]
1
2
3
alias my_name_for_bit_0 : std_logic is my_sig(0);
...
my_name_for_bit_0 <= value;

 
Excellent, thanks very much!


Another point to note is if you're doing this, why are you using the unsigned type. Are you doing arithmatic on it later? also, unsigned types should always be decalred (N downto 0) to ensure arithmatic is done correctly.

It was just an example, I tend to use X downto 0 for all things that require arithmetic anyway.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top