Forum Discussion
Altera_Forum
Honored Contributor
14 years agoThe best way to achieve what you are asking is to draw yourself a flow chart. If you are looking for an on/off button with just one push then you would have something like this.
process(clk) begin
if(rising_edge(clk)) then
button_prev <= button_curr;
button_curr <= button;
end if;
end process
Button_pulse <= button_curr AND (NOT button_prev);
Now, you can register the pulse, add debounce, ect. It is up to you. Next, you need to create a state machine to handle the enable to your counter. From what you've described you have 2 states, on and off. you start in the off state, if the button_pulse = 1 then you go to the on state and again if the button pulse is 1 you go back to the off state. Then you describe your counter enable as 1 when in the on state and 0 when in the off. I recommend drawing this out and then creating your state machine to match your diagram.