Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21602 Discussions

Toggling switch button to start and pause using logic '0' or '1'

Altera_Forum
Honored Contributor II
2,939 Views

Hi Altera Friends, 

 

I have an issue with design of clock. I have written a program for a clock to count from 0 to 9 and returns to zero. I use a switch as start/stop as in std_logic and i want a logic that I can use that when i press button ones, it will toggle between 1 and 0 so that the button can perform the two tasks start and stop. I will appreciate your urgent reply. 

Thanks.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
1,967 Views

please post the code you have already done with specific questions about what the problem is.

0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

PORT 

clOCK : IN STD_LOGIC; 

ce : IN STD_LOGIC; 

rst : IN STD_LOGIC; 

d1: BUFFER STD_LOGIC_VECTOR (3 DOWNTO 0); 

clk_2: OUT STD_LOGIC 

); 

-- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE! 

 

END mod_mod; 

 

-- Architecture Body 

ARCHITECTURE mod_mod_architecture OF mod_mod IS 

SIGNAL M: STD_LOGIC; 

 

BEGIN 

PROCESS (clock,rst,M) 

BEGIN 

IF (rst = '0') THEN 

d1 <= "0000"; 

ELSIF (clOCK 'EVENT AND clOCK='1') THEN 

IF (ce = '0') THEN 

d1<= "0000" ; 

ELSE  

d1<= d1 + '1'; 

M<= '0'; 

END IF; 

IF d1= "1001" THEN 

d1<= "0000"; 

M<= '1'; 

END IF; 

END IF; 

clk_2<=M; 

END PROCESS; 

end mod_mod; 

 

I want ce to perform the function of start and stop.I want it to be like if i press ce switch it should change the logic from 1 to 0 to purse and for the next state to start after pressing same ce switch.
0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

Hi Ebony, 

 

Not sure what you are referring to here. If you wanted a CE using a KEY, you could simply read the KEY press (remember in DE2 boards its active LOW) and feed it as an enable input in a tri-state buffer. When key isnt pressed the clock output will be driven to Z. Not sure if this is what you wanted!? 

 

BP
0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

if i press the switch button on the altera board down without removing hand, it will purse or stop. if i rmove my hand from the button, it will start counting. I want the state to change such that if i press the switch button and remove my hand it will purse or stop and if i press the switch button and remove my hand next it should start counting. 

 

ce i assigned to start/stop switch. 

 

hope you understand it?
0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

if i press the switch button on the altera board down without removing hand, it will purse or stop. if i rmove my hand from the button, it will start counting. I want the state to change such that if i press the switch button and remove my hand it will purse or stop and if i press the switch button and remove my hand next it should start counting. 

 

ce is assigned as start/stop switch button. 

 

hope you understand it?
0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

If I correctly understood your needs, you can try changing your code this way: 

 

SIGNAL M: STD_LOGIC; SIGNAL run: STD_LOGIC; SIGNAL last_ce: STD_LOGIC; PROCESS (clock,rst,M) BEGIN IF (rst = '0') THEN d1 <= "0000"; run <= '0'; last_ce <= ce; ELSIF (clOCK 'EVENT AND clOCK='1') THEN IF (run='1') THEN d1<= d1 + '1'; M <= '0'; END IF; IF d1= "1001" THEN d1<= "0000"; M <= '1'; END IF; IF (ce='1' and last_ce='0') run <= not run; END IF; END IF; clk_2<=M; END PROCESS; 

 

Regards
0 Kudos
Altera_Forum
Honored Contributor II
1,967 Views

still not working

0 Kudos
Reply