From 6faa702d45de56ee6b17520b71af4f0946c23e60 Mon Sep 17 00:00:00 2001 From: lshprung Date: Fri, 13 Nov 2020 09:04:07 -0800 Subject: Post-class 11/13 --- 20.md | 3 +++ 21.1.png | Bin 0 -> 8029 bytes 21.2.png | Bin 0 -> 13259 bytes 21.3.png | Bin 0 -> 18432 bytes 21.4.png | Bin 0 -> 32145 bytes 21.5.png | Bin 0 -> 17100 bytes 21.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 88 insertions(+) create mode 100644 21.1.png create mode 100644 21.2.png create mode 100644 21.3.png create mode 100644 21.4.png create mode 100644 21.5.png create mode 100644 21.md diff --git a/20.md b/20.md index a3af7a4..0d30c32 100644 --- a/20.md +++ b/20.md @@ -156,3 +156,6 @@ reg [2:0] y, Y; parameter [2:0] A=3'b001, B=3'b010, C=3'b100; ``` +--- + +[Multiple control inputs ->](21.md) diff --git a/21.1.png b/21.1.png new file mode 100644 index 0000000..eca6441 Binary files /dev/null and b/21.1.png differ diff --git a/21.2.png b/21.2.png new file mode 100644 index 0000000..3025cee Binary files /dev/null and b/21.2.png differ diff --git a/21.3.png b/21.3.png new file mode 100644 index 0000000..13aa2b8 Binary files /dev/null and b/21.3.png differ diff --git a/21.4.png b/21.4.png new file mode 100644 index 0000000..ebc0050 Binary files /dev/null and b/21.4.png differ diff --git a/21.5.png b/21.5.png new file mode 100644 index 0000000..dd19944 Binary files /dev/null and b/21.5.png differ diff --git a/21.md b/21.md new file mode 100644 index 0000000..7449cbe --- /dev/null +++ b/21.md @@ -0,0 +1,85 @@ +[\<- 1-hot encoding and State machines in Verilog](20.md) + +--- + +# Multiple control inputs + +## Defining and starting the vending machine example + +### Adding control inputs + +- So far, we've seen just one control input +- Next example is a vending machine + - Items cost 15 cents and the machine accepts both nickles (N) and dimes (D) + - Need to track (via states) how much money has been put in, and whether there is change +- Every state needs to account for all feasible input combinations + - Doesn't necessarily mean a full enumeration of all possible input encodings, but solution space should be complete + +### An arc for every input combo + +- Start with state A, representing no money +- Stay in A as long as no money inserted +- N goes to a state (B) representing 5 cents +- D goes to a state (C), for 10 cents +- Note that N\*D can't happen, not in diagram + - N really means N\*!D, D really means D\*!N + +![diagram](21.1.png) + +--- + +## Thinking thru the rest of the vending machine state diagram + +### Now evaluate state B + +- Adding possibilities from B results in adding state D, which enables output +- Note that state C represents 10 cents, whether we got there from a dime or two nickels + +![diagram](21.2.png) + +### Evaluating state C + +- A dime inserted in state C introduces an interesting question: what to do? + - Decision here: give them 5 cents credit + - Needs a new state (E) to keep track of this + +![diagram](21.3.png) + +### Finishing Up + +- Once a selection is enabled (i.e., the output is asserted), we can unconditionally transition to the next state + - State A from state D + - State B from state E, to give 5 cents credit + +--- + +## State table and next state equations for 1-hot encoding + +### Alternate notation + +- Different state names, but same function +- Different view of the uncoditional transfers + +![diagram](21.4.png) + +### The state table + +- Without assignments, for now + - As a reminder: S1=0 cents, S2=10 cents, S3=5 cents, S4=15 cents, S5=20 cents +- Fully encoded states would need 3 flops + - 5 states -> need 3 bits to get 5 unique states +- 1-hot encoding would need 5 flops + +![diagram](21.5.png) + +### Next state equations + +- State table starts to get hard to manage +- Next state is the sum of the arcs leading to the state +- With 1-hot encoding, not too bad: + - `D1 = Q1*!D*!N + Q4` + - `D2 = Q1*D + Q2*!D*!N + Q3*N` + - `D3 = Q1*N + Q3*!D*!N + Q5` + - `D4 = Q2*N + Q3*D` + - `D5 = Q2*D` +- Getting more complex than this is where Verilog really helps -- cgit