Vending Machine using Verilog



Similar documents
ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

A New Paradigm for Synchronous State Machine Design in Verilog

No serious hazards are involved in this laboratory experiment, but be careful to connect the components with the proper polarity to avoid damage.

IE1204 Digital Design F12: Asynchronous Sequential Circuits (Part 1)

ECE 451 Verilog Exercises. Sept 14, James Barnes

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

Design and Implementation of Vending Machine using Verilog HDL

An Integer Square Root Algorithm

Finite State Machine Design and VHDL Coding Techniques

VENDING MACHINE. ECE261 Project Proposal Presentaion. Members: ZHANG,Yulin CHEN, Zhe ZHANG,Yanni ZHANG,Yayuan

Finite State Machine Design A Vending Machine

Design of Digital Circuits (SS16)

Registers & Counters

Digital Circuit Design Using Xilinx ISE Tools

Finite State Machine. RTL Hardware Design by P. Chu. Chapter 10 1

Computer organization

Digital Design Verification

(Refer Slide Time: 00:01:16 min)

E158 Intro to CMOS VLSI Design. Alarm Clock

Traffic Light Controller. Digital Systems Design. Dr. Ted Shaneyfelt

CSE140: Midterm 1 Solution and Rubric

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Multiplexers Two Types + Verilog

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

A Verilog HDL Test Bench Primer Application Note

Getting the Most Out of Synthesis

FINITE STATE MACHINE: PRINCIPLE AND PRACTICE

Design: a mod-8 Counter

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Modeling Registers and Counters

Testing high-power hydraulic pumps with NI LabVIEW (RT) and the StateChart module. Jeffrey Habets & Roger Custers

Topics of Chapter 5 Sequential Machines. Memory elements. Memory element terminology. Clock terminology

Chapter 7: Advanced Modeling Techniques

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

Understanding Verilog Blocking and Non-blocking Assignments

VHDL Test Bench Tutorial

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

ModelSim-Altera Software Simulation User Guide

ENEE 244 (01**). Spring Homework 5. Due back in class on Friday, April 28.

State Machines in VHDL

Cadence Verilog Tutorial Windows Vista with Cygwin X Emulation

University of Toronto Faculty of Applied Science and Engineering

Exercises for Design of Test Cases

Take-Home Exercise. z y x. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

CNC FOR EDM MACHINE TOOL HARDWARE STRUCTURE. Ioan Lemeni

HOST Embedded System. SLAVE EasyMDB interface. Reference Manual EasyMDB RS232-TTL. 1 Introduction

FREE ENTERPRISE TEST

Audit Pro 2000 Operational Manual For use with C2000 v3.x, v4.x or v5.x

Arbitration and Switching Between Bus Masters

Lab1 : 2-1 MUX. 1. Change to Lab1 directory. It contains the mux.v and mux_text.v files. use this command : cd Lab1

Digital Design with VHDL

Money Unit $$$$$$$$$$$$$$$$$$$$$$$$ First Grade

Informatique Fondamentale IMA S8

The Little Man Computer

Lecture 7: Clocking of VLSI Systems

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

Counters and Decoders

Chapter 2 Verilog HDL for Design and Test

Synthesizable Finite State Machine Design Techniques Using the New SystemVerilog 3.0 Enhancements

Lab 1: Full Adder 0.0

Wiki Lab Book. This week is practice for wiki usage during the project.

The 104 Duke_ACC Machine

Pre-Algebra Lecture 6

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

Module 3: Floyd, Digital Fundamental

Manchester Encoder-Decoder for Xilinx CPLDs

Reading 13 : Finite State Automata and Regular Expressions

EE360: Digital Design I Course Syllabus

(1) /30 (2) /30 (3) /40 TOTAL /100

Getting off the ground when creating an RVM test-bench

Lab 1: Introduction to Xilinx ISE Tutorial

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.


A low-cost, connection aware, load-balancing solution for distributing Gigabit Ethernet traffic between two intrusion detection systems

