I need some help with getting the system to do what I want. As it is now, when one of the coin-buttons are pressed, the sum-so-far will keep on incrementing every clock cycle for as long as the button is pressed.
I would like for the system to increment the sum only once every time a button is pressed.
So far, I have tried different solutions myself, but none seem to work.
1) Debounce the switch, if you're not already doing that
2) Use a state-machine. When it sees the button pressed, it goes to state S1 where your count is incremented, it then goes to state S2. It remains in S2 until it sees the button UN-pressed. Then go to your idle state.
case state is
when idle =>
if button='1' then
state<=S1;
end if;
when S1 =>
count=count+1;
state <= s2;
when s2 =>
if button='0' then
state<=idle;
end if;
end case;
I have worked a little on my project in accordance with your advice. The buttons are responding well now, but there is still a little problem.
Once the sum-so-far becomes greater than the price, the price is automatically deducted from the sum, which is not the intention. This should only happen when the user presses the "buy"-button.
The help has been great so far, can you help me with the last part?
The revised VHDL code of the entity is in this pastie:
I have just solved it myself. If anyone is interested, this is the pastie:
http://pastie.org/5476250
Thanks for the help, you saved my day and my grade!