# Need help with VHDL-project

Status
Not open for further replies.

#### peter92

##### Newbie level 3
Hi

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:

http://pastie.org/5475527

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.

#### barry

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.

peter92

### peter92

Points: 2

#### peter92

##### Newbie level 3

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?

#### barry

something like:

Code:
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;

peter92

### peter92

Points: 2

#### TrickyDicky

This obviously has to be inside a clocked process.

#### barry

This obviously has to be inside a clocked process.

Well, I can't give him ALL the answers.

#### peter92

##### Newbie level 3
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:

http://pastie.org/5476200

- - - Updated - - -

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!

Status
Not open for further replies.