Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Single pulse (one clock) generator in VHDL

Status
Not open for further replies.

FlyingDutch

Advanced Member level 1
Joined
Dec 16, 2017
Messages
457
Helped
45
Reputation
92
Reaction score
55
Trophy points
28
Location
Bydgoszcz - Poland
Activity points
4,957
Hello,

I need a single pulse after pushing button (FPGA). I know how to debounce signal from button, but signal after debounce is too long (in best case i want one clock signal). So when I push button then one clock pulse be generated. I find such example of circuit that provide needed behavior - see link:

https://www.fpgakey.com/technology/...e-pulse-generator-circuit-in-fpga-development

I implemented such circuit (from figure 2 from link above) - here is implementation i VHDL. First it is D flip-flop (with async reset) - see code:


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

entity DFF_AsyncReset is
   port(
      Q : out std_logic;
      QNot : out std_logic;       
      clk : in std_logic; 
      reset: in std_logic; 
      D :in  std_logic   
   );
end DFF_AsyncReset;

architecture Behavioral of DFF_AsyncReset is 
begin 
 process(clk,reset)
 begin
     if(reset='0') then
      Q <= '0';
        QNot <= '1';
     elsif(rising_edge(clk)) then
      Q <= D;
      QNot <= (not D);
  end if;     
 end process; 
end Behavioral;

And here is this circuit - see code:

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

entity monostable_ff is
 port(
      mono_pulse : out std_logic;       
      clk : in std_logic; 
      reset: in std_logic; 
      key : in  std_logic   
   );
end monostable_ff;

architecture Behavioral of monostable_ff is
    
    component DFF_AsyncReset is
   port(
      Q : out std_logic;
      QNot : out std_logic;       
      clk : in std_logic; 
      reset: in std_logic; 
      D :in  std_logic   
      );
   end component;
    
    signal Q1,Q2,Q3,Q4 : std_logic;
   signal Q1N,Q2N,Q3N,Q4N : std_logic;
    signal G1O : std_logic;

begin

  DFF1: DFF_AsyncReset port map (                           
                                              Q      => Q1,                                         
                                     QNot   => Q1N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => key   
                                 );
                                            
  DFF2: DFF_AsyncReset port map (                           
                                              Q      => Q2,                                         
                                     QNot   => Q2N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => Q1   
                                 );   

  DFF3: DFF_AsyncReset port map (                           
                                              Q      => Q3,                                         
                                     QNot   => Q3N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => '1'   
                                 );   
    G1O <= (Q2 and Q3);                           
                                
                                        
  DFF4: DFF_AsyncReset port map (                           
                                       Q      => mono_pulse,                                         
                                      QNot   => Q4N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => G1O 
                                 );   
end Behavioral;

Could I ask if someone more experienced than me check if I implement this circuit properly. Of course I am going to write test bench and simulate this circuit (tomorrow).

Best Regards
 

If you are "of course" going to simulate it, why should we waste our time checking your code?

If you have a problem, post a question. Tell us what you've done and where you are having trouble.

But a quick look says this isn't going to do what you want. Q3 goes high the first clock after reset is deasserted and stays there. What's the point of that?
 
Hi,

I agree with Barry.

I don´t understand the problem. So could you just draw some sketches (timing diagram, schematics ...) of
* how you want it to be
* how it is instead

Klaus
 
Hello guys,

thanks for your answers. Today a test-bench for monostable flip-flop has been written by me. The simulation shows, that circuit not work in desired way - it was generating one pulse shifted in phase, but with length equal impulse of pushed button. I resolved circuit and came to a conclusion that error was in entry signals for and gate

It was:
Code:
G1O <= (Q2 and Q3);
, but
should be
Code:
G1O <= (Q2 and Q3N);

where Q2 is output from D2 flip-flop, and Q3 is output from D3 flip-flop, and Q3N is negated output from D3 flip-flop. I also corrected D3 FF port map , on it Dinput was '1" now is Q2 (but it was not cause of error.
So the code of "monostable_ff" entity after corrections is:

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

entity monostable_ff is
 port(
      mono_pulse : out std_logic;       
      clk : in std_logic; 
      reset: in std_logic; 
      key :in  std_logic   
   );
end monostable_ff;

architecture Behavioral of monostable_ff is
    
    component DFF_AsyncReset is
   port(
      Q : out std_logic;
      QNot : out std_logic;       
      clk : in std_logic; 
      reset: in std_logic; 
      D :in  std_logic   
      );
   end component;
    
    component nand2 is
   port(a,b : in std_logic;
       y : out std_logic);
   end component;
    
    signal Q1,Q2,Q3,Q4 : std_logic;
   signal Q1N,Q2N,Q3N,Q4N : std_logic;
    signal G1O : std_logic;

