Reputation: 53
So I'm trying to write a VHDL program that runs a simple vending machine. It takes in quarters, nickels, and dimes, and moves between the states Start, to 45 cents in increments of 5 cents. When state 25 cents is reached, it distributes a product, if it goes past 25, like say previous state is 20 and a quarter is added to bring it up to 45, then it cascades down the states, distributing change until it reaches 25. I also set up a reset.
Now the problem I'm having is simple but frustratingly vague. There are two processes, the first fsm1, holds all the code for moving between the different states of change etc. The second process is basically to allow for the asynchronous reset. It's the second process, fsm2, where I'm having problems. As it is now, I'm getting a syntax error that simply says something is wrong near the 'AND'. That's it. If anyone can clear up what the problem is I'd really appreciate it. The code is below.
Thanks in advance.
-- Vending Machine FSM from Lab 8
-- There are 10 States, 3 Inputs, and 2 Outputs
-- When State is Start, Product is 0, Change is 0
-- Start moves to Five when Nickle is Pushed
-- Start moves to Ten when Dime is Pushed
-- Start moves to Twentyfive when Quarter is Pushed
-- When State is Five, Product is 0, Change is 0
-- Five moves to Ten when Nickle is Pushed
-- Five moves to Fifteen when Dime is Pushed
-- Five moves to Thirty when Quarter is Pushed
-- When State is Ten, Product is 0, Change is 0
-- Ten moves to Fifteen when Nickle is Pushed
-- Ten moves to Twenty when Dime is Pushed
-- Ten moves to Thirtyfive when Quarter is Pushed
-- When State is Fifteen, Product is 0, Change is 0
-- Fifteen moves to Twenty when Nickle is Pushed
-- Fifteen moves to Twentyfive when Dime is Pushed
-- Fifteen moves to Fourty when Quarter is Pushed
-- When State is Twenty, Product is 0, Change is 0
-- Twenty moves to Twentyfive when Nickle is Pushed
-- Twenty moves to Thirty when Dime is Pushed
-- Twenty moves to Fourtyfive when Quarter is Pushed
-- When State is Twentyfive, Product is 1, Change is 0
-- Twentyfive moves to Start unconditionally
-- When State is Thirty, Product is 0, Change is 1
-- Thirty moves to Twentyfive unconditionally
-- When State is Thirtyfive, Product is 0, Change is 1
-- Thirtyfive moves to Thirty unconditionally
-- When State is Fourty, Product is 0, Change is 1
-- Fourty moves to Thirtyfive unconditionally
-- When State is Fourtyfive, Product is 0, Change is 1
-- Fourtyfive moves to Fourty unconditionally
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY vending IS
PORT (
reset : IN std_logic;
clock : IN std_logic;
QDN : IN std_logic_vector(2 DOWNTO 0);
PC : OUT std_logic_vector(1 DOWNTO 0)
);
END vending;
ARCHITECTURE behavior OF vending IS
TYPE statetype IS (Start, Five, Ten, Fifteen, Twenty, Twentyfive, Thirty, Thirtyfive, Fourty, Fourtyfive);
SIGNAL currentstate, nextstate : statetype;
BEGIN
fsm1: PROCESS (QDN, currentstate)
BEGIN
CASE currentstate IS
WHEN Start =>
PC <= "00";
CASE QDN IS
WHEN "000" =>
nextstate <= Start;
WHEN "001" =>
nextstate <= Five;
WHEN "010" =>
nextstate <= Ten;
WHEN "100" =>
nextstate <= Twentyfive;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN Five =>
PC <= "00";
CASE QDN IS
WHEN "000" =>
nextstate <= Five;
WHEN "001" =>
nextstate <= Ten;
WHEN "010" =>
nextstate <= Fifteen;
WHEN "100" =>
nextstate <= Thirty;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN Ten =>
PC <= "00";
CASE QDN IS
WHEN "000" =>
nextstate <= Ten;
WHEN "001" =>
nextstate <= Fifteen;
WHEN "010" =>
nextstate <= Twenty;
WHEN "100" =>
nextstate <= Thirtyfive;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN Fifteen =>
PC <= "00";
CASE QDN IS
WHEN "000" =>
nextstate <=Fifteen;
WHEN "001" =>
nextstate <= Twenty;
WHEN "010" =>
nextstate <= Twentyfive;
WHEN "100" =>
nextstate <= Fourty;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN Twenty =>
PC <= "00";
CASE QDN IS
WHEN "000" =>
nextstate <= Twenty;
WHEN "001" =>
nextstate <= Twentyfive;
WHEN "010" =>
nextstate <= Thirty;
WHEN "100" =>
nextstate <= Fourtyfive;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN Twentyfive =>
PC <= "10";
nextstate <= Start;
WHEN Thirty =>
PC <= "01";
nextstate <= Twentyfive;
WHEN Thirtyfive =>
PC <= "01";
nextstate <= Thirty;
WHEN Fourty =>
PC <= "01";
nextstate <= Thirtyfive;
WHEN Fourtyfive =>
PC <= "01";
nextstate <= Fourty;
END CASE;
END PROCESS;
fsm2: PROCESS (reset, clock)
BEGIN
IF (reset = '0') THEN
currentstate <= Start;
ELSEIF (clock'EVENT) AND (clock = '1') THEN
currentstate <= nextstate;
END IF;
END PROCESS;
END behavior;
Upvotes: 0
Views: 93
Reputation:
ELSEIF (clock'EVENT) AND (clock = '1') THEN
elsif
not elseif
After which your code analyzes.
Upvotes: 2