mirror of
https://github.com/chipsalliance/chisel.git
synced 2026-05-31 01:00:52 +08:00
Page:
A Detailed Example
Pages
A Detailed Example
Acknowledgements
Annotations Extending Chisel and Firrtl
BlackBoxes
Builtin Operators
Bundles and Vecs
CS250 Chisel Scala Primer
Chisel Developer Stuff
Chisel Governance
Chisel Introduction
Chisel Memories
Chisel Tutorial
Chisel3 vs Chisel2
ChiselSheet
Combinational Circuits
Cookbook
Datatypes in Chisel
Debugging with the Interpreter REPL 1
Debugging with the Interpreter REPL 2
Debugging with the Interpreter REPL 3
Developers
Experimental Interval Type
Experimental Features
FixedPoint
Frequently Asked Questions
Functional Abstraction
Functional Module Creation
Hardware Expressible in Chisel
Home
Installation Preparation
Interfaces Bulk Connections
Memories
Modules
Multiple Clock Domains
Muxes and Input Selection
Polymorphism and Parameterization
Ports
Printing in Chisel
Randomization flags
Running Stuff
Scala Cheatsheet
Scala Things You Should Know
Scala land vs. Chisel land
Short Users Guide to Chisel
State Elements
Style Guide
Test Coverage
Troubleshooting
Tutorial Problems
Unconnected Wires
Useful SBT Commands
Width Inference
chisel toolchain
how to publish
intellij setup
release notes 17 03 23
release notes 17 04 12
release notes 17 05 03
release notes 17 05 16
release notes 17 05 25
release notes 17 05 30
release notes 17 06 22
release notes 17 07 19
release notes 17 08 16
release notes 17 09 14
release notes 17 09 27
release notes 17 10 06
release notes 17 10 27
release notes 17 11 09
sbt subproject
tips and tricks
Clone
5
A Detailed Example
Chick Markley edited this page 2017-05-30 09:03:45 -07:00
Table of Contents
In this example, we will walk through the process of designing a hardware generator in Chisel. It is intended for users who have completed A Short Users Guide to Chisel. Using a vending machine as a motivating example, we will start with a finite state machine implemented in Verilog and end with a fully parametrizable Chisel generator.
Vending Machine State Machine
Our sample design is a simple vending machine:
- Sodas cost 20¢
- Nickels (5¢) and dimes (10¢) only
- No change given
Verilog Implementation
// A simple Verilog FSM vending machine implementation
module VerilogVendingMachine(
input clock,
input reset,
input nickel,
input dime,
output dispense
);
parameter sIdle = 3'd0, s5 = 3'd1, s10 = 3'd2, s15 = 3'd3, sOk = 3'd4;
reg [2:0] state;
wire [2:0] next_state;
assign dispense = (state == sOk) ? 1'd1 : 1'd0;
always @(*) begin
case (state)
sIdle: if (nickel) next_state <= s5;
else if (dime) next_state <= s10;
else next_state <= state;
s5: if (nickel) next_state <= s10;
else if (dime) next_state <= s15;
else next_state <= state;
s10: if (nickel) next_state <= s15;
else if (dime) next_state <= sOk;
else next_state <= state;
s15: if (nickel) next_state <= sOk;
else if (dime) next_state <= sOk;
else next_state <= state;
sOk: next_state <= sIdle;
endcase
end
// Go to next state
always @(posedge clock) begin
if (reset) begin
state <= sIdle;
end else begin
state <= next_state;
end
end
endmodule
WIP - Bug @jackkoenig to finish