The Concept of State in System Theory

The Boundary Scan Test (BST) technology

The Fundamentals of Efficient Synthesizable Finite State Machine Design using NC-Verilog and BuildGates. Clifford E. Cummings

Lecture 12: More on Registers, Multiplexers, Decoders, Comparators and Wot- Nots

FPGA Implementation of an Advanced Traffic Light Controller using Verilog HDL

Measuring Resistance Using Digital I/O

ABB Drives. User s Manual. Pulse Encoder Interface Module RTAC-01

x10* CP290 HOME CONTROL INTERFACE PROGRAMMING GUIDE FOR ADVANCED PROGRAMMERS

1 9/25/2009. wsnyder. Verilog-Mode. Still Reducing the Veri-Tedium. /*AUTOAUTHOR*/ Wilson Snyder.

New York University Computer Science Department Courant Institute of Mathematical Sciences

MIDECO 64-outputs MIDI note decoder USER MANUAL. Roman Sowa 2012

Digital Controller for Pedestrian Crossing and Traffic Lights

PCM Encoding and Decoding:

Chapter 5. Sequential Logic

ezee Absolute Release Notes

WA Manager Alarming System Management Software Windows 98, NT, XP, 2000 User Guide

BANK B-I-N-G-O. service charge. credit card. pen. line nickel interest cash bank. ATM dollar check signature. debit card.

Operations and Supply Chain Management Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology Madras

Download and Installation Instructions. Visual C# 2010 Help Library

Using Xilinx ISE for VHDL Based Design

Digital Design with Synthesizable VHDL

SDLC Controller. Documentation. Design File Formats. Verification

Zero-knowledge games. Christmas Lectures 2008

Integration Designer Version 7.5 Version 7 Release 5. Creating a vending machine using the business state machine editor

Transcription:

Vending Machine using Verilog Ajay Sharma 3rd May 05

Contents 1 Introduction 2 2 Finite State Machine 3 2.1 MOORE.............................. 3 2.2 MEALY.............................. 4 2.3 State Diagram........................... 4 3 Verilog Code of the Machine 6 4 TesT Bench 10 5 Output 14 6 Explaination of Output 17 1

Chapter 1 Introduction Vending Machine is a soft drink dispensor machine that dispenses drink based on the amount deposited in the machine. It accepts all the coins ie: Nickel(5 cents), Dime(10 cents), Quarter(25 cents). Till it recieves 40 cents it will not dispense anything. After it has recieved 40 cents it will dispense a softdrink. Any amount above that will be given back as a change. The diagram below is the block diagram of the vending machine.the inputs are the coins and the output is the drink. In the next chapter we will see the how we can encode the state machine in a state diagram and draw it. 2

Chapter 2 Finite State Machine Any Sequential digital circuit can be converted into a state machine using state diagram. In a State machine the circuit s output is defined in a different set of states ie. each output is a state. There is a State Register to hold the state of the machine and a nextstate logic to decode the nextstate. There is also a output register that defines the output of the machine. The nextstate logic is the sequential part of the machine and the Output and Currentstate are the Register part of the logic. There are two types of state machines: 1. MOORE 2. MEALY Lets see each: 2.1 MOORE In a moore machine the output state is totally dependent on the present state. The diagram shows the information. 3

2.2 MEALY In a mealy machine the output depends on the input as well as the present state. 2.3 State Diagram The State Diagram of the Vending Machine is given here. It has the following states: 1. State 1: reset 2. State 2: Five 3. State 3: Ten 4. State 4: Fifteen 5. State 5: Twenty 6. State 6: Twenty Five The next state is the Reset state again. The diagram is given below and is self explanatory. 4

What happens is whenever we get a coin we jump to the next state. So for example we get a coin from the reset state say a NICKEL, then we jump to the next state FIVE. Otherwise we stay in the same state. When we get Extra amount we come back to the reset state and the difference is given back to the user. In the next chapter we will see the Verilog Code for the Vending Machine/State Machine. 5