begin

  DFF1: DFF_AsyncReset port map (                           
                                              Q      => Q1,                                         
                                     QNot   => Q1N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => key   
                                 );
                                            
  DFF2: DFF_AsyncReset port map (                           
                                              Q      => Q2,                                         
                                     QNot   => Q2N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => Q1   
                                 );   

  DFF3: DFF_AsyncReset port map (                           
                                              Q      => Q3,                                         
                                     QNot   => Q3N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => Q2   
                                 );   
    G1O <= (Q2 and Q3N);                           
                                
                                        
  DFF4: DFF_AsyncReset port map (                           
                                              Q      => mono_pulse,                                         
                                     QNot   => Q4N,       
                                       clk    => clk,
                                       reset  => reset,
                                       D      => G1O 
                                 );   
end Behavioral;

Below is screenshot from simulator:
Monostable_ff_sim_.png

keybut signal is from push button, and pulse signal is monostable flip-flop output.

Best Regards
--- Updated ---

Hello guys,

thanks for your answers. Today a test-bench for monostable flip-flop has been written by me. The simulation shows, that circuit not work in desired way - it was generating one pulse shifted in phase, but with length equal impulse of pushed button. I resolved circuit and came to a conclusion that error was in entry signals for and gate

It was:
Code:
G1O <= (Q2 and Q3);
, but
should be
Code:
G1O <= (Q2 and Q3N);

where Q2 is output from D2 flip-flop, and Q3 is output from D3 flip-flop, and Q3N is negated output from D3 flip-flop. I also corrected D3 FF port map , on it Dinput was '1" now is Q2 (but it was not cause of error.
So the code of "monostable_ff" entity after corrections is:

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

entity monostable_ff is
 port(
      mono_pulse : out std_logic;      
      clk : in std_logic;
      reset: in std_logic;
      key :in  std_logic  
   );
end monostable_ff;

architecture Behavioral of monostable_ff is
   
    component DFF_AsyncReset is
   port(
      Q : out std_logic;
      QNot : out std_logic;      
      clk : in std_logic;
      reset: in std_logic;
      D :in  std_logic  
      );
   end component;
   
    component nand2 is
   port(a,b : in std_logic;
       y : out std_logic);
   end component;
   
    signal Q1,Q2,Q3,Q4 : std_logic;
   signal Q1N,Q2N,Q3N,Q4N : std_logic;
    signal G1O : std_logic;

begin

  DFF1: DFF_AsyncReset port map (                          
                                              Q      => Q1,                                        
                                     QNot   => Q1N,      
                                       clk    => clk,
                                       reset  => reset,
                                       D      => key  
                                 );
                                           
  DFF2: DFF_AsyncReset port map (                          
                                              Q      => Q2,                                        
                                     QNot   => Q2N,      
                                       clk    => clk,
                                       reset  => reset,
                                       D      => Q1  
                                 );  

  DFF3: DFF_AsyncReset port map (                          
                                              Q      => Q3,                                        
                                     QNot   => Q3N,      
                                       clk    => clk,
                                       reset  => reset,
                                       D      => Q2  
                                 );  
    G1O <= (Q2 and Q3N);                          
                               
                                       
  DFF4: DFF_AsyncReset port map (                          
                                              Q      => mono_pulse,                                        
                                     QNot   => Q4N,      
                                       clk    => clk,
                                       reset  => reset,
                                       D      => G1O
                                 );  
end Behavioral;

Below is screenshot from simulator:
Monostable_ff_sim_.png

keybut signal is from push button, and pulse signal is monostable flip-flop output.

Best Regards
BTW: here is test-bench:
Code:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
 
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
 
ENTITY monostable_ff_TB IS
END monostable_ff_TB;
 
ARCHITECTURE behavior OF monostable_ff_TB IS
 
    -- Component Declaration for the Unit Under Test (UUT)
    
      component monostable_ff is
     port(
           mono_pulse : out std_logic;       
           clk : in std_logic; 
           reset: in std_logic; 
           key :in  std_logic   
         );
     end component;

   --Inputs
   signal clk_i : std_logic := '0';
   signal rst : std_logic := '0';
   signal keyBut : std_logic := '0';

     --Outputs
   signal pulse : std_logic;

   -- Clock period definitions
   constant clk_i_period : time := 20 ns;
 
BEGIN
 
    -- Instantiate the Unit Under Test (UUT)
    uut: monostable_ff port map (
                             mono_pulse => pulse,   
                             clk  => clk_i,
                             reset => rst, 
                             key  => keyBut   
                           );
    
    
   -- Clock process definitions
   clk_i_process :process
   begin
        clk_i <= '0';
        wait for clk_i_period/2;
        clk_i <= '1';
        wait for clk_i_period/2;
   end process;
 

   -- Stimulus process
   stim_proc: process
   begin       
      -- hold reset state for 100 ns.
      wait for 100 ns;   

      wait for clk_i_period*10;

      -- insert stimulus here
        keyBut <= '0';
      rst <= '0';
      wait for 60 ns;
      rst <= '1';   
      wait for 60 ns;
      keyBut <= '1';
      wait for 400 ns;   
      keyBut <= '0';       

      wait;
   end process;

END;
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top