Tying two wires together

M

mhs000

I have a setup where there are two wires one for input to a module and
the other for output from this module. The two wires are tied together
outside of the module to form a single serial line, and then fed to a
bi-directional buffer with a direction control input. How can I model
this setup? Normally when the buffer is in the input mode the input
pin will receive what is on the other side of the buffer but if the
output is not high impedance at the same time this is happening, a
contention will happen. I would like to detect that contention. Right
now I'm using the following process to model this behavior but I
wonder if there's a better way to do it that represents the physical
connection and that does not require me to explicitly assign 'X' to
the line.

PROCESS (data_en, target, sdi, sdo)
BEGIN
IF (data_en = '1') THEN
target <= sdo;
sdi <= sdo;
ELSE
IF (sdo = 'Z') THEN
sdi <= target;
ELSE
sdi <= 'X';
END IF;
END IF;
END PROCESS;

The bidirectional buffer here is not physically represented but
implied from the process.

any help is appreciated

Thank you!
 
D

D Stanford

It depends on your simulation tools. ModelSim will detect contention
of a signal having 2 drivers in VHDL and will assign it a U
(undefined).
 
M

Martin Thompson

D Stanford said:
It depends on your simulation tools. ModelSim will detect contention
of a signal having 2 drivers in VHDL and will assign it a U
(undefined).

This is tool independent. If you have two (or more) drivers on a
signal, they will resolve to values depending on the type of the
signal.

For std_logic, you'll get an 'X' if you drive a '0' from one and a '1'
from another. 'U' is reserved for "uninitialised".

Cheers,
Martin
 
M

Martin Thompson

I have a setup where there are two wires one for input to a module and
the other for output from this module. The two wires are tied together
outside of the module to form a single serial line, and then fed to a
bi-directional buffer with a direction control input. How can I model
this setup? Normally when the buffer is in the input mode the input
pin will receive what is on the other side of the buffer but if the
output is not high impedance at the same time this is happening, a
contention will happen. I would like to detect that contention. Right
now I'm using the following process to model this behavior but I
wonder if there's a better way to do it that represents the physical
connection and that does not require me to explicitly assign 'X' to
the line.

I don't think you need to be that complex - just tie the signals
together and the simulator will resolve them for you. If you drive Z
and a 1 or 0, the 1 or 0 will dominate, otherwise you'll get X:

Assuming your target drives on the one wire, a model of your
tristatable buffer would be:
target <= sdo when enable = '1' else 'Z';
sdi <= target;

This ought to work if I understand your setup correctly...

Cheers,
Martin
 
M

mhs000

Thanks for the responses. To model the bidirectional buffer, I did:

target <= sdisdo WHEN data_en = '1' ELSE 'Z';
sdisdo <= target WHEN data_en = '0' ELSE 'Z';

And to model the two wires tied together, I did :

sdisdo <= sdo;
sdi <= sdisdo;

Where sdisdo is a signal i declared to represent the junction, and sdi
and sdo are the input and output ports. This seems to work.
 
W

weber

Thanks for the responses. To model the bidirectional buffer, I did:

target <= sdisdo WHEN data_en = '1' ELSE 'Z';
sdisdo <= target WHEN data_en = '0' ELSE 'Z';

And to model the two wires tied together, I did :

sdisdo <= sdo;
sdi <= sdisdo;

Where sdisdo is a signal i declared to represent the junction, and sdi
and sdo are the input and output ports. This seems to work.

I think there is something wrong here... aren't you trying to do this?

+-------+
| |
+--->| module|---+
| | | |
| +-------+ | +----+
| +--->|mux |
---+-------------------->| |------> output
input +----+
^
|
|
|ctrl

Cheers,
weber
 
M

mhs000

Here is what I'm trying to do:
enable
|
sdo >---------- ------->-------
| | |
+-----------+ +----------- target
| | |
sdi <---------- -------<-------
|
/enable
 
R

Ralf Hildebrandt

Here is what I'm trying to do:
enable
|
sdo >---------- ------->-------
| | |
+-----------+ +----------- target
| | |
sdi <---------- -------<-------
|
/enable


Why do you need a transfer gate? You need a tri state output driver:

target<=sdo when (enable='1') else 'Z';

Additionally you have to read the value of the target as input:

sdi<=target;

Nothing more - if I did not miss a point.


Ralf
 
M

mhs000

Why do you need a transfer gate? You need a tri state output driver:
target<=sdo when (enable='1') else 'Z';

Additionally you have to read the value of the target as input:

sdi<=target;

The only problem i see with your approach is that it represent only
one junction at the target:

enable
|
sdo >------------------------------>-------
|
+----------- target
|
sdi <------------------------------<-------
|
/enable

If enable = 1 then the effect is the same, but when enable is 0, i
believe the first approach will detect a contention if both sdo and
target trying to drive the sdi line together, while the second
approach has sdo isolated from sdi and target and will not be able to
detect that situation. This is important for me since the enable bit
is different from the bit that sets sdo to 'Z' or not.
 
R

Ralf Hildebrandt

The only problem i see with your approach is that it represent only
one junction at the target:

enable
|
sdo >------------------------------>-------
|
+----------- target
|
sdi <------------------------------<-------
|
/enable

If enable = 1 then the effect is the same, but when enable is 0, i
believe the first approach will detect a contention if both sdo and
target trying to drive the sdi line together

If enable='0' then sdo cannot drive target or sdi.

, while the second
approach has sdo isolated from sdi and target and will not be able to
detect that situation. This is important for me since the enable bit
is different from the bit that sets sdo to 'Z' or not.

Why do you need /two/ tri-state drivers in a chain?

sdo <= sdo_i when (enable_i='1') else 'z';
target <= sdo when (enable ='1') else 'z';

Do I miss something or is this just a waste of ressources?


Ralf
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top