Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A state machine is required for a simple vending machine. The machine takes one

ID: 3851074 • Letter: A

Question

A state machine is required for a simple vending machine. The machine takes one dollar coins only. Each time a coin is added the input signal "coin" is set to 1 for one clock cycle. When a total of exist4 has been added the output signal "deliver" is set to 1 for one clock cycle and the state machine starts counting coins for the next delivery. a) Draw a state diagram for this state machine. Make sure you label each state with a state name and the value of the "deliver" output. Also make sure you label each transition with the value of the "coin" input. Please use "VM0", "VM1", "VM2"... for the state names. b) For an ASIC implementation of the vending machine, a binary state encoding is the best choice. i) Perform a binary state assignment. Please use "s0", "s1", ... for the binary state bit names. ii) Using this state assignment, draw a state table showing next state as a function of current state and the "coin" input. Use "next_s0", "next_s1", ... for the binary next state bit names. Using the state table, derive (unoptimised) equations for the next state bits. iii) Using this state assignment, draw an output table showing the outputs as a function of current state and the "coin" input. Using the output table, derive an (unoptimised) equation tor the "deliver" output. c) For an FPGA implementation of the vending machine, a one-hot (or modified one-hot) state encoding is the best choice. i) Perform a one-hot (or modified one-hot) state assignment. Please use "vm0", "vm1", ... for the state signal names. ii) Using this state assignment, draw a state table showing next state as a function of current state and the "coin" input. Use "next_vm0", "next_vm1", ... for the next state signal names. Using the state table, derive next (unoptimised) equations for the next state signals. Using this state assignment, draw an output table showing the outputs as a function of current state and the "coin" input. Using the output table, derive an (unoptimised) equation for the "deliver" output.

Explanation / Answer

public class VendingMachineAssignement {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

double item1 = 4;
double item2 = 5;
double item3 =5;
double item4 = 4;
double item5 = 1;
double item6 = 5;

System.out.print("Enter an item number: ");
int item = keyboard.nextInt();

System.out.print("Enter the amount paid: ");
double paid = keyboard.nextDouble();

if (item == 2 || item == 4 || item == 6)
{
if (paid >= item2)
{
System.out.println("Thank you for buying item " + item + ", your change is " + (paid-item2) + ". Please come again!");
}
if (paid < item2)
{
System.out.println("Please insert another " + "" + (item2-paid));
}
}

else if (item == 1)
{
if (paid >= item1)
{
System.out.println("Thank you for buying item " + item + ", your change is " + (paid-item1) + ". Please come again!");
}
if (paid < item1)
{
System.out.println("Please insert another " + "" + (item1-paid));
}
}
else if (item == 3)
{
if (paid >= item3)
{
System.out.println("Thank you for buying item " + item + ", your change is " + (paid-item3) + " ");
}
if (paid < item3)
{
System.out.println("Please insert another " + "" + (item3-paid));
}
}
else if (item == 5)
{
if (paid >= item5)
{
System.out.println("Thank you for buying item " + item + ", your change is " + (paid-item5) + " ");
}
if (paid < item5)
{
System.out.println("Please insert another " + + (item5-paid));
}
}


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote