Continue to Site

Welcome to

Welcome to our site! 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.

Need help with VHDL-project

Not open for further replies.


Newbie level 3
Dec 3, 2012
Reaction score
Trophy points
Activity points

Not sure if I'm posting this the right place, but here goes:

I'm working on a vending machine project. The VHDL code for the entity is in this pastie:

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.

Two things:

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.
Thanks for the advice barry.

The buttons have already been debounced and synchronized.

I will try out the state machine and get back to you. Would you mind perhaps giving an example of how to do it?

something like:

case state is
	when idle =>
		if button='1' then
		end if;
	when S1 =>
		state <= s2;
	when s2 =>
		if button='0' then
		end if;	
end case;
This obviously has to be inside a clocked process.

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:

- - - Updated - - -

I have just solved it myself. If anyone is interested, this is the pastie:
Thanks for the help, you saved my day and my grade!

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to