Day 28
I. Last Time:
Lab #4 Due VERY Soon!!!
A. Lab #4 Discussion!
Questions?
Development Techniques?
Testing individual functions?
Correction on Row/Col inputs!!!
B. Simple ALU: AND, OR, Addu, Subu, not, add, sub.
Checking for overflow:
CO of highest bit (Addu)
/CO of highest bit (Subu)
pos+pos=neg / neg+neg=pos (add)
...
ALU composed of "bit-cells"
slt - subtraction / sign bit
II. New Stuff
A. MIPS & Logic Instructions:
MIPS logic instructions are BITWISE Logic:
and/andi = bitwise and (diagram) = & in C
or/ori = bitwise or = | in C
not = bitwise not = ~ in C
sll = Shifting Left Logical Constant
sllv = Shifting Left Logical Variable
srl = Shifting Right Logical Constant
sra = Shift Right Arithmetic
srlv = Shift Right logical variable
srav = Shift right arithmetic variable
xor/xori
nor
B. Weird Stuff - The RS-Latch!
Latches & Registers: bit memory elements:
1. NOR Gate
A B A NOR B
0 0 1
0 1 0
1 0 0
1 1 0
Note: A 1 input = a 0 output
2. Cross Coupled NOR - How's this beast work?
Timing Diagram
(This is an RS Latch - Good for a burgler alarm
because it "Latches" when set)
3. The Race Condition
C. The Solution to Racing: Clocking
(Build a circuit to prevent race conditions)
The D-Latch (D for Data, Latch for "latching onto" the data)
D. Even More percise timing - the D Flip-Flop
(The Value Flips one Way, then Flops back the other)
The Beauty of the flip flop is that we "capture"
information at very precise time intervals
E. State Machines & How to build them
Combinational vs. State (sequantial) logic
Combinational Logic - "Combines" the inputs in some way to produce
the output.
State Machines - Machines that remember "history" I.e. they are in
some state and the output depends on the current
AND previous input.
Ex: TV - the results of the UP button depends on the current channel.
Inputs: UP button. Current State is the current channel.
Output is the next chanel.
1. The state diagram:
Used to graphically describe a machine.
A bubble is a "state" I.e. some important status
of the machine.
Arcs connect states - they describe what conditions cause
the machine to enter another "state". Arcs are labeled with
the conditions that cause the transition.
A diagram where bubbles represent "states"
Bubbles/states are often given names and if a specific
output is associated with the state it is also indicated.
2. Any graph of this sort can be written as a table with a few parts:
Input section: consists of true "inputs" and the states
Output section: consists of true "outputs" and the NEXT states
3. Once in table form, each "state" can be given a unique
encoding. There are a lot of possible choices:
One-Hot. Each State has a "TRUE" bit.
Ex: if there are 3 states: 001 means state 1
010 means state 2, 100 means state 3.
Binary Encoding: 3 states: 00, 01, and 10
Choice of encoding is more of an art than a science.
Different encodings have very different impacts on the
circuits usually.
4. Give binary values to all other inputs/outputs
5. Now that the table is in "binary" we can write out equations:
1 eq for each bit of the "state vector"
(I.e. each bit of the state encoding)
1 eq for each output
6. From equations, we can produce circuits and real machines.
Example: The traffic light controller
(The EE version of "Hello World")
The Process:
1) Draw Diagram following simple rules:
A Bubble is a state
Outputs may be turned on in a state
(This is part of what makes the state special)
States are connected to other states with "Arcs"
These arcs are the paths taken when certain conditions
are met.
Things to keep in mind:
The clock - this dictates how long the machine will
take in each bubble.
2) Write out a Table with inputs/states and outputs/next states
(ALL possible combinations of inputs/states and the outputs/
next staes that result)
3) Pick a binary encoding for the states and inputs/outputs
4) Fill in the table with the encoding.
5) Write equations for the outputs and each bit of the next state
in terms of the inputs and current state bits
(This describes the "combinational logic" part of the machine)
6) Draw out the combinational logic and attach it to flip-flops.
1 flip-flop per state bit.
DONE!
B. Example:
Simple "toy" with green, yellow, red lights.
reset button (resets to green, ignores up/down switch)
up/down switch -
Up causes lights to go from green->yellow->red
"down" (Up turned off) causes lights to go from red->yellow->green
State Diagram:
State Table:
"Left" side is the inputs to the logic.
"Right" side is the outputs from the logic.
This describes how our machine works (including the internal "memory")
Current State Inputs | Outputs Next State
Up Reset | Green Yellow Red
-----------------------------------------------------------------------
Green State 0 0 | 1 0 0 Green State
Green State 0 1 | 1 0 0 Green State
Green State 1 0 | 1 0 0 Yellow State
Green State 1 1 | 1 0 0 Green State
-----------------------------------------------------------------------
Yellow State 0 0 | 0 1 0 Green State
Yellow State 0 1 | 0 1 0 Green State
Yellow State 1 0 | 0 1 0 Red State
Yellow State 1 1 | 0 1 0 Green State
-----------------------------------------------------------------------
Red State 0 0 | 0 1 0 Yellow State
Red State 0 1 | 0 1 0 Green State
Red State 1 0 | 0 1 0 Red State
Red State 1 1 | 0 1 0 Green State
-----------------------------------------------------------------------
Chose a state encoding:
Current State
CS1 CS0
Green State = 0 0
Yellow State = 0 1
Red State = 1 0
Add State encoding to the table:
Current State = Inputs | Outputs Next State =
CS1 CS0 Up Reset | Green Yellow Red NS1 NS0
-----------------------------------------------------------------------------------
Green State 0 0 0 0 | 1 0 0 Green State 0 0
Green State 0 0 0 1 | 1 0 0 Green State 0 0
Green State 0 0 1 0 | 1 0 0 Yellow State 0 1
Green State 0 0 1 1 | 1 0 0 Green State 0 0
----------------------------------------------------------------------------------
Yellow State 0 1 0 0 | 0 1 0 Green State 0 0
Yellow State 0 1 0 1 | 0 1 0 Green State 0 0
Yellow State 0 1 1 0 | 0 1 0 Red State 1 0
Yellow State 0 1 1 1 | 0 1 0 Green State 0 0
-----------------------------------------------------------------------------------
Red State 1 0 0 0 | 0 1 0 Yellow State 0 1
Red State 1 0 0 1 | 0 1 0 Green State 0 0
Red State 1 0 1 0 | 0 1 0 Red State 1 0
Red State 1 0 1 1 | 0 1 0 Green State 0 0
----------------------------------------------------------------------------------
Generate Equations:
Using Sum of Products and Simplification:
Green = /CS1 * /CS0
Yellow = /CS1 * CS0
Red = CS1 * /CS0
Using Sum of Products:
NS0 = /CS1*/CS0*Up*/Reset + CS1*/CS0*/Up*/Reset
NS1 = /CS1*CS0*Up*/Reset + CS1*/CS0*Up*/Reset
Use the equations to develop a circuit.
(Use flip-flops with NS1/NS0 as inputs to D,
and Q outputs are CS1/CS0)
III. Next Time:
A. Finish State Machines!
B. Memory / Registers