VHDL equivalent of verilog trireg

Discussion in 'VHDL' started by Sanjeev, Jul 22, 2004.

  1. Sanjeev

    Sanjeev Guest

    I would like to know the vhdl equivalent of verilog trireg.
    Sanjeev, Jul 22, 2004
    #1
    1. Advertising

  2. On 22 Jul 2004 04:05:46 -0700, (Sanjeev)
    wrote:

    >I would like to know the vhdl equivalent of verilog trireg.


    Depends how much of the Verilog functionality you need to mimic.

    The basic behaviour (hold the last driven value, if all drivers
    are floated) is easy to achieve: just drive a weaker version
    of the signal's level back on to itself, so it holds its value
    if all other drivers on it are driving 'Z'. Here's one
    possible implementation, using a lookup table as a cut-price
    conversion function (one of my favourite pieces of VHDL
    testbench trickery):

    [in some package]
    type sl_map_table is array(std_ulogic) of std_ulogic;
    constant weaken: sl_map_table := (
    'U' => 'W',
    'X' => 'W',
    '0' => 'L',
    '1' => 'H',
    'Z' => 'W',
    'W' => 'W',
    'L' => 'L',
    'H' => 'H',
    '-' => 'W'
    );

    [declaration]
    signal my_trireg: std_logic;

    [within the architecture]
    my_trireg <= weaken(my_trireg);

    If I remember correctly, Verilog trireg can also offer a
    "capacitive decay" behaviour in which its value collapses
    to X if it hasn't been updated after some specified time.
    You can imitate this using VHDL inertial delay:

    my_trireg <= weaken(my_trireg), 'W' after decay_time;

    None of this makes any sense for synthesis, of course.
    You also need to be aware that it puts some constraints
    on any other logic connected to the same signal:

    1) Drivers must drive '1' or '0', never 'H' or 'L',
    so that they can overcome the trireg hold value.
    2) Any logic that uses the signal's value must
    treat 'H' and 'L' as valid '1' and '0' values.
    Verilog deals with this automatically. Likewise,
    so do all the std_logic_1164 logic operators:

    'H' and '1' = '1'
    'L' and '1' = '0'
    not 'L' = '1'

    But you can get into trouble if you test for
    '1' or '0' in an "if" or "case", or use
    the equality or comparison operators:

    if my_trireg = '1' then ...
    -- FAILS if my_trireg = 'H' :-(

    if my_trireg > '0' then ...
    -- SUCCEEDS if my_trireg = 'L' :-(

    Most of these problems can be worked-around by
    applying the To_X01() strength stripper whenever
    you try to make use of the signal value:

    if To_X01(my_trireg) = '1' then ...
    -- SUCCEEDS if my_trireg = 'H' :)

    Hope this helps.
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
    Tel: +44 (0)1425 471223 mail:
    Fax: +44 (0)1425 471573 Web: http://www.doulos.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Jul 22, 2004
    #2
    1. Advertising

  3. On Thu, 22 Jul 2004 13:11:13 +0100, Jonathan Bromley
    <> wrote:

    >>I would like to know the vhdl equivalent of verilog trireg.

    >
    >Depends how much of the Verilog functionality you need to mimic.


    [snip lots of vaguely sensible ramblings]

    >If I remember correctly, Verilog trireg can also offer a
    >"capacitive decay" behaviour in which its value collapses
    >to X if it hasn't been updated after some specified time.
    >You can imitate this using VHDL inertial delay:
    >
    > my_trireg <= weaken(my_trireg), 'W' after decay_time;


    Oh dear, oh dear, oh dear. This doesn't work. It's my
    faulty memory of something similar, but slightly different.

    Today's challenge (1): what's wrong with it?
    Today's challenge (2), harder: how to fix it?

    I have a wonderful solution, but the margin of this
    lunch break is too short to accommodate it :)
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
    Tel: +44 (0)1425 471223 mail:
    Fax: +44 (0)1425 471573 Web: http://www.doulos.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Jul 22, 2004
    #3
  4. On Thu, 22 Jul 2004 13:11:13 +0100, Jonathan Bromley
    <> wrote:

    >On 22 Jul 2004 04:05:46 -0700, (Sanjeev)
    >wrote:
    >
    >>I would like to know the vhdl equivalent of verilog trireg.


    [snip]

    >None of this makes any sense for synthesis, of course.


    I assume that you meant to say that it cannot be inferred by current
    synthesis tools.
    XST, for example, can generate one from HDL source using the "keeper"
    attribute (on an I/O pin only, since Xilinx FPGAs no longer have
    internal tristate signals).

    (Or were you just referring to the decay effect? If this is the case,
    I agree with you.)

    Regards,
    Allan.
    Allan Herriman, Jul 23, 2004
    #4
  5. On Fri, 23 Jul 2004 13:19:44 +1000, Allan Herriman
    <> wrote:

    >On Thu, 22 Jul 2004 13:11:13 +0100, Jonathan Bromley
    ><> wrote:


    >>None of this makes any sense for synthesis, of course.


    >I assume that you meant to say that it cannot be inferred by current
    >synthesis tools.
    >XST, for example, can generate one from HDL source using the "keeper"
    >attribute (on an I/O pin only)


    The code I posted is, of course, a "weak keeper" or "bus hold" model.
    It was careless of me to say that it makes no sense for synthesis,
    since it represents a perfectly reasonable hardware structure;
    but I was not aware that any tools could correctly infer such
    a structure from the behavioural description. One more gold star
    to XST (the first one was for correct handling of initialisation
    in the declaration of a flip-flop signal).
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
    Tel: +44 (0)1425 471223 mail:
    Fax: +44 (0)1425 471573 Web: http://www.doulos.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Jul 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    0
    Views:
    8,666
    walala
    Aug 1, 2003
  2. walala
    Replies:
    3
    Views:
    5,648
    walala
    Aug 30, 2003
  3. Replies:
    1
    Views:
    2,088
    Ralf Hildebrandt
    Mar 13, 2007
  4. afd
    Replies:
    1
    Views:
    8,266
    Colin Paul Gloster
    Mar 23, 2007
  5. sheri
    Replies:
    13
    Views:
    6,364
    Kim Enkovaara
    Feb 28, 2008
Loading...

Share This Page