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.

Led Control with One Button

Status
Not open for further replies.

vitruvius

Newbie level 5
Joined
Apr 13, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,342
Hi all. I'm a begginer at VHDL and Fpga and i have Spartan-3E Starter Kit. I tried to do led control with using only one button. I wanted that when i press the button, next led will be logic 1. The problem is; leds don't be logic 1 in the right order.

My Vhdl Code:

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

entity btn_state_de is
    Port ( btn : in  STD_LOGIC;
           clk : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           led : out  STD_LOGIC_VECTOR (7 downto 0));
end btn_state_de;

architecture Behavioral of btn_state_de is

type state_type is (s0,s1,s2,s3,s4,s5,s6,s7,s8);
signal state : state_type;

begin

	process (clk,rst)
	begin
		if (rst='1') then
		state <= s0;		
			elsif (clk'event and clk='1') then			
				case state is
					when s0 =>
						if btn='1' then							
							state <= s1;
						else
						state <= s0;
						end if;
					when s1 =>
						if btn='1' then							
							state <= s2;					
						else
						state <= s1;
						end if;
					when s2 =>
						if btn='1' then							
							state <= s3;
						else
						state <= s2;
						end if;
					when s3 =>
						if btn='1' then							
							state <= s4;
						else
						state <= s3;
						end if;
					when s4 =>
						if btn='1' then							
							state <= s5;
						else
						state <= s4;
						end if;
					when s5 =>
						if btn='1' then							
							state <= s6;
						else
						state <= s5;
						end if;
					when s6 =>
						if btn='1' then							
							state <= s7;
						else
						state <= s6;
						end if;
					when s7 =>
						if btn='1' then							
							state <= s8;
						else
						state <= s7;
						end if;
					when s8 =>
						if btn='1' then							
							state <= s0;
						else
						state <= s8;
						end if;
				end case;
		end if;
	end process;
	
	process (state)
		begin
			case state is
				when s0 =>led<="00000000";
				when s1 =>led<="10000000";
				when s2 =>led<="01000000";
				when s3 =>led<="00100000";
				when s4 =>led<="00010000";
				when s5 =>led<="00001000";
				when s6 =>led<="00000100";
				when s7 =>led<="00000010";
				when s8 =>led<="00000001";
			end case;
		end process;
		


end Behavioral;

Thank you for your answers.
 

I think the problem is that you are using a very fast clock so each time you press the button you execute a few thousand steps and this gives you the impression of random steps.
Use a counter to change states once per second or something.

Alex
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top