Chapter 3 Verilog Code of the Machine The code below is the verilog Code of the State Diagram. There are two parts to the code. The first being the Sequential Logic that decides where to go nex or the change in state. The second being the one that decides the Outputs of each state. The Code is as follows: \\*********************** \\***AUTHOR : AJAY SHARMA \\************************ \\please see the website: \\****************************** \\ http://www.csun.edu/~ags55111 \\****************************** \\for the entire source code of the machine \\module name module fsm(clock,reset,coin,vend,state,change); \\these are the inputs and the outputs. input clock; input reset; input [2:0]coin; output vend; output [2:0]state; output [2:0]change; 6

\\i need to define the registers as change,coin and vend reg vend; reg [2:0]change; wire [2:0]coin; \\my coins are declared as parameters to make reading better. parameter [2:0]NICKEL=3 b001; parameter [2:0]DIME=3 b010; parameter [2:0]NICKEL_DIME=3 b011; parameter [2:0]DIME_DIME=3 b100; parameter [2:0]QUARTER=3 b101; \\MY STATES ARE ALSO PARAMETERS. I DONT WANT TO MAKE YOU READ \\IN MACHINE LANGUAGE parameter [2:0]IDLE=3 b000; parameter [2:0]FIVE=3 b001; parameter [2:0]TEN=3 b010; parameter [2:0]FIFTEEN=3 b011; parameter [2:0]TWENTY=3 b100; parameter [2:0]TWENTYFIVE=3 b101; \\AS ALWAYS THE STATES ARE DEFINED AS REG reg [2:0]state,next_state; \\MY MACHINE WORKS ON STATE AND COIN always @(state or coin) begin next_state=0; \\VERYFIRST NEXT STATE IS GIVEN ZERO case(state) IDLE: case(coin) \\THIS IS THE IDLE STATE NICKEL: next_state=five; DIME: next_state=ten; QUARTER: next_state=twentyfive; default: next_state=idle; endcase FIVE: case(coin) \\THIS IS THE SECOND STATE 7

NICKEL: next_state=ten; DIME: next_state=fifteen; QUARTER: next_state=twentyfive; //change=nickel default: next_state=five; endcase TEN: case(coin) \\THIS IS THE THIRD STATE NICKEL: next_state=fifteen; DIME: next_state=twenty; QUARTER: next_state=twentyfive; //change=dime default: next_state=ten; endcase FIFTEEN: case(coin) \\THIS IS THE FOURTH STATE NICKEL: next_state=twenty; DIME: next_state=twentyfive; QUARTER: next_state=twentyfive; //change==nickel_dime default: next_state=fifteen; endcase TWENTY: case(coin) \\THIS IS THE FIFTH STATE NICKEL: next_state=twentyfive; DIME: next_state=twentyfive; //change=nickel QUARTER: next_state=twentyfive; //change==dime_dime default: next_state=twenty; endcase TWENTYFIVE: next_state=idle; \\THE NEXT STATE HERE IS THE RESET default : next_state=idle; endcase end always @(clock) begin \\WHENEVER I GIVE A RESET I HAVE TO MAKE THE STATE TO IDLE AND VEND TO 1 if(reset) begin state <= IDLE; vend <= 1 b0; // change <= 3 b000; end \\THE CHANGE ALSO HAS TO BECOME NONE else state <= next_state; 8

case (state) \\HERE WE DECIDE THE NEXT STATE \\ALL THE STATES ARE DEFINED HERE AND THE OUTPUT IS ALSO GIVEN IDLE: begin vend <= 1 b0; change <=3 d0; end FIVE: begin vend <= 1 b0; if (coin==quarter) change <=NICKEL; else change <=3 d TEN: begin vend <= 1 b0; if (coin==quarter) change <=DIME; else change <= 3 d FIFTEEN : begin vend <= 1 b0; if (coin==quarter) change <=NICKEL_DIME; else cha TWENTY : begin vend <= 1 b0; if (coin==dime) change <=NICKEL; else if (coin==qu TWENTYFIVE : begin vend <= 1 b1; change <=3 d0; end default: state <= IDLE; endcase end endmodule In the next chapter we see the Test Bench of the machine. 9

Chapter 4 TesT Bench We try to test the machine for the outputs. We add coins to the machine and see after which state does it give output or Softdrink. The testbench code is given below. \\AUTHOR: AJAY SHARMA \\PLEASE VISIT: HTTP://WWW.CSUN.EDU/~AGS55111 \\FOR THE ENTIRE SOURCE CODE OF THE MACHINE. \\OK \\SO I HAVE TO INCLUDE THE STATEMACHINE VERILOG CODE \\IN THIS FILE SO THAT THE I CAN RUN IT AND TEST IT HERE. include "fsm2.v" \\THIS IS THE HIGHEST LEVEL OF THE MODULE: THE TEST BENCH. module test; \\THE INPUT IN THE FSM MODULE ARE REG HERE reg clock,reset; reg [2:0]coin; \\THE OUTPUT IN THE FSM MODULE ARE WIRES HERE wire vend; wire [2:0]state; wire [2:0]change; 10

\\THE PARAMETERS AGAIN FOR THE COIN AND STATE parameter [2:0]IDLE=3 b000; parameter [2:0]FIVE=3 b001; parameter [2:0]TEN=3 b010; parameter [2:0]FIFTEEN=3 b011; parameter [2:0]TWENTY=3 b100; parameter [2:0]TWENTYFIVE=3 b101; parameter [2:0]NICKEL=3 b001; parameter [2:0]DIME=3 b010; parameter [2:0]NICKEL_DIME=3 b011; parameter [2:0]DIME_DIME=3 b100; parameter [2:0]QUARTER=3 b101; \\I MONITOR THE TIME,DRINK,RESET,CLOCK,STATE AND CHANGE FOR CHANGES. initial begin $display("time\tcoin\tdrink\treset\tclock\tstate\tchange"); $monitor("%g\t%b\t%b\t%b\t%b\t%d\t%d",$time,coin,vend,reset,clock,state,change); \\NEW FEATURE: MY MACHINE HAS THE FACILITY TO DUMP VARIABLES SO THAT \\ I CAN VIEW THEM USING A VCD VIEWER. $dumpvars; $dumpfile("file.vcd"); // Dump output file. \\THIS IS WHERE THE COINS ARE ADDED. clock=0; reset=1; \\FIRST LETS RESET THE MACHINE coin=nickel; \\CHECK FOR STATE 1 #2 reset=1; coin=2 b00; coin=dime; \\RESET AGAIN AND CHECK FOR STATE 2 #2 reset=1; coin=2 b00; \\RESET AGAIN AND CHECK FOR STATE 5 11

coin=quarter; #2 reset=1; coin=2 b00; \\RESET AGAIN AND CHECK FOR STATE 5 coin=nickel; #2 reset=1; coin=2 b00; \\RESET AGAIN AND CHECK FOR STATE 5 AND SO ON coin=nickel; #2 coin=dime; #2 coin=dime; #2 reset=1; coin=2 b00; coin=nickel; #2 coin=dime; #2 coin=quarter; #2 reset=1; coin=2 b00; coin=nickel; #2 coin=dime; #2 reset=1; coin=2 b00; coin=nickel; #2 coin=dime; #2 reset=1; coin=2 b00; coin=nickel; #2 coin=quarter; 12

#2 reset=1; coin=2 b00; coin=nickel; #2 coin=quarter; #2 reset=1; coin=2 b00; #2 $finish; end \\THE CLOCK NEEDS TO TICK EVERY 2 TIME UNIT always #1 clock=~clock; //always @(state) // coin=!coin; initial begin if (reset) coin=2 b00; end \\THIS IS WHERE I INSTANTIATE THE MACHINE fsm inst1(clock,reset,coin,vend,state,change); endmodule 13

Chapter 5 Output This chapter describes the output of the machine GPLCVER_2.10c of 02/28/05 (Linux-elf). Copyright (c) 1991-2005 Pragmatic C Software Corp. All Rights reserved. Licensed under the GNU General Public License (GPL). See the COPYING file for details. NO WARRANTY provided. Today is Wed May 11 03:36:14 2005. Compiling source file "fsmtest2.v" Highest level modules: test Time coin drink reset clock state change 0 000 0 1 0 0 x 1 000 0 1 1 0 0 2 001 0 0 0 0 0 3 001 0 0 1 1 0 4 000 0 1 0 0 0 5 000 0 1 1 0 0 6 010 0 0 0 0 0 7 010 0 0 1 2 0 8 000 0 1 0 0 0 9 000 0 1 1 0 0 10 101 0 0 0 0 0 11 101 0 0 1 5 0 14

12 000 1 1 0 0 0 13 000 0 1 1 0 0 14 001 0 0 0 0 0 15 001 0 0 1 1 0 16 001 0 0 0 2 0 17 001 0 0 1 3 0 18 001 0 0 0 4 0 19 001 0 0 1 5 0 20 001 1 0 0 0 0 21 001 0 0 1 1 0 22 001 0 0 0 2 0 23 001 0 0 1 3 0 24 000 0 1 0 0 0 25 000 0 1 1 0 0 26 001 0 0 0 0 0 27 001 0 0 1 1 0 28 010 0 0 0 2 0 29 010 0 0 1 4 0 30 010 0 0 0 5 1 31 010 1 0 1 0 0 32 000 0 1 0 0 0 33 000 0 1 1 0 0 34 001 0 0 0 0 0 35 001 0 0 1 1 0 36 010 0 0 0 2 0 37 010 0 0 1 4 0 38 101 0 0 0 5 4 39 101 1 0 1 0 0 40 000 0 1 0 0 0 41 000 0 1 1 0 0 42 001 0 0 0 0 0 43 001 0 0 1 1 0 44 001 0 0 0 2 0 45 001 0 0 1 3 0 46 001 0 0 0 4 0 47 001 0 0 1 5 0 48 010 1 0 0 0 0 49 010 0 0 1 2 0 15

50 000 0 1 0 0 0 51 000 0 1 1 0 0 52 001 0 0 0 0 0 53 001 0 0 1 1 0 54 001 0 0 0 2 0 55 001 0 0 1 3 0 56 001 0 0 0 4 0 57 001 0 0 1 5 0 58 001 1 0 0 0 0 59 001 0 0 1 1 0 60 010 0 0 0 2 0 61 010 0 0 1 4 0 62 000 0 1 0 0 0 63 000 0 1 1 0 0 64 001 0 0 0 0 0 65 001 0 0 1 1 0 66 001 0 0 0 2 0 67 001 0 0 1 3 0 68 101 0 0 0 4 3 69 101 0 0 1 5 4 70 000 1 1 0 0 0 71 000 0 1 1 0 0 72 001 0 0 0 0 0 73 001 0 0 1 1 0 74 101 0 0 0 2 1 75 101 0 0 1 5 2 76 000 1 1 0 0 0 77 000 0 1 1 0 0 Halted at location **fsmtest2.v(82) time 78 from call to $finish. There were 0 error(s), 0 warning(s), and 15 inform(s). 16

Chapter 6 Explaination of Output The Output is explained here. We start by adding coins. We start first with the least amount NICKEL. Then we reset the machine to see the output ie: state and the SOFTDRINK. Then we add a DIME and see the result. So on till till QUARTER is also added. Then i add a dime 5 times to see the output and it vends. ie. a softdrink is given. When i add an extra amount it gives a change also. so my machine works. The next page has the state diagram of the machine. 17