Help with State Machines and Timers

OP #3381553
Rate this post
• ▲ useful
▼ not useful
Hey everyone, hoping you guys could give me some tips on how to finish 
my last VHDL assignment for this semester.

We have to program a vending machine according to assignment 
specifications. Part of this is displaying the coin inserted into the 
machine for 4 seconds after it has been inserted. Alternatively, if the 
coin you inserted causes the total amount to exceed the price, the SSD's 
must display the change being returned.

I have a state machine with 4 states: reset, ready, processing, paid.

In the ready state, the machine accepts new coins. When a new coin is 
inserted it goes to the 'processing' state. This state sets an enable 
signal (process_en) that goes to another component that calculates how 
much has been paid, how much is remaining, and if there is any change.

What I am struggling to do is set up a timer that counts for 4 seconds 
(with a 100Mhz clock) ONCE when process_en goes high, before sending a 
signal back to the state machine (state_en) that allows it to either go 
back  to ready state, or on to the finished state.

Below is what I have now, which simulates what I want but won't 
synthesize (I understand why, I just don't know how else to implement 
it). I feel like I'm missing something obvious, so if anyone could give 
me an idea of what else might work I would greatly appreciate it.

Timer:
1
counter : process (clk, timer_en) is
2
begin
3
if timer_en <= '1' then
4
  if clk'event and clk = '1' then
5
    timer <= '1';
6
    timer_count <= timer_count + 1;
7
    --if timer_count <= "10111110101111000010000000" then
8
    if timer_count = "0000000000000000000000000100" then
9
      timer_count <= "00000000000000000000000000";
10
      timer <= '0';
11
    end if;
12
  end if;
13
end if;
14
end process;

Timer Controller:
1
timer_controller : process is
2
begin
3
wait until process_en = '1';
4
  state_en <= '0';
5
  timer_en <= '1';
6
wait until timer = '0';
7
  timer_en <= '0';
8
  state_en <= '1';
9
end process;

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.