3
\$\begingroup\$

I am relearning VHDL and have a question about the code below. This is from a tutorial I have been following. When a button is pressed, an LED gets turned on after the person releases their finger from the button. I am confused about the order of execution in the process. Specifically this line: if i_Switch_1 = '0' and r_Switch_1 = '1' then

I have been reading that inside processes the code is executed sequentially, so I do not understand how this gets executed, since they are assigned to the same value right before.

Thanks

library ieee;
use ieee.std_logic_1164.all;
entity Clocked_Logic is
 port(
 i_Clk : in std_logic;
 i_Switch_1 : in std_logic;
 o_LED_1 : out std_logic);
end entity Clocked_Logic;
architecture RTL of Clocked_Logic is
signal r_LED_1 : std_logic := '0';
signal r_Switch_1 : std_logic := '0';
begin
 p_Register : process (i_Clk) is
 begin
 if rising_edge(i_Clk) then
 r_Switch_1 <= i_Switch_1;
 if i_Switch_1 = '0' and r_Switch_1 = '1' then
 r_LED_1 <= not r_LED_1;
 end if;
 end if;
end process p_Register;
o_LED_1 <= r_LED_1;
end architecture RTL;
asked Nov 6, 2020 at 19:30
\$\endgroup\$
4
  • 2
    \$\begingroup\$ you are dealing with hardware, not software ... there is a delay between input states and output states \$\endgroup\$ Commented Nov 6, 2020 at 19:48
  • 2
    \$\begingroup\$ Signal assignment semantics and delta cycles. stackoverflow.com/questions/13954193/… \$\endgroup\$ Commented Nov 6, 2020 at 19:49
  • 2
    \$\begingroup\$ The answer to this question is teaching the basics of VHDL and it's a Q&A site, not a step-by-step tutorial or discussion site. I won't write an answer because there's tons on the internet. But... Get yourself away from the trap you've walked into: seeing VHDL as a programming language that executes software instructions. It's a descriptor language for describing the behaviour of digital logic circuits. It behaves very differently. Signals are not program variables, they are scheduled in a simulator and circuitry in a chip. It's for you to teach yourself the basics. Good luck with it, enjoy. \$\endgroup\$ Commented Nov 6, 2020 at 19:56
  • \$\begingroup\$ There is no "execution", as these are hardwares. Btw you can learn C/C++ in 2 months but not HDL languages cz there are more to it. Good luck 🙂 \$\endgroup\$ Commented Nov 7, 2020 at 16:53

1 Answer 1

3
\$\begingroup\$

Here is essentially what the hardware looks like. The i_ prefix means input or intermediate signal to a register. What you have is one register for detecting a falling edge on the Switch_1 signal and another register for toggling the LED output whenever a falling edge occurs on the Switch_1 signal. Note that wrapping the output of a register back to the input through a NOT gate creates a toggle flop. The toggle flop is enabled (toggles) whenever a falling edge occurs on the Switch_1 signal.

enter image description here

answered Nov 6, 2020 at 20:05
\$\endgroup\$
2
  • \$\begingroup\$ Sorry, I accidentally left that out. @TonyM is correct, the i_CLK signal in the VHDL code should be connected to the CLK inputs of the registers in the drawing. \$\endgroup\$ Commented Nov 6, 2020 at 20:10
  • \$\begingroup\$ Yup all done! Fixed a copy and paste error with the LED register too. Thanks @TonyM \$\endgroup\$ Commented Nov 6, 2020 at 20:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.