Forum Discussion

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

Can a bidirectional port becomes both input and output at the same time?

I would like to create VHDL codes which are able to display data to the Input/Output port as well as receiving values of the port, if there is any changes to the port. Firstly, is it possible without causing logic contention?

8 Replies

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

    No, technology may advance in future but the physical line is shared. Only one side should drive the line at any given sample time.

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

    Ok. thanks for your reply because i've been trying hard to do it. i guess i need to assign a set of ports to it. meaning input and output as a single port. I really hope there is another way for this.

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

    I am not clear what you want to say (assigning ports to it??).

    A bidirectional bus is under control of two(or more devices). At any sample time, the designer has to know who should write to the bus(drive it) and who should read it. Any other drive should be cut-off including your own fpga drive if you want to read the bus inside the fpga(as input).

    The simple fpga method is connect the bidir pin to two internal nodes(A,B). read A anytime you want. write to port when you want to output else cut-off(so you don't read back your own drive). So you need a 3rd control signal to enable/disable the tristate buffer.

    A <= bidir; -- read port

    bidir <= B when enable = '1' else 'Z';; --write to port
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I also didn't understand exactly, what you want to achieve. Clearly, while a bidirectional port is driving out, either high or low, there shouldn't be a second driver at the node, that is driving the opposite level. Otherwise, the involved outputs can be damaged, at least when using higher drive strengths. Also the read back input level would be unpredictable.

    A wired or circuit of several open drain outputs and a pullup resistor (as used with I2C bus or the smart card IO node) is a possible way to send and receive at the same time.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Actually, I wanted to assigned those bidirectional pins to the DE1 development board so that I can input values from external sources and as well as output values internally from the same pins. I wanted to create a pin which acts both as input and output so that it is not specifically tied to input nor output.

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

    1 - Yes the pin can be an output and an input at the same time. Meaning that you can read whatever you are driving on the pin. You read whatever you output.

    2 - If you want to read a signal on the pin that's driven by an external source. You must disable the output driver. If you try to drive at the same time the external driver is driving, you will get contention.

    3 - Please refer to figure 2-20 on page 2-38 of the user's guide for the Cyclone II. This figure shows you what the IOE structure of each IO pin looks like. This should explain things well enough.

    http://www.altera.com/literature/hb/cyc2/cyc2_cii51002.pdf

    Look at the three components (output, output enable, and input). You can think of the input as being directly connected to the pin at all times. It always reads what's on the pin. Now who's driving the pin? Well if you have the output enable asserted, you are, otherwise the pin is driven externally or floating if there is no active driver.

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

    Ooh. this mean that i can assign as inout and connect it to the external ports then control it by using an output enable bit and at the same time continuously reading the ports value is it?

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

    Yes. Just don't turn on the output enable at the same time that an external driver is active.

    Jake