VHDL - Add Delay to Flip-Flop

  • Thread starter HD555
  • Start date
  • Tags
    Delay
In summary, the conversation discusses implementing a delay in VHDL code for simulation purposes. The code uses a rising edge detector and a one-shot behavior to create a 5-second pulse. The code is written using Xilinx's ISE WebPACK software and uses a state machine to enable the one-shot behavior. The conversation also mentions that the code is not truly a one-shot since the trigger must stay on the whole time, but it was still effective in achieving the desired result.
  • #1
HD555
27
0
Hi, I have a small piece of code that will detect a rising edge and output a pulse for 2 clock cycles. I'm only doing this for simulation purposes and will not be porting this into a FPGA.

When using the after 10 ns after a statement, I know this is ignored during sythesis. How can I implement a delay and have it be shown on the testbench waveform?

Thanks. I'm using Xilinx's ISE WebPACK Software. Code is below.

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity rising_edge_detector_2ms is
    Port ( 
			  clk : in  STD_LOGIC;
           signal_input : in  STD_LOGIC;
			  out1, out2 : out STD_LOGIC;
           output : out  STD_LOGIC
			 );  
end rising_edge_detector_2ms;


architecture Behavioral of rising_edge_detector_2ms is

signal Q_FF, Q1_FF, Q2_FF : STD_LOGIC;

begin

	process(clk)
	begin
		if rising_edge(clk) then
			Q_FF <= signal_input after 20 ns;
		end if;
	end process;
	
	process(clk)
	begin
		if rising_edge(clk) then
			Q1_FF <= Q_FF  after 20 ns;
		end if;
	end process;
	
	process(clk)
	begin
		if rising_edge(clk) then
			Q2_FF <= Q1_FF  after 20 ns;
		end if;
	end process;
	
-- Final Output Through AND Gate
	out1 <= Q1_FF;
	out2 <= Q2_FF;
	output <= (not Q2_FF) and signal_input;

end Behavioral;
 
Engineering news on Phys.org
  • #2
I've had to create a purely VHDL one-shot type of behavior..which is pretty annoying.

Code:
--5 second one shot
Process (onehertz, fivetrigger, reset)
	variable fiveint: integer range 0 to 4;
begin
	if (reset = '0') then
		fivesec <= '1';
		fiveint := 0;
	elsif (rising_edge(onehertz)) then
		if (fivetrigger = '0') then
			fiveint := 0;
			fivesec <= '1';
		elsif (fiveint = 4) then
			fivesec <= '0';
		else
			fiveint := fiveint + 1;
		end if;
	end if;	
end process;

Not truly a one-shot since the trigger has to stay on the whole time, but if you create a state machine where a certain state enables this trigger, you can do it.

My thought process was:

State 1 goes to State 2 when the input goes high
State 2 enables this counting process
State 2 goes back to State 1 when counting is done.

It's bootleg but I got an A so it's all good.
 
  • #3


As a scientist, it is important to understand the limitations and capabilities of the tools and software being used for simulations and experiments. In this case, the VHDL code provided is only for simulation purposes and will not be implemented in a FPGA. Therefore, the use of "after" statements for delaying signals is appropriate and will not affect the final outcome of the experiment.

However, if the goal is to accurately capture the delay in the testbench waveform, there are a few options to consider. One option is to use the "wait" statement instead of "after" to introduce a delay in the process. This will allow the delay to be reflected in the testbench waveform. Another option is to use a delay component from the Xilinx ISE library, such as the "IBUFGDS_DELAY" component, which can be instantiated in the code to introduce a specific delay.

Additionally, it is important to keep in mind that delays introduced in simulation may not accurately reflect the delays in a physical FPGA implementation. It is always best practice to verify and test the final design on the actual hardware to ensure accurate results.
 

1. What is VHDL and what is its role in adding delay to a flip-flop?

VHDL (VHSIC Hardware Description Language) is a programming language used for describing digital circuits and systems. It is commonly used in the design and verification of electronic systems. In the context of adding delay to a flip-flop, VHDL is used to create a behavioral model of the desired delay and then assign it to the flip-flop.

2. Why would I need to add delay to a flip-flop?

Adding delay to a flip-flop is often necessary in digital circuit design to ensure proper timing and avoid glitches or errors. It allows for control over the propagation delay and setup/hold times of the flip-flop, which can affect the stability and functionality of the circuit.

3. How do I add delay to a flip-flop using VHDL?

The most common method is to use the "after" keyword, which specifies a time delay in a VHDL process statement. For example, "Q <= D after 10 ns;" would add a 10 nanosecond delay to the output Q, relative to the input D. Another method is to use a delay element in the circuit design, such as a buffer or inverter, and then adjust the delay by changing the component parameters.

4. Can I add delay to any type of flip-flop using VHDL?

Yes, VHDL can be used to add delay to any type of flip-flop, including D, JK, T, and SR flip-flops. However, the method for adding delay may vary depending on the specific type of flip-flop and the design requirements.

5. Are there any limitations or drawbacks to using VHDL to add delay to a flip-flop?

One limitation is that adding delay to a flip-flop can increase power consumption and may affect the overall timing and performance of the circuit. It is important to carefully design and optimize the delay to ensure it is necessary and does not cause any negative effects. Additionally, using VHDL to add delay may require a certain level of expertise and understanding of the language and digital circuit design.

Similar threads

  • Electrical Engineering
Replies
2
Views
27K
  • Electrical Engineering
Replies
6
Views
4K
  • Electrical Engineering
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
11K
Replies
5
Views
10K
Replies
2
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • General Engineering
Replies
3
Views
3K
Back
Top