Author Topic: VHDL Lexical help; Multi-dimensional arrays  (Read 4919 times)

0 Members and 1 Guest are viewing this topic.

Offline McPeteTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: au
  • Layout Designer, AKA eCAD monkey
VHDL Lexical help; Multi-dimensional arrays
« on: October 23, 2011, 03:58:14 am »
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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12252
  • Country: us
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #1 on: October 23, 2011, 04:35:02 am »
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.
 

Offline McPeteTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: au
  • Layout Designer, AKA eCAD monkey
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #2 on: October 23, 2011, 06:20:40 am »
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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12252
  • Country: us
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #3 on: October 23, 2011, 06:39:44 am »
Ah, I see.

So if your switches represent an 'A' then you have a dot matrix that looks something like this:
Code: [Select]
.....
..X..
.X.X.
XXXXX
X...X
X...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.
 

Offline armandas

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
    • My projects
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #4 on: October 23, 2011, 10:23:26 am »
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: [Select]
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.
 

Offline McPeteTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: au
  • Layout Designer, AKA eCAD monkey
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #5 on: October 23, 2011, 11:26:15 pm »
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 is count and ascii tacked end-to-end. I think that's what your example is showing, but if you could clarify that, I'd appreciate it.

P.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Was it really supposed to do that?
 

Offline armandas

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
    • My projects
Re: VHDL Lexical help; Multi-dimensional arrays
« Reply #7 on: October 24, 2011, 07:15:32 am »
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 is count and ascii tacked end-to-end. I think that's what your example is showing, but if you could clarify that, I'd appreciate it.

Both 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: [Select]
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 code

new_vector <= count & ascii;

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf