In this module, we will learn how to use a Final-State-Machine(FSM) which describes the working of a Soda vending machine:
Assume, We have a soda vending machine which sells soda cans of cost 15¢ each, and we have only 2 types of coins: 10¢ and 5¢.
In this problem, our goal is make a state machine which can determine, how much of change should be returned, and when a can is dispenced.
Note: in this design we will ignore the capacity of the stock, which means, we’ll assume that there will always be can in the vending machine. Also, we can assume that only one action could be made in every “clock cycle” or state
- First give the change.
- Then dispense the can.
Understanding the possibilities
There are quite some options like:
- entering no money
- putting 5¢ followed by another 10¢ => getting the can
- putting 10¢ followed by 10¢ => receiving change => getting a can
- putting 5¢ followed by 5¢ followed by followed by 10¢=> receiving change => getting a can
- putting 10¢ followed by 5¢ and getting the can
- putting 5$ followed by 5¢ followed by 5¢ => getting a can.
Now we translate the options which are listed above into a FSM diagram/flow-chart:
The 'idle' state will be the first state, the machine will be, when its has been 'turned on', and in this the state we also 'Reset' the machine into. Note: The FSM is the Moore machine, because the current state related to the output.
Lets try the soda can vending machine and look for the corresponding state changes FSM diagram in each of the above mentioned possibilities.