VHDL Code help

OP #3435989
Rate this post
• ▲ useful
▼ not useful
Ok so when I run Isim through xilink I get this:

Simulator is doing circuit initialization process.
at 0 ps, Instance /testbench/uut/ : Warning: NUMERIC_STD."<": metavalue 
detected, returning FALSE
ERROR: In process functionT.vhd:25
 Target Size 10 and source size 20 for array dimension 0 does not match.


Is it referring to "z <= y * 3;" ????


Code:
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4

5
entity functionT is
6
    port(
7
        clk: in std_logic;
8
        switches: in std_logic_vector(9 downto 0);
9
        output: out std_logic_vector(9 downto 0)
10
    );
11
end functionT;
12

13
architecture ARCH of functionT is
14
--signals
15
constant A: unsigned(9 downto 0):=("0110101001"); -- A=425
16
signal B: unsigned(9 downto 0);
17
signal sig512: unsigned(9 downto 0):=("1000000000");
18
signal T: unsigned(9 downto 0);
19
signal x, y, z: unsigned(9 downto 0);
20

21
begin
22
    B <= unsigned(switches); --something like that
23
    x <= A when A>sig512 else sig512;
24
    y <= x when x<B else B;
25
    z <= y * 3;
26
    T <= z(7 downto 0) & "00";
27
    output <= std_logic_vector(T);
28
end ARCH;
Attached files:
OP #3436332
Rate this post
• ▲ useful
▼ not useful
Thanks I have it working. The only problem now is how to divide the "T" 
by 4 so I get the right "output". With this code T=672 and ouput=672, 
168 is the correct output meaning I need to divide by 4.


CODE:
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4

5
entity functionT is
6
    port(
7
        clk: in std_logic;
8
        output: out std_logic_vector(19 downto 0)
9
    );
10
end functionT;
11

12
architecture ARCH of functionT is
13
--signals
14
signal A: unsigned(9 downto 0):=("0110101001"); -- A=425
15
signal B: unsigned(9 downto 0):=("0011100000"); -- B=224
16
signal sig512: unsigned(9 downto 0):=("1000000000"); -- sig512=512
17
signal T: unsigned(19 downto 0);
18
signal x, y: unsigned(9 downto 0);
19
signal z: unsigned(19 downto 0);
20

21
begin
22
    x <= A when A>sig512 else sig512; --Maximum
23
    y <= x when x<B else B; --Minimum
24
    z <= y * 3;
25
   T <= z(17 downto 0) & "00";
26
    output <= std_logic_vector(T);
27
end ARCH;
Moderator (Company: Titel) #3436375
Rate this post
• ▲ useful
▼ not useful
Tai Tai wrote:
> The only problem now is how to divide the "T" by 4
Why don't you simply try it this way:  output <= std_logic_vector(T/4);
That will work, because an unsigned division by 4 is just "truncating 
the last two bits"...


BTW: why not using integer datatypes?
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4

5
entity functionT is
6
port(
7
  clk: in std_logic;
8
  inA: in std_logic_vector(19 downto 0),
9
  inB: in std_logic_vector(19 downto 0),
10
  output: out std_logic_vector(9 downto 0) -- can never be longer than A or B
11
);
12
end functionT;
13

14
architecture ARCH of functionT is
15
--signals
16
signal A: integer := 425; -- initialazation makes no sense
17
signal B: integer := 224; -- because A nd B are not in registers!
18
signal T, x, y: integer;
19

20
begin
21
  -- convert inputs to integers
22
  A <= to_integer(unsigned(inA));
23
  B <= to_integer(unsigned(inB));
24

25
  -- do the calculation
26
  x <= A when A>512 else 512; -- Maximum
27
  y <= x when x<B   else B;   -- Minimum
28
  T <= (y*3)/4;               -- *0.75
29

30
  -- convert back for output
31
  output <= std_logic_vector(to_unsinged(T,10));
32
end ARCH;

For the magic conversions between vectors and integers see the picture 
there:
http://www.lothar-miller.de/s9y/categories/16-Numeric_Std
OP #3437617
Rate this post
• ▲ useful
▼ not useful
Yeah thanks for all your input. This the code I have working perfectly.
Thanks :)

Code:
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4

5
entity functionT is
6
    port(
7
        clk: in std_logic;
8
        output: out std_logic_vector(19 downto 0)
9
    );
10
end functionT;
11

12
architecture ARCH of functionT is
13
--signals
14
signal A: unsigned(9 downto 0):=("0010111001"); -- A=185
15
signal B: unsigned(9 downto 0):=("0100100100"); -- B=292
16
signal sig512: unsigned(9 downto 0):=("1000000000"); -- sig512=512
17
signal x, y: unsigned(9 downto 0);
18
signal z: unsigned(19 downto 0);
19

20
begin
21
    x <= A when A>sig512 else sig512; --Maximum
22
    y <= x when x<B else B; --Minimum
23
    z <= y * 3; --Multiple by 3
24
    output <= std_logic_vector(z/4); --Divide by 4
25
end ARCH;

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.