Friday, 13 February 2015

Group 1--Vending machine design--Blog for second lab day (Feb. 13th. 2015)

This is our second lab day. Today, we have modified our block diagram to include more cases and functions, such as cancelling one purchase and getting the money back and we also changed some settings like displaying. 


Figure 1. The revised block diagram
Specifically, we have made the following changes or improvements.
1. Adding a cancel function and return the money which has been put into the machine before.

2. Using an LEDs above the switches to indicate the corresponding product when the product is purchased out instead of a 7-segment display.

3. Using the extra 7-segment display to show the number of 100p which would be taken from the machine.

4. The switch_error output was added into the product_price block to indicate the wrong input of the switches.

5. The cancelling situation should also be added to distinguish the situation of normal return or the cancelling return.


Then, we have designed the ASM charts and programming for the product choice and coin_input block, which are shown below.


SUBDESIGN product_choice

(
clk, reset,sw[14..0]: INPUT;
product_price_LSB[3..0], product_price_MSB[3..0], sw_error: OUTPUT;
)

BEGIN
IF (reset)THEN
product_price_LSB[]=B"0000" ; product_price_MSB[]=B"0000" ; sw_error=B"0";

ELSIF (sw[]==B"000000000000000")then
sw_error=B"0";

ELSIF (sw[]==B"000000000000001")then
product_price_LSB[]=B"0010" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000000000010")then
product_price_LSB[]=B"0010" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000000000100")then
product_price_LSB[]=B"0010" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000000001000")then
product_price_LSB[]=B"0101" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000000010000")then
product_price_LSB[]=B"0101" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000000100000")then
product_price_LSB[]=B"0101" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000001000000")then
product_price_LSB[]=B"1000" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000000010000000")then
product_price_LSB[]=B"1000" ; product_price_MSB[]=B"0000";
ELSIF (sw[]==B"000000100000000")then
product_price_LSB[]=B"1000" ; product_price_MSB[]=B"0000";

ELSIF (sw[]==B"000001000000000")then
product_price_LSB[]=B"0000" ; product_price_MSB[]=B"0001";

ELSIF (sw[]==B"000010000000000")then
product_price_LSB[]=B"0000" ; product_price_MSB[]=B"0001";

ELSIF (sw[]==B"000100000000000")then
product_price_LSB[]=B"0000" ; product_price_MSB[]=B"0001";

ELSIF (sw[]==B"001000000000000")then
product_price_LSB[]=B"0111" ; product_price_MSB[]=B"0001";

ELSIF (sw[]==B"010000000000000")then
product_price_LSB[]=B"0111" ; product_price_MSB[]=B"0001";

ELSIF (sw[]==B"100000000000000")then
product_price_LSB[]=B"0111" ; product_price_MSB[]=B"0001";

ELSE 
sw_error=B"1";
END IF;

END;

In details, there has 15 products designed to choose from. 
- Product 1-3 worth 20p. 
- Product 4-6 worth 50p. 
- Product 7-9 worth 80p.
- Product 10-12 worth 100p.
- Product 13-15 worth 170p

After the customer choose one of the fifteen products, the corresponding price was divided into two parts (the unit and the decade) to be displayed on two 7-segment indicators in decimal number. In addition, the unit of the price is set to be 10 because the smallest coin allowed is 10p.

Refer to the coin_input block, we decided to use an counter to calculate the whole amount of money the customer put in the machine for one purchase.



Figure 2. The ASM chart for Coin_input block in Figure 1.
Figure 2 shows a general process of input different kinds of coins. To achieve this function, the original code is shown below.

SUBDESIGN coin_receiver
(
clk, reset :INPUT ;
coin_input[3..0] :INPUT;
total_money_LSB[3..0], total_money_MSB[3..0] : OUTPUT;
)

VARIABLE
total_money_LSB[3..0], total_money_MSB[3..0] : DFF;

BEGIN
     total_money_LSB[].clk = clk;
    total_money_MSB[].clk = clk;
 
 IF (reset) THEN 
 total_money_LSB[].d = 0; 
 total_money_MSB[].d = 0;
 
 ELSIF (coin_input[0] == 1) THEN
    IF(total_money_LSB[].q != 9)THEN
    total_money_LSB[].d = total_money_LSB[].q + 1;
    total_money_MSB[].d = total_money_MSB[].q + 0;
 
 ELSIF(total_money_LSB[].q == 9) THEN
 total_money_LSB[].d = 0;
 total_money_MSB[].d = total_money_MSB[].q + 1;
 END IF;
 
 ELSIF (coin_input[1] == 1)THEN
 IF(total_money_LSB[].q < 8)THEN
 total_money_LSB[].d = total_money_LSB[].q + 2;
 total_money_MSB[].d = total_money_MSB[].q + 0;
 
 ELSIF(total_money_LSB[].q >= 8) THEN
 total_money_LSB[].d = total_money_LSB[].q - 8;
 total_money_MSB[].d = total_money_MSB[].q + 1;
 END IF;
 
 ELSIF (coin_input[2] == 1)THEN
 IF(total_money_LSB[].q < 5)THEN
 total_money_LSB[].d = total_money_LSB[].q + 5;
 total_money_MSB[].d = total_money_MSB[].q + 0;
 
 ELSIF(total_money_LSB[].q >= 5 & total_money_LSB[].q <= 9) THEN
 total_money_LSB[].d = total_money_LSB[].q - 5;
 total_money_MSB[].d = total_money_MSB[].q + 1;
 END IF;
 
 ELSIF (coin_input[3] == 1)THEN
 total_money_LSB[].d = total_money_MSB[].q + 0;
 total_money_MSB[].d = total_money_MSB[].q + 1;
 
 ELSIF (coin_input[] == B"0000")THEN
 total_money_LSB[].d = total_money_LSB[].q + 0;
 total_money_MSB[].d = total_money_MSB[].q + 0;
 
 END IF;
END;

No comments:

Post a Comment