Digital Electronics System Design, 2014-1015 Fall

You might also like

You are on page 1of 14

Digital Electronics System Design, 2014-1015 Fall

VHDL Design Project


Project #3 Vending Machine
Azamat Kenesbekov
Sanzhar Askaruly

1
Introduction
It is interesting that the first vending machines appeared in the first century. Their functionality
was to dispense holy water after receiving a coin. These had lever-based working principle. With
the evolution of electronics in the 20th century, modern vending machines are implemented using
microcontrollers in a number of ways. The goal of our group is to design a vending machine
described in VHDL language, which can be further applied into FPGA circuits. The prototype is
to vend chocolates that cost 40 tenge. The machine is able to accept only coins of 5, 10 and 20
tenge. If there are enough coins deposited, the user is asked to select the chocolate of interest.
After responding, the user receives chocolate and receives change, if he had put more than 40
tenge.

System Description
As in the real vending machine system, we need 5, 10 and 20 tenge coins to get chocolate. In the
VHDL this can be implemented, with coins to be the input and the chocolate giving to be the
output.
Inputs:
x  is for 5 tenge, y  is 10 for tenge, z  is for 20 tenge
a  is for chocolate 1, b  is 10 for chocolate 2, c  is for chocolate 3
reset  is to return the state to empty
Outputs:
ch1  is for input a, ch2  is for input b, ch3 is for input c.
change 1  is for 5 tenge, change 2  is for 10 tenge, change 3  is for 15 tenge
States:
There are 12 states in the system. They are grouped according to the deposit.
Empty: Vending machine is empty. The system starts from this state.
Five: In this state vending machine has 5 tenge deposited.
Ten: In this state vending machine has 10 tenge deposited.
Fifteen: In this state vending machine has 15 tenge deposited.
Twenty: In this state vending machine has 20 tenge deposited.
TwentyFive: In this state vending machine has 25 tenge deposited.
Thirty: In this state vending machine has 30 tenge deposited.
ThirtyFive: In this state vending machine has 35 tenge deposited.
Forty: In this state vending machine has 40 tenge deposited.
FortyFive: In this state vending machine has 45 tenge deposited, 5 tenge for change.
Fifty: In this state vending machine has 50 tenge deposited, 10 tenge for change.
FiftyFive: In this state vending machine has 55 tenge deposited, 15 tenge for change.

We came up with FSM provided below. In this diagram, the cases, when the vending machine
should give change, are also considered.

2
State Diagram

3
Simulation Results
Testbench #1
Title: “User receives Chocolate C and the change of 15 tenge”
Description: User operates successful transaction. He wants to get chocolate C, which
costs 40 tenge. To do that, he/she initially puts 35 tenge and after that a user
puts 20 tenge and chooses chocolate C. After that the vending machine
responds that chocolate 3 is chosen and gives back 15 tenge change.
Main Success 1. Vending machine is on, deposit cash is initialized
2. User inputs 5 tenge coins during 70 ns (35 tenge in total), vending is
Scenario:
waiting for further actions
3. User inputs another 20 tenge after 20 ns break, and now user is given
to make choice of chocolates
4. The user chooses Chocolate C. We also note that, simultaneous
choice of chocolate with coin input was excluded. So that some time
should pass after coin input to choose chocolate correctly.
5. The final output is seen in 100ns time (Ch3 and Change3 is 1).

The code snippet for the case described above can be seen in Appendix B. Testbench #1

“User receives Chocolate C and the change of 15 tenge”

