Default value for an unconstrained port

vhdl

    Next

  • 1. Simple combinatorial logic consuming major resources?
    Hi, I am currently working on a design using Warp & Galaxy. When I compile, I see: CLOCK/LATCH ENABLE signals 1 Input REG/LATCH signals 0 Input PIN signals 2 Input PINs using I/O cells 0 Output PIN signals 1 Total PIN signals 3 Macrocells Used 12 Unique Product Terms 16 Unique Internal Banked Combs 0 Whan I add this statement: PosFet<=ADStr and BDStr; I get: CLOCK/LATCH ENABLE signals 1 Input REG/LATCH signals 0 Input PIN signals 4 Input PINs using I/O cells 8 Output PIN signals 2 Total PIN signals 14 Macrocells Used 59 Unique Product Terms 346 Unique Internal Banked Combs 0 I must be doing something wrong. If I add another combinatorial statement I get too many Unique Product Terms. Thanks, Robert rz (at) nikola.Skirtcom. Remove your skirt to reply.
  • 2. generate testbench for array signals
    Hey there, i tried to generate a testbench waveform with Xilinx ISE Software - but it seems that it doesnt support array types.... (it wants me to use either bit, bit_vector or integer). i'm using ISE 4.2 - does somebody know if this is better in version 5.2? Thanx, Simone
  • 3. VHDL design and ModelSim
    Hi, the 'lpm' library is missing when i try to compile VHDL code. I am using ModelSim. Any idea where I may find it ? thanks, Vi'
  • 4. another newbie question about vhdl
    the following source has a strange behaviour -----------8<----------------- entity main is Port ( clk : in std_logic; cnt : inout std_logic_vector(2 downto 0); o: out std_logic; en : in std_logic); end main; architecture Behavioral of main is begin process (clk, en) begin if en = '0' then cnt <= (others => '0'); o <= '0'; elsif rising_edge(clk) then cnt <= cnt + 1; if cnt = 1 then o <= '1'; end if; end if; end process; end Behavioral; ------8<--------------- I'm expecting that o goes high at first rising edge of clk, after en goes high. Instead this happens after another clock cycle. Debugging this code I found that cnt is not updated immediatly, is it right? thanks

Default value for an unconstrained port

Postby XYZ » Tue, 18 May 2010 04:42:20 GMT

Hi,

How to set a default value for an unconstrained port? Doing it this way
input : in std_logic_vector;
val : in std_logic_vector := (others => '0');
doesn't work as val'range is not known and obviously I end up with 
ModelSim error "OTHERS choice can not be used in unconstrained array 
aggregate."

