VHDL - connect switch and LED - vhdl

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.

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.

Related

VHDL Push Button & LED

New to VHDL, familiarizing myself with everything.
I got my FPGA to turn on an LED when the button is pressed (code below), but the button has to be held down for the LED to stay on. I would like the LED to turn and stay on when the button is pushed and released (and turned off when pressed again) but I'm confused on how this is done.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ButtonLED is Port (BUTTON: in STD_LOGIC:='1';
LED : out STD_LOGIC:='0');
end ButtonLED;
architecture Behavioral of ButtonLED is
begin
LED <= not BUTTON;
end Behavioral;
(Warning: I am not giving you the answer. I am only addressing your question on "how it is done")
The statement LED <= not BUTTON defines that the LED is directly connected to the BUTTON through an inverting element. Therefore, your LED will always follow the opposite current state of the BUTTON. If BUTTON is in high logic level, then LED will be set to a low logic level, and vice versa.
I would like the LED to turn and stay on when the button is pushed and released (and turned off when pressed again) but I'm confused on how this is done.
For implementing this feature you must be capable of (1) detecting whenever the button is pressed and released, and (2) to "save" the current state of your LED. Detecting the button "movement" is simply detecting a change in state from high to low, and low to high. As mentioned in the comments it is also important to insert a de-bouncer mechanism between your edge detector and the button. Since FPGA buttons are very sensitive, the de-bouncer will ensure that you won't interpret glitches/noises as an actual press. I advise you to check it out yourself, implementation a version with and without the de-bouncer. Depending on how you press your button you may see the LED toggling multiple times when your hardware doesn't filter the input.
Once you know how to detect when the button was pressed and released, you have to simply add a memory element that toggles every time your condition is met. Now, instead of using LED <= not BUTTON, you'll have an internal variable that will control the LED behavior (i.e., LED <= led_state). This internal variable can be controlled through a process that is sensitive to your edge detection "module". Moreover, this variable will ensure your LED state only changes when your condition is met (i.e., pressing and releasing the button), instead of following the BUTTON inverse state.
Hope this gives you a general overview of your solution.

How to know direction of signal in Schemetic Tracer of simvision?

I am trying to tracing the signal at Schemetic Tracer in simvision(cadence).
But It's really hard to find for some signal which have direction.
Is there anyway to know the direction of port in Schemetic Tracer?
Yellow arrow on left of port name, pointing into box, input. Arrow on right of port name, output.

Show signals in ModelSim

I wrote a synchronous BCD counter. The counter count from 0 to 9, and so on and I want to see the signals (inputs & outputs) in ModelSim to verify the code I wrote.
So how can i see the signals?
Do I need to add something to my code or I need to run some function in ModelSim?
thanks,
Aviv
Suppose you have stored the source code of BCD counter and it's testbench in same file. (Let it be BCDcounter.v)
Then you just right click on BCDcounter.v and click compile.
Then if compilation was successful you will right click again the file(the name of the testbench file suppose it is BCDtestbench) and click simulate.
Then a new window will appear. Now in the left pane you will see the same filename that you simulated. Right click on that and select Add to ->Add to wave-> All items in design. Then run it.
Note: you may want to set the run-length appropiately.

PLC ladder logic sequence

I've spent hours and a trees worth of paper sketching and I haven't been able to stumble upon anything to get me past this problem. I'm able to switch back and forth between two motors but I can't figure out how to turn the motors off while switching between them, while still following the criteria below.
Using ladder logic:
Use only one start stop station consisting of only one NC contact and one NO contact, two motor starters and three control relays create the following cycle. (No timers or counters)
When the start button is pressed motor 1 will start and run until stopped by pressing the stop button.
When the start button is pressed again motor 2 will run until stopped by pressing the stop button.
When the start button is pressed again motors 1 & 2 will run until stopped by pressing the stop button.
Pressing the start button again will now start the cycle over.
Any help is very appreciated.
Thank you
Ira Baxter is right. You should use a state machine. I have set-up one below. Normally you would draw such a state machine using circles and arrows, but this will do for now I guess...
Although you talk about having 3 different steps (states) I actually see 6 states:
State0: Both motors are switched off (If start button pressed goto state 1)
State1: Motor 1 running (If stop button pressed goto state 2)
State2: Both motors are switched off (If start button pressed goto state 3)
State3: Motor 2 running (If stop button pressed goto state 4)
State4: Both motors are switched off (If start button pressed goto state 5)
State5: Both motors are running (If stop button pressed goto state 0)
What you should do is have one block determine the state (0..5) and have the motor-control blocks react to that state.
If you are limited on relays and don't want state machine you can do it with only 2 relays. Use logic flags to solve it. This example assumes you have rising edge contacts and set+reset coils as starters. I can't write ladder code here so I do what I can:
START is NO button and STOP is NC button. M1+M2 are motors F1+F2 are relays
START M1 M2 F1 F2 M1
-|P|--|/|--|/|--|/|--|/|--(S)
STOP M1 M2 M1 F1
-|N|--| |--|/|--(R)--(S)
START M1 M2 F1 F2 M2
-|P|--|/|--|/|--| |--|/|--(S)
STOP M1 M2 M1 F2 F1
-|N|--|/|--| |--(R)--(S)--(R)
START M1 M2 F1 F2 M1 M2 F2
-|P|--|/|--|/|--|/|--| |--(S)--(S)--(R)
STOP M1 M2 M1 M2
-|N|--| |--| |--(R)--(R)-

Addressing a styling issue not accessable from QT Designer

I am working on a QTreeWidget and I can't see a property for column size in the edit items... context menu. So I guess the cleanest way to perform this step is to attach application code to a signal (and not inheritance).
What signal do I attach to. More specifically, What signal should I attach to, to execute code that should be part of visual styling which should be editable from a GUI Builder, but isn't, or is to elaborate to model in a GUI builder. I guess i'm looking for a signal that is a one off call meant for further styling.
edit:
I guess I'll stick to inheritance, still if I shouldn't, or if there is indeed a one-off signal please post, and state merits :D

Resources