EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL Code works, need help with testbench and isim


von Tai T. (john9686)


Attached files:

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;

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


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

von Tai T. (john9686)


Attached files:

Rate this post
useful
not useful
just copy pasted the testbench.vhd to notepad. here is orginal 
testbench.vhd.

constant A: unsigned(9 downto 0):=("0110101001"); -- A=425
does not work. Is the error coming from my testbench code?
In the image attached the clock is default 0

von Duke Scarring (Guest)


Attached files:

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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.