Friday, 27 February 2015

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

This is our forth lab day. Our objective today was to revise the ASM chart for some of the blocks and try to code for them.
Figure 1. Revised block diagram
Figure 1 is the revised (forth edition) block diagram for our design. Compared to the one in week three, one new block has been added to obtain the correct number of coins in the machine after giving out the change. As for other blocks, they remained the same. 

By this week, we have also finished the code for all imporatant functional blocks (1st edition).
Codes for the 'product_choice' block:
SUBDESIGN product_choice

(
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;


Codes for 'coin_input' block:
SUBDESIGN coin_input
(
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_LSB[].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;


Codes for 'counter' block:
SUBDESIGN counter
(
clk, reset :INPUT ;
coin_input[3..0]      :INPUT;
temp_10p[3..0] , temp_20p[3..0] , temp_50p[3..0] , temp_100p[3..0] : OUTPUT;
)

VARIABLE
count_10p[3..0] , count_20p[3..0] , count_50p[3..0] , count_100p[3..0] : DFF;

BEGIN
           
     count_10p[].clk  = clk;
            count_20p[].clk  = clk;
            count_50p[].clk  = clk;
            count_100p[].clk = clk;
           
temp_10p[] = count_10p[];
temp_20p[] = count_20p[];
temp_50p[] = count_50p[];
temp_100p[] = count_100p[];
           
            IF (reset) THEN
            count_10p[].d  = 0;
            count_20p[].d  = 0;
            count_50p[].d  = 0;
            count_100p[].d = 0;

           
            ELSIF (coin_input[0] == 1) THEN
        count_10p[].d   = count_10p[].q + 1;
                     count_20p[].d   = count_20p[].q  + 0;
                     count_50p[].d   = count_50p[].q  + 0;
                     count_100p[].d  = count_100p[].q + 0;
                    
                     ELSIF (coin_input[1] == 1) THEN
           count_10p[].d   = count_10p[].q  + 0;
                        count_20p[].d   = count_20p[].q  + 1;
                        count_50p[].d   = count_50p[].q  + 0;
                        count_100p[].d  = count_100p[].q + 0;
                    
                        ELSIF (coin_input[2] == 1) THEN
              count_10p[].d   = count_10p[].q  + 0;
                           count_20p[].d   = count_20p[].q  + 0;
                           count_50p[].d   = count_50p[].q  + 1;
                           count_100p[].d  = count_100p[].q + 0;
                    
                     ELSIF (coin_input[3] == 1) THEN
                 count_10p[].d   = count_10p[].q  + 0;
                              count_20p[].d   = count_20p[].q  + 0;
                              count_50p[].d   = count_50p[].q  + 0;
                              count_100p[].d  = count_100p[].q + 1;
                    
                              ELSIF (coin_input[] == B"0000")THEN
                    count_10p[].d   = count_10p[].q  + 0;
                                 count_20p[].d   = count_20p[].q  + 0;
                                 count_50p[].d   = count_50p[].q  + 0;
                                 count_100p[].d  = count_100p[].q + 0;
                                                           
            END IF;        
END;


Codes for 'subs' block:
SUBDESIGN subs
(
sys_reset, change_end  :INPUT ;
coin_change_10p[3..0] , coin_change_20p[3..0] , coin_change_50p[3..0] , coin_change_100p[3..0] : INPUT;
temp_10p[3..0] , temp_20p[3..0] , temp_50p[3..0] , temp_100p[3..0]                             : INPUT;
number_10p[3..0] , number_20p[3..0] , number_50p[3..0] , number_100p[3..0]                     : OUTPUT;
)

VARIABLE
c1 : node;
c2 : node;
c3 : node;
c4 : node;

BEGIN

IF (sys_reset)THEN
Number_10p[] = B"0000";
Number_10p[] = B"0000";
Number_10p[] = B"0000";
Number_10p[] = B"0000";

ELSE

IF(change_end)THEN

(c1,number_10p[])=(gnd,temp_10p[])-(gnd,coin_change_10p[]);

(c1,number_20p[])=(gnd,temp_20p[])-(gnd,coin_change_20p[]);

(c3,number_50p[])=(gnd,temp_50p[])-(gnd,coin_change_50p[]);
                    
(c4,number_100p[])=(gnd,temp_100p[])-(gnd,coin_change_100p[]);

ELSE

number_10p[] = temp_10p[];
number_20p[] = temp_20p[];
number_50p[] = temp_50p[];
number_100p[] = temp_100p[];

END IF;

END IF;
                    
END;


Codes for 'control' block:
SUBDESIGN control
(
clk, reset, cancel                                : INPUT;
product_price_LSB[3..0], product_price_MSB[3..0]  : INPUT;
total_LSB[3..0], total_MSB[3..0]                  : INPUT;
product_out, change_total[3..0]                   : OUTPUT;
cancel_change_LSB[3..0], cancel_change_MSB[3..0]  : OUTPUT;
)

variable
c_LSB, s_LSB[3..0] : NODE;

BEGIN

(c_LSB,s_LSB[])=(gnd,total_LSB[])-(gnd,product_price_LSB[]);

IF (cancel)THEN
cancel_change_LSB[] = total_LSB[];
cancel_change_MSB[] = total_MSB[];
product_out=B"0" ;
ELSE
cancel_change_LSB[] = B"0000";
cancel_change_MSB[] = B"0000";
END IF;

IF (reset)THEN
change_total[] = B"0000";
product_out=B"0";

ELSIF (product_price_MSB[1] == 1  & total_MSB[1] == 0 )THEN
product_out=B"0" ;
change_total[] = B"0000";

ELSIF (product_price_MSB[1] == total_MSB[1])THEN
   
                 IF (product_price_MSB[0] == 1 & total_MSB[0] == 0 )THEN
                 product_out=B"0" ;
                 change_total[] = B"0000";
                 ELSIF (product_price_MSB[0] == total_MSB[0])THEN
                    
                                  IF (product_price_LSB[3] == 1 & total_LSB[3] == 0 )THEN
                                  product_out=B"0" ;
                                  change_total[] = B"0000";
                                  ELSIF (product_price_LSB[3] == total_LSB[3])THEN
                                     
                                                                IF (product_price_LSB[2] == 1 & total_LSB[2] == 0)THEN
                                      product_out=B"0" ;
                                                                change_total[] = B"0000";
                                                                ELSIF (product_price_LSB[2] == total_LSB[2])THEN
                                                                   
                                                                                 IF (product_price_LSB[1] == 1 & total_LSB[1] == 0)THEN
                                                                                 product_out=B"0" ;
                                                                                 change_total[] = B"0000";
                                                                                 ELSIF (product_price_LSB[1] == total_LSB[1])THEN
                                                                                     
                                                                                                  IF (product_price_LSB[0] == 1 & total_LSB[0] == 0)THEN
                                                                                                  product_out=B"0" ;
                                                                                                  change_total[] = B"0000";
                                                                                                  ELSIF (product_price_LSB[0] == total_LSB[0])THEN
                                                                                                  product_out=B"1" ;
                                                                                                  change_total[] = B"0000";
                                                                                                  ELSIF  (product_price_LSB[0] == 0 & total_LSB[0] == 1)THEN
                                                                                                  product_out=B"1" ;
                                                                                                  change_total[] = B"0001";
                                                                                                  END IF;
                                                                                                 
                                                                                 ELSIF (product_price_LSB[1] == 0 & total_LSB[1] == 1)THEN
                                                                                 product_out=B"1" ;
                                                                                 change_total[] = s_LSB[];
                                                                                 END IF;
                                                                                 
                                                                ELSIF (product_price_LSB[2] == 0 & total_LSB[2] == 1)THEN
                                                                product_out=B"1" ;
                                                                change_total[] = s_LSB[];
                                      END IF;                          
                                 
                                  ELSIF (product_price_LSB[3] == 0 & total_LSB[3] == 1)THEN
                                  product_out=B"1" ;
                                  change_total[] = s_LSB[];
                                  END IF;
                                 
    ELSIF (product_price_MSB[0] == 0 & total_MSB[0] == 1)THEN
                 product_out=B"1" ;
                 change_total[] = s_LSB[] + B"1010" ;
                 END IF;
                                 
ELSIF (product_price_MSB[1] == 0 & total_MSB[1] == 1)THEN
product_out=B"1" ;
change_total[] = s_LSB[] + B"1010" ;
END IF;


END;

Codes for 'change' block:
SUBDESIGN change
(
reset, ent, clk, cancel                                                                        : INPUT;
change_LSB[3..0] , change_MSB[3..0]                                                            : INPUT;
number_10p[3..0] , number_20p[3..0] , number_50p[3..0] , number_100p[3..0]                     : INPUT;
change_error, change_end                                                                          : OUTPUT;
coin_change_10p[3..0] , coin_change_20p[3..0] , coin_change_50p[3..0] , coin_change_100p[3..0] : OUTPUT;
)

variable
t1, s1[3..0] : DFF;
t2, s2[3..0] : DFF;
t3, s3[3..0] : DFF;
t4, s4[3..0] : DFF;
value[3..0]  : DFF;
MSB[3..0]    : DFF;
a[3..0], b[3..0], c[3..0], d[3..0] : DFF;
change_10p[3..0] , change_20p[3..0] , change_50p[3..0], change_100p[3..0] :DFF;

BEGIN
a[] = number_10p[];
b[] = number_20p[];
c[] = number_50p[];
d[] = number_100p[];

coin_change_10p[] = change_10p[];
coin_change_20p[] = change_20p[];
coin_change_50p[] = change_50p[];
coin_change_100p[] = change_100p[];

a[].clk = clk;
b[].clk = clk;
c[].clk = clk;
d[].clk = clk;

value[].clk = clk;
MSB[].clk   = clk;
change_10p[].clk = clk;
change_20p[].clk = clk;
change_50p[].clk = clk;
change_100p[].clk = clk;

(t1,s1[])=(gnd,number_10p[])-(gnd,change_10p[]);
(t2,s2[])=(gnd,number_20p[])-(gnd,change_20p[]);
(t3,s3[])=(gnd,number_50p[])-(gnd,change_50p[]);
(t4,s4[])=(gnd,number_100p[])-(gnd,change_100p[]);
a[] = s1[];
b[] = s2[];
c[] = s3[];
d[] = s4[];

IF (cancel # ent)THEN
value[] = change_LSB[];
MSB[] = change_MSB[];
END IF;

IF (!reset)Then
    IF (MSB[].q == 1)THEN
MSB[].d = MSB[].q - 1;
change_100p[].d = change_100p[].q + 1;
    IF (value[].q == 0)THEN
 change_end = B"1";
 END IF;
ELSE
MSB[].d = MSB[].q + 0;
change_100p[].d = change_100p[].q + 0;
END IF;
IF (value[].q > 5)THEN
    IF (c[].q > 0)THEN
 value[].d = value[].q - 5;
 change_50p[].d = change_50p[].q + 1;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 ELSIF (b[].q > 0)THEN
 value[].d = value[].q - 2;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 1;
 change_10p[].d = change_10p[].q + 0;
 ELSIF (a[].q > 0)THEN
 value[].d = value[].q - 1;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 1;
 ELSE
 value[].d = value[].q + 0;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_error = B"1";
 END IF;
ELSIF (value[].q == 5)THEN
    IF (c[].q > 0)THEN
 value[].d = value[].q - 5;
 change_50p[].d = change_50p[].q + 1;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_end = B"1";
 ELSIF (b[].q > 0)THEN
 value[].d = value[].q - 2;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 1;
 change_10p[].d = change_10p[].q + 0;
 ELSIF (a[].q > 0)THEN
 value[].d = value[].q - 1;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 1;
 ELSE
 value[].d = value[].q + 0;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_error = B"1";
 END IF;
    ELSIF (value[].q > 2 & value[].q < 5)THEN
    IF (b[].q > 0)THEN
 value[].d = value[].q - 2;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 1;
 change_10p[].d = change_10p[].q + 0;
 ELSIF (a[].q > 0)THEN
 value[].d = value[].q - 1;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 1;
 ELSE
 value[].d = value[].q + 0;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_error = B"1";
 END IF;
ELSIF (value[].q == 2)THEN
    IF (b[].q > 0)THEN
 value[].d = value[].q - 2;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 1;
 change_10p[].d = change_10p[].q + 0;
 change_end = B"1";
 ELSIF (a[].q > 0)THEN
 value[].d = value[].q - 1;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 1;
 ELSE
 value[].d = value[].q + 0;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_error = B"1";
 END IF;
    ELSIF (value[].q == 1)THEN
    IF (a[].q > 0)THEN
 value[].d = value[].q - 1;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 1;
 change_end = B"1";
 ELSE
 value[].d = value[].q + 0;
 change_50p[].d = change_50p[].q + 0;
 change_20p[].d = change_20p[].q + 0;
 change_10p[].d = change_10p[].q + 0;
 change_error = B"1";
 END IF;
ELSIF (value[].q == 0)THEN
value[].d = value[].q + 0;
change_50p[].d = change_50p[].q + 0;
change_20p[].d = change_20p[].q + 0;
change_10p[].d = change_10p[].q + 0;
END IF;
ELSE
coin_change_10p[] = B"0000";
         coin_change_20p[] = B"0000";
         coin_change_50p[] = B"0000";
coin_change_100p[] = B"0000";
change_error = B"0";
change_end = B"0";
END IF;


END;




9 comments:

  1. hi!i am computer engineering year two student who is currently doing digital mini project about this title too...since i hvnt learn about the quartus coding...so can i reference to ur coding and modify it?

    ReplyDelete
  2. beside that, can you guide me how you make the block diagram for all the 7-segment displays and the pulsar?what is the use of pulsar?are they all use coding too?can you show me the coding?i hv no idea on that coding...@@i will truly appreciate for ur reply...it is urgent for me right now..thanks

    ReplyDelete
    Replies
    1. BY the way, i have forgotten that project details. But i do remember all the functional blocks have their codings for setting up.

      Delete
  3. Hi, i have just found your comments here, i am glad that our project could be a help for your's. For the 7-segment, it was very commonly used, so you can just search them using the software (Quartus II) resources (help/search), the codes were already there for use. For the pulsars, they are also easy to design with the use of (finite) state machines (there should be many ways to do that).
    Hope it's not late for your project.

    SUBDESIGN pulsar
    (
    clk, reset, y : INPUT;
    z : OUTPUT;
    )
    VARIABLE
    ss: MACHINE WITH STATES (s0 ,s1 ,s2);
    BEGIN
    ss.clk = clk;
    ss.reset = reset;
    TABLE
    ss, y => z, ss;
    s0, 0 => 0, s0;
    s0, 1 => 1, s1;
    s1, 0 => 0, s0;
    s1, 1 => 0, s1;
    s2, 0 => 0, s0;
    s2, 1 => 0, s2;

    END TABLE;
    END;

    ReplyDelete
  4. Hi! I'm so surprise that you will reply my message..coz that day I just try my luck to ask after stuck at the final circuit part...Actually I hvnt study about the coding..our mini project is based on the basic knowledge...but I cant find any useful information from the internet until I saw you and your partner's project...so I just try to use that coding that I never learn before...but it seems still so hard for me...so I ask for your help...I'm glad that you reply my message...although now we hv change our path back to the basic...but your project had help us to get the idea...by the way..we still facing problems in constructing the logic circuit for the block...haha..anyway thanks for your reply again....I dont think I'm so lucky before...haha

    ReplyDelete
    Replies
    1. Hi, we usd the 'AHDL' language which was not commonly used today (people used VHDL nowadays). So i guess you went back to VHDL. Actually, we had not even know there was a 'Blogger' in Google until we were asked by the department to use it for reporting our project progress... Whatever, i hope your project will go well.

      Delete
    2. ya..when i search from internet,it rarely saw about AHDL but VHDL is always pip up on screen...by the way..thank you so much...wish you hv ur nice day^^

      Delete
    3. ya..when i search from internet,it rarely saw about AHDL but VHDL is always pip up on screen...by the way..thank you so much...wish you hv ur nice day^^

      Delete
  5. Hi! I'm so surprise that you will reply my message..coz that day I just try my luck to ask after stuck at the final circuit part...Actually I hvnt study about the coding..our mini project is based on the basic knowledge...but I cant find any useful information from the internet until I saw you and your partner's project...so I just try to use that coding that I never learn before...but it seems still so hard for me...so I ask for your help...I'm glad that you reply my message...although now we hv change our path back to the basic...but your project had help us to get the idea...by the way..we still facing problems in constructing the logic circuit for the block...haha..anyway thanks for your reply again....I dont think I'm so lucky before...haha

    ReplyDelete