VHDL Lexical help; Multi-dimensional arrays - Page 1
Forum section: electronics / beginners

author: McPete
author_rank: Regular Contributor
timestamp: October 23, 2011, 03:58:14 am
content: Hey all,I'm working through a small synchronous design in VHDL, and I've come to a point where I need to test where the output of a counter against the position of some switches is to produce an output.Someone suggested I use a two-dimensional array to merge the data from the switches (an external device) with the output of my counter entity (an internal signal in another ENTITY/ARCHITECTURE/PROCESS statement). How do I declare such an array?Thanks!p.

author: IanB
author_rank: Super Contributor
timestamp: October 23, 2011, 04:35:02 am
content: A two dimensional array is a square or rectangular matrix. Is that really what you need or want? (Just checking here)At the risk of seeming unhelpful, let me do that classic thing on forums and not answer your question (I can't anyway as I don't know VHDL), but instead let me ask for a little more background into the problem. It could be that there is a simpler way to proceed.When you say "counter" that implies a single value. It seems you want to compare this against other values defined by some switches (one other value or several?). Your job therefore would be to encode the switch positions into the value or values you want to compare.I can see how an array or matrix might be used to encode switch positions into a value, but another method might be to perform a scaled addition. For example, the binary value 10011 is equal to 10000 + 10 + 1 (where 1 and 0 would represent switches set or unset). If you had binary encoding in your switches you could take each switch position, scale it by a suitable factor and then add them all together.

author: McPete
author_rank: Regular Contributor
timestamp: October 23, 2011, 06:20:40 am
content: Hi Ian,What I have is a three bit array from a Mod-5 counter clocked at 38kHz, and a set of selector switches (not sure if I'll use 7 or just 4 on my demo board...).What I need to do is relate the switch position (which defines an ASCII character) and the counter output (which indicates the row of the display being strobed) so than I can generate the appropriate row output. For reference, the display in question is a 5x7 LED matrix. I'm open to other ideas, but the multi-dimensional array, used functionally as a look-up table, was what first occurred to me.

author: IanB
author_rank: Super Contributor
timestamp: October 23, 2011, 06:39:44 am
content: Ah, I see.So if your switches represent an 'A' then you have a dot matrix that looks something like this:Code:.......X...X.X.XXXXXX...XX...X.....And you want to pull off each row one by one to output to the LED display?So yes, a lookup table seems to be the obvious way to go about it. I guess you have to store the dot matrix pattern data somewhere in order to read it out into the display.Since I have no clue about VHDL it needs someone else to chime in with specific information about how to do it.

author: armandas
author_rank: Frequent Contributor
timestamp: October 23, 2011, 10:23:26 am
content: I read your messages a few times and I'm still not sure if I understand what you want to do. I'll try anyway.If you want to select a character using switches and then display it on the LED matrix, you don't need to "test" anything. Use the switches to determine the start address of each character and the counter value to select the appropriate row.You can store the characters in an array like so [full example]:Code:type rom_type is array(0 to 13) of std_logic_vector(4 downto 0);constant FONT: rom_type :=("00000", --"00100", -- #"01010", -- # #"11111", -- #####"10001", -- # #"10001", -- # #"00000", --"00000", --"00100", -- ###"01010", -- # #"11111", -- ###"10001", -- # #"10001", -- ###"00000", --)Then you know that 'A' starts at 0 and 'B' starts at 7 and so on.The active row will be defined by the counter value (assuming that's what the counter is for). You know that the LED matrix has 7 rows and that each row can be addressed using 3 bits. Now all you have to do is to take the 3 lower bits of the counter and combine with the switch value to get the correct row:full address = character start address (switch value) + row address (counter value)Hope this helps.

author: McPete
author_rank: Regular Contributor
timestamp: October 23, 2011, 11:26:15 pm
content: Hi Armandas,My main question was on HOW to declare a vector that had two components- How do I explain to my compiler that this new vector iscountandasciitacked end-to-end. I think that's what your example is showing, but if you could clarify that, I'd appreciate it.P.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: October 24, 2011, 12:22:57 am
content: http://www.edaboard.com/thread30735.html

author: armandas
author_rank: Frequent Contributor
timestamp: October 24, 2011, 07:15:32 am
content: Quote from: McPete on October 23, 2011, 11:26:15 pmBoth count and ascii should be of type std_logic_vector, so you don't need to do anything special. Just choose the appropriate length for the new vector. For example:Code:signal count: std_logic_vector(4 downto 0);signal ascii: std_logic_vector(2 downto 0);signal new_vector: std_logic_vector(7 downto 0);-- then in the codenew_vector <= count & ascii;