Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

Function to_unsigned returns only zeros

Hello,

I'm programming a FIR Filter in VHDL and I want to insert stuck on errors in the taps.. so, I did this:


SIGNAL    tap0, tap1, tap2, tap3 : INTEGER :=0 ;
SIGNAL    error : INTEGER :=0;  -- other problem if I don't initialize them with "0", the test bench won't run.
SIGNAL    tap3std : std_logic_vector(to_unsigned(tap3, 8));
SIGNAL    tap_error : to_integer(unsigned(std_logic_vector(to_unsigned(error, 8)) or tap3std));
p1 : process
  begin
    --here I put the equations for the FIR Filter, it works perfectly if I don't try to put any errors.
  end process;

In the test bench I change the values in the taps and everything, but when I look the results, the tap3 signal works properly... but the tap3std is only zeros. :confused:

Does anyone know how to fix this?

Thank you,

Helder. :)

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    SIGNAL tap3std : std_logic_vector(to_unsigned(tap3, 8));

    --- Quote End ---

    In the declaration you should give the size of the vector, not the initial value:

    SIGNAL tap3std : std_logic_vector(15 downto 0);

    In this example tap3std has 16 bits. You can give an initial value to a signal that is a register.

    The only exception are the testbenches where you can do that. This initial value is assigned in the reset condition:

    process(clk)

    begin

    if( rst = '1' ) then

    tap3std <= std_logic_vector(to_unsigned(....

    elsif( clk'event and ....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    instead of posting just a snippet, which is riddled with errors, why not post the real code?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Oh, hi!

    I solved the problem! You're right, Tricky, I'm sorry for that. My problem was that I declared the "tap_error" signal outside of the architecture, not only out of the process. It made the signal work as a constant. Now that I changed it, it works.

    Thank you, guys!