VHDL - connect switch and LED

2019-08-18 22:21发布

问题:

I have the Xilinx Spartan6 and next VHDL code:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity Switches_Leds is
    Port (switch_0: in STD_LOGIC;
          LED_0 : out STD_LOGIC);
end Switches_Leds;

architecture Behavioral of Switches_Leds is
begin
   LED_0 <= switch_0;
end;

Here is my User constraint file:

NET "switch_0" LOC = C3;

NET "LED_0" LOC = P4;

My question is: Why the led is always is turned on, but it goes off if I click on button ?

I explain: I program my fpga - the led is turned on, I press the switch button - the led is turned off, I unpress the button - led goes on.

回答1:

The inversion can happen in two places:

  • In the button.
  • In the LED.

It all depends on how they are connected. I made a diagram:

(Had to draw it as we do not have a schematic editor here as on the EE site)

If you look at the diagram: buttons can be connected in two ways. They can either generate a high when pushed or a low.

LEDs can also be connected in two ways: they can light up when the output is high or they can light up when the output is low.

That gives you four combinations from which two give an LED lighting up when the button is pushed and two give an LED which goes off when the button is pushed.