4
Testbench #2
Title: “User receives Chocolate B and the change of 10 tenge”
Description: User operates successful transaction. He wants to get chocolate B, which
costs 40 tenge. To do that, he/she initially puts 20 tenge and after that a user
puts 10 tenge and then puts 20 tenge more. Then the user chooses chocolate
B. After that the vending machine responds that chocolate 2 is chosen and
gives back 10 tenge change immediately. Here, it should be noted that
vending machine discards all the choices, if deposit is not full.
Main Success 1. Vending machine is on, deposit cash is initialized
2. User inputs 5 tenge coins during 40 ns (20 tenge in total), vending is
Scenario:
waiting for further actions
3. User puts another 10 tenge after 30 ns break, and 20 tenge more right
after. Now user has 50 tenge of deposit and hence is given to make
choice of chocolates
4. The user chooses Chocolate B. In this case, as well as in the previous,
the vending machine responds immediately.
5. The final output is seen in 120ns time (Ch2 and Change2 is 1).

The code snippet for the case described above can be seen in Appendix B. Testbench #2

“User receives Chocolate B and the change of 10 tenge”

5
Testbench #3
Title: “User receives Chocolate A and no change”
Description: User operates successful transaction. He wants to get chocolate A, which
costs 40 tenge. To do that, he/she initially puts 20 tenge, takes some time to
seek for another 20 tenge and puts them. Then the user chooses chocolate A.
Right after that, the vending machine responds that chocolate 1 is chosen and
gives out chocolate. In this case, there is no need to give change, since the
user has only 40 tenge of deposit.
Main Success 1. Vending machine is on, deposit cash is initialized
2. User inputs 5 tenge coins during 40 ns (20 tenge in total), vending is
Scenario:
waiting for further actions
3. User takes break for 20 ns and puts another series of 5 tenge coins
during 40 ns. Now, user`s deposit is 40 tenge overall. Hence, the user
has possibility to make choice of chocolates.
4. The user chooses Chocolate A. In this case, as well as in the previous,
the vending machine responds immediately.
5. The final output is seen in 100ns time (Ch1 signal is 1).

The code snippet for the case described above can be seen in Appendix B. Testbench #3

“User receives Chocolate A and no change”

6
Testbench #4
Title: “User does not have enough deposit to choose chocolate. The timeout error
for user”
Description: User operates unsuccessful transaction. He wants to get chocolate B, which
costs 40 tenge. However, he only has 30 tenge of deposit. User initially puts
20 tenge, takes some time to seek for another 10 tenge and puts the coin.
Then the user chooses chocolate B. However, vending machine ignores this
input and waits for more money. But, unfortunately, user does not have more
money to put. Time is elapsed.
Main Success 1. Vending machine is on, deposit cash is initialized
2. User inputs 5 tenge coins during 40 ns (20 tenge in total), vending is
Scenario:
waiting for further actions
3. User takes break for 30 ns and puts another 10 tenge coin. Now,
user`s deposit is 30 tenge overall. Hence, the user cannot make choice
of chocolates.
4. The user chooses Chocolate B. Vending ignores the wish of user,
since deposit is not enough to complete transaction.
5. The cycle finishes at 140ns, and repeats again.

The code snippet for the case described above can be seen in Appendix B. Testbench #4

“User does not have enough deposit to choose chocolate. The timeout error for user”

7
Conclusions
To conclude, it should be mentioned that the vending machine works very well. It can operate at
continuous coin input or interruptive coin input. The vhdl code for the machine is pretty simple
and depends on the clock cycle. Surely, some simulations which presented above are imprecise
because it is very difficult to press the button only for some nanoseconds. However, they
represent general behavior of human who make mistakes (inserting surplus coins, pressing
buttons before there is enough money). So, from this project we learnt how to correctly code the
vending machine, understood the principles behind this and how to test it. The improvements
that can be implemented in this project include the increasing number of the chocolates,
increasing variety of coins.

8
Appendix A

