Forum Discussion

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

assigning DE2 switches to inout port

Hello all,

I am building a custom microcontroller. I just tried to implement GPIO ports. The microcontroller entity has multiple ports as inout. This works fine in simulation, but in 'reality' on a DE2 board a problem occurs. Connecting it to the 7-segment displays and LEDs is no problem, but connecting it to the switches I get a message telling me that I have multiple drivers. I understand why this happens, but don't know how to fix it. Could you help me on my way?

13 Replies

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

    --- Quote Start ---

    When I want to use inout signal in a component, usually I do this way:

    pin_o : std_logic;

    pin_i : std_logic;

    pin_oe_n : std_logic;

    Then I can connect it to the top level pin this way:

    pin_i <= sw(0);

    sw(0) <= pin_o when (pin_oe_n = '0') else 'Z';

    --- Quote End ---

    When you set it this way I described, you have to change sw to inout std_logic_vector(17 downto 0)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can't set sw as inout because the switches are inout on the cyclone-chip.

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

    SOLUTION:

    I used this module in for each switch. where the switch is mapped to data_write.

    Data read is left open,

    IO is connected to an internal signal, witch in turn is connected to the inout port of the microcontroller.

    and the dir port is connected to an extra(unused) switch. This switch sould always be NOT(DDR_out).

    DDR_out is a constant defining the polarity of the dir.

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    entity IO_control is
    port(
        dir : in std_logic;
        data_write : in std_logic;
        IO : inout std_logic;
        data_read : out std_logic
    );
    end entity IO_control;
    architecture rtl of IO_control is
    begin
        IO <= data_write when dir = DDR_out else 'Z';
        data_read <= IO;
    end rtl;