Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VHDL code for Button OnRelease

Status
Not open for further replies.

CJ199

Technical User
Oct 5, 2004
5
0
0
US
I am having trouble making the code for kind of an OnRelease function

When a button is pressed there will be a '0' bit when not pressed there will be a '1' bit. I need to wait for the button to be pressed, and then to wait for it to be release before anything happens.... can someone please
help?

***load is the signal from the button

Code:
begin
	if(Reset='1') then timer:="0000"; load_count:="00"; 
	elsif(CLK'event and CLK='1') then

	    if(launch_in='1') then GAMEOVER<='1';
		
	    elsif(load='0' and load_count="00") then		
			--if (load='1') then
				timer:=data_in;
				load_count:="01";
			--end if;
								
		elsif(load='0' and load_count="01") then
			--if(load='1') then
				start_temp:='1';
				load_count:="10";
			--end if;
				
		elsif(load='0' and load_count="10") then
			--if(load='1') then
				pause_temp:='1';
				load_count:="11";
			--end if;
		
		elsif(load='0' and load_count="11") then
			--if(load='1') then
				pause_temp:='0';
				load_count:="00";
			--end if;

		end if;		
	end if;
 
I usually do that kind of thing with a shift register. Of course it depends on all kinds of things, like how often the button is to be pressed, and what kind of debounce you might need. For a physical button you probably need a very large debounce of say 250ms or more, unless that is built in already somewhere.

but the idea is:

buttonHistory <= buttonHistory(3 downto 1) & button;

if (buttonHistory = "1110") then
--whatever you want to do when button is pressed

elsif (buttonHistory = "0001") then
-- whatever you want to do on release.


of course with a bounce that won't work just right, so you might need to modify it to something like

if (buttonHistory = "1111") then
status <= '1';
elsif (buttonHistory = "0000") then
status <= '0';
end if;

statusHistory <= statusHistory(0) & status;

if statusHistory = "10" then
-- button press with 4 clocks of debounce.
-- do you stuff here.
elsif statusHistory = "01" then
-- button release with 4 clocks of debounce.
-- do your stuff here.

of course there are lots of ways you could do that. but there is an example.


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top