Design File
main.vhd
library ieee;
use ieee.std_logic_1164.all;
entity vending_machine is
port (clk, reset, a, b, c, x, y, z: in bit ; --x=5;y=10;z=20 tenge
ch1,ch2,ch3,change1,change2,change3 : out bit);--change1=5;change2=10;change3=15 tenge.
end vending_machine ;
architecture behavior of vending_machine is
TYPE state IS (empty, five, ten, fifteen, twenty, twentyfive, thirty, thirtyfive,
fourty,fourtyfive,fifty,fiftyfive);
SIGNAL pr_state, next_state : state;
begin
PROCESS(clk, reset)
begin
IF (reset = '1') THEN
pr_state <= empty;
ELSIF (clk'event) AND (clk = '1') THEN
pr_state <= next_state;
END IF;
END PROCESS;
--declaring the inputs/outputs and states as well as showing that rising edge is for changing
state
PROCESS(pr_state, x, y, z, a, b, c)
BEGIN
CASE pr_state IS

WHEN empty =>


IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=empty;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= five;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=ten;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twenty;
END IF;
--initial state no outputs

WHEN five =>


IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=five;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= ten;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fifteen;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twentyfive;
END IF;
--five tenge in machine no outputs

WHEN ten =>


IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=ten;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= fifteen;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
9
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twenty;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirty;
END IF;
--ten tenge in machine no outputs

WHEN fifteen=>
IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fifteen;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= twenty;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twentyfive;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirtyfive;
END IF;
--fifteen tenge no outputs

WHEN twenty=>
IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twenty;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= twentyfive;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirty;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fourty;
END IF;

WHEN twentyfive=>
IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=twentyfive;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= thirty;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirtyfive;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fourtyfive;
END IF;

WHEN thirty=>
IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirty;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= thirtyfive;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fourty;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fifty;
10
END IF;

WHEN thirtyfive=>
IF ((x='0' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0')) THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=thirtyfive;
ELSIF ((x='1' AND y='0' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <= fourty;
ELSIF ((x='0' AND y='1' AND z='0') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0';change1<='0';change2<='0';change3<='0';
next_state <=fourtyfive;
ELSIF ((x='0' AND y='0' AND z='1') AND (a='1' OR b='1' OR c='1' OR a='0' OR b='0' OR c='0'))
THEN
ch1<='0';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state <=fiftyfive;
END IF;

WHEN fourty=>
IF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='0') THEN
ch1<='0';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=fourty;
ELSIF (x='0' AND y='0' AND z='0' AND a='1' AND b='0' AND c='0') THEN
ch1<='1';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='1' AND c='0') THEN
ch1<='0';ch2<='1'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='1') THEN
ch1<='0';ch2<='0'; ch3<='1'; change1<='0';change2<='0';change3<='0';
next_state<=empty;
END IF;
--fourty tenge in machine gives output depending on the type of chocolate (a,b,c)

WHEN fourtyfive=>
IF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='0') THEN
ch1<='0';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=fourtyfive;
ELSIF (x='0' AND y='0' AND z='0' AND a='1' AND b='0' AND c='0') THEN
ch1<='1';ch2<='0'; ch3<='0'; change1<='1';change2<='0';change3<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='1' AND c='0') THEN
ch1<='0';ch2<='1'; ch3<='0'; change1<='1';change2<='0';change3<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='1') THEN
ch1<='0';ch2<='0'; ch3<='1'; change1<='1';change2<='0';change3<='0';
next_state<=empty;
END IF;
--gives output depending on the type of chocolate and gives out 5 tenge

WHEN fifty=>
IF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='0') THEN
ch1<='0';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=fifty;
ELSIF (x='0' AND y='0' AND z='0' AND a='1' AND b='0' AND c='0') THEN
ch1<='1';ch2<='0'; ch3<='0'; change2<='1';change3<='0';change1<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='1' AND c='0') THEN
ch1<='0';ch2<='1'; ch3<='0'; change2<='1';change3<='0';change1<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='1') THEN
ch1<='0';ch2<='0'; ch3<='1'; change2<='1';change3<='0';change1<='0';
next_state<=empty;
END IF;
--gives output depending on the type of chocolate and gives out 10 tenge

WHEN fiftyfive=>
IF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='0') THEN
ch1<='0';ch2<='0'; ch3<='0'; change1<='0';change2<='0';change3<='0';
next_state<=fiftyfive;
ELSIF (x='0' AND y='0' AND z='0' AND a='1' AND b='0' AND c='0') THEN
ch1<='1';ch2<='0'; ch3<='0'; change3<='1';change2<='0';change1<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='1' AND c='0') THEN
ch1<='0';ch2<='1'; ch3<='0'; change3<='1';change2<='0';change1<='0';
next_state<=empty;
ELSIF (x='0' AND y='0' AND z='0' AND a='0' AND b='0' AND c='1') THEN
ch1<='0';ch2<='0'; ch3<='1'; change3<='1'; change2<='0';change1<='0';
11
next_state<=empty;
--gives output depending on the type of chocolate and gives out 15 tenge

END IF;
END CASE;
END PROCESS;
end behavior;

Appendix B

Test Files
Testbench #1. “User receives Chocolate C and the change of 15 tenge”
55tenge.vhd
ENTITY vending_test IS
END vending_test;

ARCHITECTURE test_file OF vending_test is


component vending_machine is
port (clk, reset, x, y, z, a, b, c: in bit;
ch1,ch2, ch3, change1, change2, change3: out bit);
end component;

SIGNAL clk: BIT := '1';


SIGNAL y: BIT;
SIGNAL x: BIT;
SIGNAL z: BIT;
SIGNAL a: BIT;
SIGNAL b: BIT;
SIGNAL c: BIT;
SIGNAL ch1:BIT;
SIGNAL ch2:BIT;
SIGNAL ch3:BIT;
SIGNAL change1:BIT;
SIGNAL change2:BIT;
SIGNAL change3:BIT;
SIGNAL reset:BIT;

begin
dut: vending_machine PORT MAP (a => a, b => b, c => c, reset => reset, clk => clk, x => x, y =>
y, z => z, ch1 => ch1, ch2 => ch2, ch3 => ch3, change1 => change1, change2 => change2, change3 =>
change3);
process
begin
WAIT FOR 5 ns;
clk <= NOT clk;
end process;
PROCESS
BEGIN
x <= '1';y <='0'; z<='0'; a<='0'; b<='0'; c<='0';
WAIT FOR 70 ns;
x <= '0';y <='0'; z<='0';a<='1';b<='0';c<='0';
WAIT FOR 20 ns;
x <= '0'; y <='0'; z<='1'; a<='0'; b<='1'; c<='0';
WAIT FOR 10 ns;
x <= '0'; y <='0'; z<='0'; a<='0'; b<='0'; c<='1';
WAIT FOR 30 ns;
END PROCESS;
END test_file;

Testbench #2. “User receives Chocolate B and the change of 10 tenge”


10tenge_change.vhd
ENTITY vending_test IS
END vending_test;

ARCHITECTURE test_file OF vending_test is


component vending_machine is
port (clk, reset, x, y, z, a, b, c: in bit;
ch1,ch2, ch3, change1, change2, change3: out bit);
end component;

12
SIGNAL clk: BIT := '1';
SIGNAL y: BIT;
SIGNAL x: BIT;
SIGNAL z: BIT;
SIGNAL a: BIT;
SIGNAL b: BIT;
SIGNAL c: BIT;
SIGNAL ch1:BIT;
SIGNAL ch2:BIT;
SIGNAL ch3:BIT;
SIGNAL change1:BIT;
SIGNAL change2:BIT;
SIGNAL change3:BIT;
SIGNAL reset:BIT;

begin
dut: vending_machine PORT MAP (a => a, b => b, c => c, reset => reset, clk => clk, x => x, y =>
y, z => z, ch1 => ch1, ch2 => ch2, ch3 => ch3, change1 => change1, change2 => change2, change3 =>
change3);
process
begin
WAIT FOR 5 ns;
clk <= NOT clk;
end process;
PROCESS
BEGIN
x <= '1';y <='0'; z<='0'; a<='1'; b<='0'; c<='0';
WAIT FOR 40 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='0';c<='0';
WAIT FOR 30 ns;
x <= '0'; y <='1'; z<='0'; a<='0'; b<='1'; c<='0';
WAIT FOR 10 ns;
x <= '0';y <='0'; z<='1';a<='0';b<='0';c<='1';
WAIT FOR 10 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='0';c<='0';
WAIT FOR 30 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='1';c<='0';
WAIT FOR 20 ns;
END PROCESS;
END test_file;

