Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a vending machine controller for a vending machine that sells an item for 25 cents. The types of coins the vending machine accepts are

Design a vending machine controller for a vending machine that sells an item for 25 cents. The types of coins the vending machine accepts are nickels, dimes, and quarters. The vending machine does not give change (that is, the customer will lose their money if more than 25 cents is inserted before the item is vended).

You will design and implement a Finite State Machine (FSM) to control your vending machine. The FSM will keep track of the state of the system, that is how much money has been inserted, and once enough money has been inserted it will turn on the motor to vend the item. As coins are inserted your vending machine controller should also keep track of remaining amount due in order to display how much money is due to purchase the item.

Your controller will have six parts:

Your FSM which will be implemented as an array of states. Each state is represented by a struct in C where the fields of the struct are the outputs of the controller (the vend motor control signal and the amount due) and the array of pointers to next states.

A main function which declares a state pointer, initializes the state pointer to a start state, and then continuously loops. In the infinite loop the following actions will take place:

The output will be displayed for the current (present) state (part 4)

The input will be read (part 6)

The controller will transition to the next state based on the input value by updating the

state pointer.

A function to generate the control signals for a 7segment controller based on the digit to be displayed. It should take as input the value of the digit and a period flag. The value of the digit can be 0 to 9. The value of the period flag should be 0 for no period and 1 for a period. The function should return the control signals expressed as hexadecimal numbers.

To the right is a picture of a seven segment display with each segment assigned a letter. You can control the display by writing a 1 to the pin that controls the LED (light emitting diode) for that segment. Assume that the segments can be controlled with a byte (8bit) control signal where segment a is the most significant bit (msb) bit 7, segment b is bit 6, segment c is bit 5, etc. Bit 0 controls the period (P).

So, to display a 0 the function input would be 0 for the digit and 0 for the period flag and it should return the following 8bit value: 11111100 (which is 0xFC in hex). To display a 0. the function input would be a 0 for the digit and a 1 for the period flag and it should return the following 8bit value: 11111101 (which is

1

0xFD). To display a 2 the function input would be 2 for the digit and 0 for the period flag and it should return the following 8bit value: 11011010 (which is 0xDA).

A function to display the output. This function will be called by the main function in part 2 to display the output. It should take as input the vend output value and the amount due output value. In the actual embedded system for the vending machine, the output signals would be connected to the motor to control when to vend (0 = motor off to not vend and 1 = motor on to vend) and the seven segment displays to display the amount due. For testing and debugging purposes, you can emulate the outputs by displaying them to the screen. You should display the following information:

If the vend control signal is a one, display a message that the item is being vended.

The amount due in decimal format. E.g., 0.20 (if 20 cents is due)

The control signals to the 7segment controller. In order to control the three 7segment

displays for the amount due, you should call the function from part 3 three times. Your function should display the returned control signal as a hexadecimal value. E.g. FD DA FC (if 20 cents is due). Part 3 above explains how these values are determined.

A function to encode the three sensor values to a 2bit value. There are three sensors used in your vending machine: nickel, dime, and quarter. The sensor value will be a one if that particular coin has been detected, otherwise the sensor value will be a zero. This function will take as input the three sensor values and return an encoded value:

00 (0) no coin when no sensors inputs are 1 01 (1) nickel when the nickel sensor input is a 1 10 (2) dime when the dime sensor input is a 1 11 (3) quarter when the quarter sensor input is a 1

A function to input the coin value and return the encoded input value for the FSM using the function from part 5. In an embedded system the sensors would detect the coin entered. For testing and debugging, to emulate the coin input, write a function to prompt the user for the value of the coin entered (0, 5, 10, 25). From this value you can generate the appropriate sensor input values to pass to the function in part 5. For example, if the user enters 10, then the function in part 5 should be passed a 0 for the nickel argument, a 1 for the dime argument, and a 0 for the quarter argument. The encoded value returned will be used by the main function to determine the next state.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago