Home › Practice › RTL Design › Candy machine
Candy machine
EasyRTLsequentialfsm
A candy costs 15. The machine takes nickels (5) and dimes (10), and gives 5 back if you overpay.
Concept first. The state of this machine is the credit collected so far: 0, 5 or 10 (at 15 the candy comes out, so 15 is never kept). A Mealy machine has outputs that depend on the state and on the input arriving right now: the same state of 10 gives nothing when nothing arrives, and a candy when a nickel arrives. Write the three states and, for each, what a nickel, a dime or nothing does. Which of those cases give a candy, and which also give change?
What to build.
- Inputs
clk,rst,nickel,dime. Outputsvendandchange. rstis synchronous and sets the credit to 0.- If both coins are 1 in the same cycle, only the dime counts.
vendis 1 (in the same cycle, before the clock edge) when the coin arriving now brings the credit to 15 or more.changeis 1 when it brings it to 20.- After a vend the credit goes back to 0. Otherwise the credit grows by the coin.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.