VHDL Code works, need help with testbench and isim

OP #3435160
Rate this post
• ▲ useful
▼ not useful
Hi!

I'm working on this function. I need some help. Here is my code. It 
works sythesizes and implements the design. When I create a testbench 
using xilink I get the code attached. I add binary value "222" to 
switches in testbench. When I run isim I get the attached image. Whats 
wrong???


T = Min[Max(A,512),B]xC

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
signal A: unsigned(9 downto 0):=("0110101001"); -- A=425
16
signal B: unsigned(9 downto 0);
17
signal sig512: unsigned(9 downto 0):=("1000000000"); --sign512=512
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:
Moderator (Company: Titel) #3435893
Rate this post
• ▲ useful
▼ not useful
> testbench_code.txt
None of my VHDL files end up with ".txt"
Why does yours?

> signal A: unsigned(9 downto 0):=("0110101001"); -- A=425
Because signal A is not in a register, it cannot store the assigned 
default value. So one timestep after the first initialisation the signal 
A will become "UUUUUU...". This results in the reported metavalue. Try 
it this way:
> constant A: unsigned(9 downto 0):=("0110101001"); -- A=425
Guest #3437773
Rate this post
• ▲ useful
▼ not useful
Tai Tai wrote:
> does not work.
You provocate a type mismatch (std_logic_vector vs. unsigned).

With these changes it will work:
1
33c33
2
< --USE ieee.numeric_std.ALL;
3
---
4
> USE ieee.numeric_std.ALL;
5
53c53
6
<    signal switches : std_logic_vector(9 downto 0) :=("0011011110"); --A=222;
7
---
8
>    signal switches : unsigned(9 downto 0) := to_unsigned( 222, 10);
9
66c66
10
<           switches => switches,
11
---
12
>           switches => std_logic_vector( switches),

Duke
Attached files:

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.