State machine - Vending machine - strange behaviour

Joined
Dec 17, 2011
Messages
2
Reaction score
0
Hello,

I'm trying to create vending machine in VHDL. It should has two kinds of products and remember theirs price and amount. My vending machine allows only tokens. When my machine is in state - payment - it starts to loop(variable vtokens is growing), ignoring conditional statement. What is wrong with my code?

Code:
    PROCESS (clock,reset)
    BEGIN
        IF (reset='1') THEN
            fstate <= init_towar1;
        ELSIF (clock'event and clock = '1') THEN
            fstate <= reg_fstate;
        END IF;
    END PROCESS;

    PROCESS (fstate)
			variable vprice1 : integer range 1 to 7;
			variable vamount1 : integer range 0 to 15;
			variable vprice2 : integer range 1 to 7;
			variable vamount2 : integer range 0 to 15;
			variable vprice : integer range 1 to 7;
			variable vamount : integer range 0 to 15;
			variable vtokens : integer range 0 to 7;
			variable vselection: integer range 0 to 2;
    BEGIN

        CASE fstate IS
				.
				.
				.
            WHEN payment =>
                IF ((IN_resign = '1')) THEN
							reg_fstate <= return;
                ELSIF ((IN_tokens = '1')) THEN
                    	vtokens := vtokens+1;
                    IF ((vtokens < vprice)) THEN
								reg_fstate <= payment;
					ELSIF (vtokens = vprice) THEN
								reg_fstate <= paid;
					ELSE
								reg_fstate <= payment;
					END IF;		
                ELSE
                    reg_fstate <= payment;
                END IF;
			.
			.
			.
    END PROCESS;
 
Joined
Mar 10, 2008
Messages
348
Reaction score
0
PROCESS (fstate, IN_resign, .....)

You need to have all input signals in the sensivitylist ... in order to get the correct combinatorial logic.
 
Joined
Mar 10, 2008
Messages
348
Reaction score
0
BEGIN

reg_fstate <= fstate; <<<<< Default value for reg_state (important)

CASE fstate IS

Try this - could be the solution
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top