Testbench #3. “User receives Chocolate A and no change”

no_change.vhd
ENTITY vending_test IS
END vending_test;

ARCHITECTURE test_file OF vending_test is


component vending_machine is
port (clk, reset, x, y, z, a, b, c: in bit;
ch1,ch2, ch3, change1, change2, change3: out bit);
end component;

SIGNAL clk: BIT := '1';


SIGNAL y: BIT;
SIGNAL x: BIT;
SIGNAL z: BIT;
SIGNAL a: BIT;
SIGNAL b: BIT;
SIGNAL c: BIT;
SIGNAL ch1:BIT;
SIGNAL ch2:BIT;
SIGNAL ch3:BIT;
SIGNAL change1:BIT;
SIGNAL change2:BIT;
SIGNAL change3:BIT;
SIGNAL reset:BIT;

begin
dut: vending_machine PORT MAP (a => a, b => b, c => c, reset => reset, clk => clk, x => x, y =>
y, z => z, ch1 => ch1, ch2 => ch2, ch3 => ch3, change1 => change1, change2 => change2, change3 =>
change3);
process

13
begin
WAIT FOR 5 ns;
clk <= NOT clk;
end process;
PROCESS
BEGIN
x <= '1';y <='0'; z<='0'; a<='0'; b<='0'; c<='0';
WAIT FOR 40 ns;
x <= '0';y <='0'; z<='0';a<='1';b<='0';c<='0';
WAIT FOR 20 ns;
x <= '1';y <='0'; z<='0'; a<='1'; b<='0'; c<='0';
WAIT FOR 40 ns;
x <= '0';y <='0'; z<='0';a<='1';b<='0';c<='0';
WAIT FOR 30 ns;
END PROCESS;
END test_file;

Testbench #4. “User does not have enough deposit to choose chocolate. The timeout error
not_enough.vhd
ENTITY vending_test IS
END vending_test;

ARCHITECTURE test_file OF vending_test is


component vending_machine is
port (clk, reset, x, y, z, a, b, c: in bit;
ch1,ch2, ch3, change1, change2, change3: out bit);
end component;

SIGNAL clk: BIT := '1';


SIGNAL y: BIT;
SIGNAL x: BIT;
SIGNAL z: BIT;
SIGNAL a: BIT;
SIGNAL b: BIT;
SIGNAL c: BIT;
SIGNAL ch1:BIT;
SIGNAL ch2:BIT;
SIGNAL ch3:BIT;
SIGNAL change1:BIT;
SIGNAL change2:BIT;
SIGNAL change3:BIT;
SIGNAL reset:BIT;

begin
dut: vending_machine PORT MAP (a => a, b => b, c => c, reset => reset, clk => clk, x => x, y =>
y, z => z, ch1 => ch1, ch2 => ch2, ch3 => ch3, change1 => change1, change2 => change2, change3 =>
change3);
process
begin
WAIT FOR 5 ns;
clk <= NOT clk;
end process;
PROCESS
BEGIN
x <= '1';y <='0'; z<='0'; a<='1'; b<='0'; c<='0';
WAIT FOR 40 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='0';c<='0';
WAIT FOR 30 ns;
x <= '0'; y <='1'; z<='0'; a<='0'; b<='1'; c<='0';
WAIT FOR 10 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='0';c<='1';
WAIT FOR 10 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='0';c<='0';
WAIT FOR 30 ns;
x <= '0';y <='0'; z<='0';a<='0';b<='1';c<='0';
WAIT FOR 20 ns;
END PROCESS;
END test_file;

14

You might also like