EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

Is an inout reg allowed

elektroda.net NewsGroups Forum Index - Verilog Language - Is an inout reg allowed

Giorgos Tzampanakis
Guest

Fri Mar 05, 2010 4:30 am   



I've tried to use an inout reg with quartus and it doesn't give a
warning. However, I read on the internet that an inout port can
only be a wire. Which one is true?

Jonathan Bromley
Guest

Fri Mar 05, 2010 10:28 am   



On Fri, 5 Mar 2010 02:22:20 +0000 (UTC), Giorgos Tzampanakis wrote:

Quote:
I've tried to use an inout reg with quartus and it doesn't give a
warning. However, I read on the internet that an inout port can
only be a wire. Which one is true?

It is unquestionably true that an inout port must be a net
(wire), and also that you must connect a net to any inout
port when you instantiate the module. "reg" on either
side of an inout port is definitely illegal.

If your design uses the inout port in a unidirectional
manner, it is possible that synthesis might be able to
do something useful with a reg on one or other side of it.
However, the resulting illegal Verilog code will never
work in any simulator. Don't do it.

The classic use of an inout port, to provide a bidi
tri-state signal, is straightforward. Inside the module
you need two signals or expressions - probably reg -
to provide the buffer enable and buffer data. You then
use a continuous assign to imply the buffer:

module has_bidi ( inout bidi, ...);
...
reg bidi_enable;
reg bidi_drive_value;
wire bidi_receive_value;
...
assign bidi = bidi_enable? bidi_drive_value: 1'bx;
assign bidi_receive_value = bidi;
...
.... other logic to use "bidi_receive_value"
.... and generate "bidi_enable" and "bidi_drive_value"
endmodule

The second "assign" does nothing more than renaming the port
for internal use, but it can often be convenient to do that.
--
Jonathan Bromley

Jonathan Bromley
Guest

Fri Mar 05, 2010 8:30 pm   



On Fri, 5 Mar 2010 09:41:25 -0800 (PST), Nathan Bialke wrote:

Quote:
Out of curiousity, why does your tristate buffer model drive an x
instead of a z?

ah, good catch. Runs for cover with tail between legs.

Of course you're right, it should have been

  assign bidi = bidi_enable? bidi_drive_value: 1'bz;

Errrrm, that's what simulators are for, right?
To catch the idiotic typing mistakes?

Thanks!
--
Jonathan Bromley

Anssi Saari
Guest

Fri Mar 05, 2010 8:36 pm   



Nathan Bialke <nathan_at_bialke.com> writes:

Quote:
Hello,

Out of curiousity, why does your tristate buffer model drive an x
instead of a z?

In my experience this is a fairly common technique to make sure some
other part of the design isn't erroneously reading the x values and
passing them on.

Nathan Bialke
Guest

Fri Mar 05, 2010 8:41 pm   



Hello,

Out of curiousity, why does your tristate buffer model drive an x
instead of a z?

- Nathan

On Mar 5, 12:28 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
Quote:
On Fri, 5 Mar 2010 02:22:20 +0000 (UTC), Giorgos Tzampanakis wrote:
I've tried to use an inout reg with quartus and it doesn't give a
warning. However, I read on the internet that an inout port can
only be a wire. Which one is true?

It is unquestionably true that an inout port must be a net
(wire), and also that you must connect a net to any inout
port when you instantiate the module.  "reg" on either
side of an inout port is definitely illegal.

If your design uses the inout port in a unidirectional
manner, it is possible that synthesis might be able to
do something useful with a reg on one or other side of it.
However, the resulting illegal Verilog code will never
work in any simulator.  Don't do it.

The classic use of an inout port, to provide a bidi
tri-state signal, is straightforward.  Inside the module
you need two signals or expressions - probably reg -
to provide the buffer enable and buffer data.  You then
use a continuous assign to imply the buffer:

  module has_bidi ( inout bidi, ...);
    ...
    reg bidi_enable;
    reg bidi_drive_value;
    wire bidi_receive_value;
    ...
    assign bidi = bidi_enable? bidi_drive_value: 1'bx;
    assign bidi_receive_value = bidi;
    ...
    .... other logic to use "bidi_receive_value"
    .... and generate "bidi_enable" and "bidi_drive_value"
  endmodule

The second "assign" does nothing more than renaming the port
for internal use, but it can often be convenient to do that.
--
Jonathan Bromley


elektroda.net NewsGroups Forum Index - Verilog Language - Is an inout reg allowed

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony