• 0
rb251415

Creating a 3 second latch for BASYS3 Button

Question

I have created a soundbox with different sounds connect to different buttons and switches. The switches work fine. High '1' is on, and low '0' is off. 

I would like my buttons to latch for 3 seconds. I would like to press the button, release it, and have the sound play for 3 seconds. Some call this a one-shot, where a single press latches the bit until unlatched.

My code is VHDL in Vivado 2016.4. My board is a BASYS3.

 

I tried using a wait statement, but others have suggested that wait statements do not synthesize. Here is what I have. All help is appreciated. Thanks!

 

period - constance set to 1000ms

tempdata - signal std_logic

squareout - signal for tone 1

integerout - signal for tone 2

ipcoreout - signal for tone 3

dataout - output from system

section of code....

D1: process
    begin  
    if btn_a = '1' then
     tempdata <= squareout;
     wait for 3 * period;
    elsif btn_b = '1' then
     tempdata <= integerout;
     wait for 3 * period;
    elsif btn_c = '1' then
     tempdata <= ipcoreout;
     wait for 3 * period;
    elsif swt_a = '1' then
     tempdata <= squareout;
     wait until swt_a = '0';
    elsif swt_b = '1' then
     tempdata <= integerout;
     wait until swt_b = '0';
    elsif swt_c = '1' then
     tempdata <= ipcoreout;
     wait until swt_c = '0';
    end if;
end process;

dataout <= tempdata; 

 

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

@rb251415,

Yeah, wait statements don't synthesize.

Try using a counter instead.   You can initialize it to zero (or your max value) when you come into a wait state, increment (or decrement) it while you are waiting, and then leaving when the counter reaches your maximum (or zero) value.

Dan

Share this post


Link to post
Share on other sites
  • 0

@D@n,

As usual, you are a genius. It took a few tries, but I got it.

Thanks

Royal

Here is the code if anyone is interested...

P1: process(clk, rst, btn_a, on_a)
    begin  
    if rst = '1' and btn_a = '0' then
      on_a <= '0';
    elsif rst = '0' and btn_a = '1' then
      cntra <= (others => '0');
      on_a <= '1';
    elsif (rising_edge(clk) and on_a = '1') then
       cntra <= cntra +1;
       if cntra < 200000000 then
         on_a <= '1';
       else 
         on_a <= '0';
       end if;
    end if;
end process;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now