I know, however, that val'range should be the same as input'range. Is 
there any way to define a default value for val vector based on input 
(input is constrained by higher entity). I need something like
val : in std_logic_vector := (input'range => '0')

I'm afraid that even if there exist different method than OTHERS to 
create a vector I wouldn't be allowed to use input'range because of 
"object 'input' cannot be used within the same interface as it is 
declared" error.

Is it better to switch to generics rather than use unconstrained ports?

Thanks.

Re: Default value for an unconstrained port

Postby XYZ » Tue, 18 May 2010 04:47:34 GMT



I send the previous post too fast. It turns out that the above is a 
valid VHDL syntax, so please skip the text above. Now, as expected, I 
faced the error given below. Is there anything I can do?

Thanks.

Re: Default value for an unconstrained port

Postby Paul Uiterlinden » Tue, 18 May 2010 07:06:26 GMT




And rightfully so. If you leave an unconstrained port unconnected, what
width is it supposed to be? Or more general: what range should the index
be? It can not be determined from anything.

As a  solutions, what you could do is something like this:

  val : in std_logic_vector := (31 downto 0 => '0');

Now if you leave the port unconnected, it's width shall be 32.

And if you connect it to another signal of any width, it will take over the
index range of that signal.

Sweet and simple.

-- 
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.

Re: Default value for an unconstrained port

Postby XYZ » Tue, 18 May 2010 09:26:04 GMT




I know, I thought it was clear from the post.

I wrote that val is supposed to have input'range. If I do like that:

	input : in std_logic_vector;
	val : in std_logic_vector := (input'range =>  '0');

I get "object 'input' cannot be used within the same interface as it is
declared". In fact this is true that input is declared in the same 
interface but is there any workaround for this, other than using generic 
values?

Re: Default value for an unconstrained port

Postby backhus » Tue, 18 May 2010 15:53:25 GMT




> I wrote that val is supposed to have input'range. If I do like that>
> input : in std_logic_ve>tor;
> val : in std_logic_vector := (in>ut'range>=>>0');
>
> I get "object 'input' cannot be used within the same interfac> as it is
> declared". In fact this is true that input is declared i> the same
> interface but is there any workaround for this, other than usi>g generic
> values?

Hi,
using unconstrained ports will be a problem once you enter the
toplevel.
There are no chips with 'morphing' pacages that automatically adapt to
the socket or pcb, to make this feature useful. :-)

But there is a (pragmatic) solution to your problem.
Write a function instead of a module (entity/architecture).
This functiion can have unconstrained parameters.
And when you want to apply this function in a real circuit you can
write a wrapper module that sets the port sizes and calls the
function.
If you need to do so more often and still want to avoid generics, a
perl script might be usefull that generates the wrappers.

Have a nice synthesis
  Eilert

Re: Default value for an unconstrained port

Postby Jonathan Bromley » Tue, 18 May 2010 17:00:39 GMT


[...]

As the discussion has shown, there doesn't seem to be any direct way
to handle this.  However, how about this as an idea...?

   val: in std_logic_vector(0 downto 1 => '0');  --- null range

Now, if you fail to connect "val", it gets a null-range input.  We
can
detect that inside the design:

  architecture....
     --- Make a signal for "val" that is the known correct size
     signal internal_val: std_logic_vector(input'range);
     ...
  begin
     missing_val_manager: if val'length = 0 generate
       assert false
         report "val not connected, defaulting to all-zero"
         severity note;
       end process;
       --- Make the correct-sized default
       internal_val <= (input'range => '0');
     end generate;
     provided_val_manager: if val'length > 0 generate
       assert val'length = input'length
         report "val was connected but its size doesn't match input"
         severity fatal;
       internal_val <= val;
     end generate;

     (and then, of course, use "internal_val" everywhere in your
design).

I'm pretty confident this is OK for simulation, but the null range
might cause some trouble for synthesis, so there might need to be some
business with synthesis-off pragmas.  Alternatively you could cheat
and set the unconnected default to be one bit wide (0 downto 0) or,
perhaps, some other size that you know will never occur in practice.

VHDL-2008 "if generate else" could make the code just a little neater.

Jonathan Bromley
still trying to pretend he remembers some VHDL
after far too long in SystemVerilog-land....

Re: Default value for an unconstrained port

Postby Paul Uiterlinden » Tue, 18 May 2010 17:58:41 GMT








Sorry, I missed that part. I should not post anything after midnight...

I think Jonathan's suggestion is quite elegant. The only issue might be the
null range (as Jonathan already pointed out for synthesis).

But also for simulation: by default a null-range gives a warning in
ModelSim. That can be suppressed again with the -nowarn 3 option, IIRC.

An alternative would be to use a special value, with bit values that
normally do not occur. For example: (31 DOWNTO 0 => '-'), or
(0 TO 0 => 'U'). This avoids the issue with the null-range warning.

-- 
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.

Re: Default value for an unconstrained port

Postby Andy » Tue, 18 May 2010 23:01:25 GMT

Jonathan,

How would you go about declaring "internal_val" such that it has
either the length of input or the length of val? I think you would
have to declare it with input'range, then resize val as necessary to
fit if val was provided but did not match.

Andy

Re: Default value for an unconstrained port

Postby Andy » Wed, 19 May 2010 01:13:35 GMT

Jonathan,

Unfortunately, declarations within a generate statement are local to
the generate's block, and furthermore, generate statements cannot be
located in the declarative region. This is one glaring limitation to
the generate capability: conditional declarations useable outside the
generate statement.

You could use a function for the declaration initializer of
internal_val...? Similarly to what the OP was doing with unconstrained
ports, declare internal_val as unconstrained SLV, with a function call
to define an initial value which also sets the range of the variable/
signal. I don't think you could replace the generate statements with
the initializer function, since the generate statements created the
correct concurrent assignment also. OK, maybe you could get rid of one
of the generates...

Andy

Re: Default value for an unconstrained port

Postby Jonathan Bromley » Wed, 19 May 2010 04:43:59 GMT




right, although of course you can see the reasoning 
behind that.


That's fine for constants, but surely not for a signal
or variable?


I still think it's OK: the declaration of internal_val would 
be outside any generate, determined by the properties 
of other ports etc (not forgetting that functions can be 
used to determine the values of constants that control 
a signal's declaration).  And then a generate could 
conditionally create a process, in whose declarative 
region there is a function used to build the signal's 
value so that process can duly drive it.

I agree, though, that it's all a bit of a faff.  Probably a 
few generics on the entity would make for a neater job.

Have pity on me.  As I complained earlier, I'm currently
in Verilog land, where such things are not permitted to 
appear even in nocturnal fantasies.
-- 
Jonathan Bromley

Re: Default value for an unconstrained port

Postby Andy » Wed, 19 May 2010 08:14:52 GMT

On May 17, 2:43m, Jonathan Bromley < XXXX@XXXXX.COM >



True, you'd have to use a function to initialize an unconstrained
constant, then you could use the constant's range to declare the
variable/signal.

You have my sympathy. Somehow I think verilog must be more kind to
those who've never known the benefits of VHDL. Otherwise, who would
prefer it? But that's a different thread...

Andy

Similar Threads:

1.How to specify default value to a variable of unconstrained type

Hi Pankaj,
You have to fix the NUMBERofHEADER here as 2 in a package entity. only
then u will be able to compile the same.
Anupam Garg

2.Default values on undriven ports in configuration?

Hi,

I have a signal which has a default value, but is undriven following a
configuration.
One simulator I am using gives the signal the default value. The
testbench I have relies on this.
A different simulator gives the signal a value of U. This causes my
testbench to fail.
Both are "mainstream" simulators.
I have looked in the LRM, and it is not obvious to me which behaviour
is correct.
I would be very grateful as for any advice on this.

(If replying by email, please get rid of the m after ken otherwise it
will be treated as spam)

Many Thanks,

Ken Morrow

A test case which shows the problem:-

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity PARTIAL_DRIVER is
  port (
    FRED : out std_logic_vector(7 downto 0));
end PARTIAL_DRIVER;

architecture TEST of PARTIAL_DRIVER is
begin  -- TEST
  FRED <= "01010101";
end TEST;



entity DEFAULT_VALUE is
end DEFAULT_VALUE;


library IEEE;
use IEEE.STD_LOGIC_1164.all;

architecture TEST1 of DEFAULT_VALUE is
signal FRED : std_logic_vector(7 downto 0);

--DEFAULT_SIGNAL is given a default value:-
signal DEFAULT_SIGNAL : std_logic_vector(7 downto 0) := (others=>'1');
--One simulator retains this default value.
--The other assigns a value of 'U'.

component DRIVER
  port (
    FRED : out std_logic_vector(7 downto 0);
    DEFAULT_SIGNAL : out std_logic_vector(7 downto 0));
end component;

begin  -- TEST

UUT : DRIVER
  port map (
    FRED          => FRED,
    DEFAULT_SIGNAL => DEFAULT_SIGNAL);

end TEST1;

configuration CFG of WORK.DEFAULT_VALUE is
  for TEST1
    for UUT : DRIVER
      use entity work.PARTIAL_DRIVER
        port map (
          FRED => FRED);                --NOTE DEFAULT_VALUE is
undriven
    end for;
  end for;
end CFG;

3.Unconstrained arrays in port : elegant but...

Hi,

It makes me nervous to see "shared variables" in RTL code... As a newbie, you 
probably shouldn't be aware of these beasts anyway ;-)
Shared vars can be very handy in test benches and behavioral models, but they must be 
used with extreme care.
A constant would have done the trick.

Unconstrained arrays in port is IMO a very elegant style, but it doesn't
have only advantages... I'm not sure all the synthesis tool accept this yet either, 
you need to check first before using this style ! Don't rely on manuals, they are 
sometimes unaware of what the tool can do !!! Use the code below (wrap it in a 
sized-ports top level first indeed) to see of it works.

So below is something which I wrote "similar" to your idea (though the function coded 
has nothing to do with a square root. I think there is a synthesizable square root in 
the Synplify examples, but if it's an assignment, write your own solution first).
You can throw this code in your VHDL simulator and see it work (PWM on Cout).

Hope this helps,
   Bert
library IEEE;
   use IEEE.std_logic_1164.all;
   use IEEE.numeric_std.all;

entity pAndG is
   port( A, B  : in  std_logic_vector;
         Plink,
         Glink : out std_logic_vector );
end pAndG;

architecture dummy of pAndG is
begin
   -- just to put something here for the sake of the example
   Plink <= A and B;
   Glink <= A xor B;
end;
-- we ae going to instanciate this entity.

-- ----------------------------------------------
library IEEE;
   use IEEE.std_logic_1164.all;

entity SquareRoot is
   port( A, B : in  std_logic_vector;
         Cin  : in  std_logic;
         Cout : out std_logic;
         Sum  : out std_logic_vector );
end SquareRoot;

library IEEE;
   use IEEE.numeric_std.all;

architecture Dummy of SquareRoot is  -- just for the example !
-- this does nothing interesting, the purpose is only to show how
-- to use unconstrained array and attributes.

constant Width : positive := A'length; -- if you want to use it.

signal Plink, Glink, Slink0, Slink1: std_logic_vector(A'range);
signal Clink0, Clink1: std_logic;
signal Sum1 : std_logic_vector (A'high+1 downto 0);

begin
   -- shows the instanciation of another entity with unconstrained vectors in port
   pg: entity work.pAndG(Dummy) port map (A, B, Plink, Glink); --

   Sum1 <= std_logic_vector (unsigned('0'& A) + unsigned('0'& B));
   Sum  <= Sum1(Sum'range);
   Cout <= Sum1(Sum1'high);
end;

-------simple test bench-----------------
library IEEE;
   use IEEE.std_logic_1164.all;
   use IEEE.numeric_std.all;
entity TB is end;
architecture test of TB is
   signal A,B,Sum : std_logic_vector(5 downto 0);
   signal Cout    : std_logic;
begin
UUT: entity work.SquareRoot port map (A,B,'0',Cout,Sum);
process begin
   A <= (others=>'0');  B <= (others=>'0');
   for i in 0 to 2**A'length-1 loop
     for j in 0 to 2**A'length-1 loop
       A <= std_logic_vector (to_unsigned(i,A'length));
       B <= std_logic_vector (to_unsigned(j,B'length));
       wait for 10 ns;
     end loop;
   end loop;
   wait;
end process;
end test;
----------------------------------

4.Unconstrained array for output port in generic :/

I'm fairly new to generics, consequently I'm having problems :)

I'm trying to create an entity with 'width' bits in and 'nbits'x'width'
bits out. I'm trying to use an unconstrained array to do this, but I'm
getting compile errors...

# ** Error: C:/Modeltech_6.0c/work/srsipo.vhd(34): near "array":
expecting: STRING IDENTIFIER

Any ideas? Thanks.

-Brandon

<SNIP>

library ieee;
use ieee.std_logic_1164.all;
use work.srsipo_pkg.all;

-------------------------------------------------------------------------------
-- ENTITY
-------------------------------------------------------------------------------
entity srsipo is
  generic (
    nbits                 : integer;
    width                 : integer
  );
  port (

---------------------------------------------------------------------------
    -- input
------------------------------------------------------------------
    rst_na                : in  std_logic;
    clk                   : in  std_logic;
    din                   : in  std_logic_vector(width-1 downto 0);
    -- output
-----------------------------------------------------------------
    dout                  : out array (width-1 downto 0)
                            of std_logic_vector(nbits-1 downto 0)

---------------------------------------------------------------------------
  );
end srsipo;

</SNIP>

5.Unconstrained array ports - Good or Bad?

As a newbie to this area I am confused as to the status/views on 
unconstrained array ports.

They appear to be legal, in the VHDL language and "The Designers Guide 
to VHDL" by Peter Ashenden makes them out to be a great thing for 
producing re-usable entities. However, the Xilinx synthesizer does not 
allow them and other reports I've read on the topic seem to indicate 
either implicitly or explicitly that they are a Very Bad Thing.

Can the experts who visit this newsgroup provide some insight to clarify 
the position?

Thanks!

6. type convertion of an unconstrained output in a port map

7. Unconstrained array of unconstrained vector.

8. How to specify default value to a variable of unconstrained type INSIDE a VHDL procedure ?



Return to vhdl

 

Who is online

Users browsing this forum: No registered users and 75 guest