You are on page 1of 22

One-Hot Encoded

Finite State Machines

ECEn 224 17 ONEHOT © 2003-2008


Page 1 BYU
Example State Machine
InA InB CS NS Z
InA’
0 - A A 0
1 - A B 0
0 - B A 1
A InA’ 1 - B C 1
InA - 0 C C 1
- 1 C D 1
- - D A 0
D Z
B
InA InB CS NS Z
InA 0 - 00 00 0
InB
1 - 00 01 0
C Z State A = 00 0 - 01 00 1
State B = 01 1 - 01 10 1
State C = 10 - 0 10 10 1
InB’ State D = 11 - 1 10 11 1
- - 11 00 0

ECEn 224 17 ONEHOT © 2003-2008


Page 2 BYU
Example Machine Implementation
Q1
Q0’ N1 Q1 N1 = Q1•Q0’ + Q1’•Q0•InA
D Q N0 = Q1•Q0’•InB + Q1’•Q0’•InA
Q1’
Q0 Z = Q1’•Q0 + Q1•Q0’
InA

CLK
Q1
Q0’
InB N0 Q0
D Q
Q1’ Logic Used:
Q0’
InA • 9 gates
• 21 gate inputs
CLK • 2 flip flops
Q1’
Q0
Z
Q1
Q0’

ECEn 224 17 ONEHOT © 2003-2008


Page 3 BYU
Choose a Different Encoding

• A=1000, B=0100, C=0010, D=0001


InA InB CS NS Z InA InB CS NS Z
0 - 1000 1000 0 0 - 1--- 1000 0
1 - 1000 0100 0 1 - 1--- 0100 0
0 - 0100 1000 1 0 - -1-- 1000 1
1 - 0100 0010 1 1 - -1-- 0010 1
- 0 0010 0010 1 - 0 --1- 0010 1
- 1 0010 0001 1 - 1 --1- 0001 1
- - 0001 1000 0 - - ---1 1000 0

This is called a one-hot encoding. Because of the state encodings,


there are many illegal states.
Only one state bit is on at a time
This TT with all these input
don’t cares is the result
ECEn 224 17 ONEHOT © 2003-2008
Page 4 BYU
One-Hot Encoding Results

• Will require 4 flip flops


– One per state
– Call the current state bits A, B, C, and D
– Call the next state bits NA, NB, NC, and ND
InA’

By inspection we see: A InA’


InA
NA = A•InA’ + B•InA’ + D
NB = A•InA D Z
B
NC = B•InA + C•InB’
ND = C•InB InA
InB
Z=B+C C Z

InB’
ECEn 224 17 ONEHOT © 2003-2008
Page 5 BYU
One-Hot Implementation
A
InA’ B
B NA InA NC
D Q A D Q C
InA’ C

D InB’

CLK CLK
NB ND
A C
D Q B D Q D
InA InB

CLK B CLK
Logic Used: Z
C
• 9 gates
• 19 gate inputs
• 4 flip flops

ECEn 224 17 ONEHOT © 2003-2008


Page 6 BYU
One-Hot Observations

• Choosing a one-hot encoding results in many,


many don’t cares in transition table

• Minimization results in simpler IFL and OFL

• Requires more flip flops

• Can do one-hot design by inspection


– Without using transition tables…

ECEn 224 17 ONEHOT © 2003-2008


Page 7 BYU
Another One-Hot Example

x’

A
x State Encoding
y’z
A 100
B y’z’
B 010
C 001
y

ECEn 224 17 ONEHOT © 2003-2008


Page 8 BYU
State Encoding and Structure

NA D Q A
With one-hot encoding, each
state has its own flip flop.
State Encoding
A 100 ‘A’ is the name of a state
NB D Q B and it is the name of the
B 010
wire coming out of the flip
C 001
flop for state ‘A’.

NC D Q C The same holds true for


states ‘B’ and ‘C’

ECEn 224 17 ONEHOT © 2003-2008


Page 9 BYU
One-Hot Encodings By Inspection

x’ When is A the next state?

Look at the arcs entering state A


A
x
y’z

B y’z’
NA = A•x’ + B•y’z + C

ECEn 224 17 ONEHOT © 2003-2008


Page 10 BYU
One-Hot Encodings By Inspection

x’ When is A the next state?

Look at the arcs entering state A


A
x
y’z

B y’z’
NA = A•x’ + B•y’z + C

ECEn 224 17 ONEHOT © 2003-2008


Page 11 BYU
One-Hot Encodings By Inspection

x’ When is A the next state?

Look at the arcs entering state A


A
x
y’z

B y’z’
NA = A•x’ + B•y’z + C

ECEn 224 17 ONEHOT © 2003-2008


Page 12 BYU
One-Hot Encodings By Inspection

x’ When is A the next state?

Look at the arcs entering state A


A
x
y’z

B y’z’
NA = A•x’ + B•y’z + C

y
Similar reasoning leads to:
C NB = A•x + B•y’z’
NC = B•y

ECEn 224 17 ONEHOT © 2003-2008


Page 13 BYU
The Key Lock Problem – One-Hot Version

There will be 6 flip flops

One for each state

ECEn 224 17 ONEHOT © 2003-2008


Page 14 BYU
Key Lock Input Forming Logic

NA = (PUSHED’•A) + (ECNT3’•E)
+ (WAITDONE•F)
+ (LOCKED•D)
NB = (PUSHED’•B)+(PUSHED•7•A)
NC = (PUSHED’•C)+(PUSHED•8•B)
ND = (LOCKED’•D)+(PUSHED•9•C)
NE = (PUSHED•7’•A)
+ (PUSHED•8’•B)
+ (PUSHED•9’•C)
NF = (ECNT3•E)
+ (WAITDONE’•F)

ECEn 224 17 ONEHOT © 2003-2008


Page 15 BYU
Key Lock Output Forming Logic

ERROR =

ECEn 224 17 ONEHOT © 2003-2008


Page 16 BYU
Key Lock Output Forming Logic

ERROR = E
INC =

ECEn 224 17 ONEHOT © 2003-2008


Page 17 BYU
Key Lock Output Forming Logic

ERROR = E
INC = (PUSHED•7’•A)
+ (PUSHED•8’•B)
+ (PUSHED•9’•C)
CLRTIMER =

ECEn 224 17 ONEHOT © 2003-2008


Page 18 BYU
Key Lock Output Forming Logic

ERROR = E
INC = (PUSHED•7’•A)
+ (PUSHED•8’•B)
+ (PUSHED•9’•C)
CLRTIMER = ECNT3•E
CLRCNTR =

ECEn 224 17 ONEHOT © 2003-2008


Page 19 BYU
Key Lock Output Forming Logic

ERROR = E
INC = (PUSHED•7’•A)
+ (PUSHED•8’•B)
+ (PUSHED•9’•C)
CLRTIMER = ECNT3•E
CLRCNTR = (WAITDONE•F)
+ (LOCKED•D)
UNLOCK =

ECEn 224 17 ONEHOT © 2003-2008


Page 20 BYU
Key Lock Output Forming Logic

ERROR = E
INC = (PUSHED•7’•A)
+ (PUSHED•8’•B)
+ (PUSHED•9’•C)
CLRTIMER = ECNT3•E
CLRCNTR = (WAITDONE•F)
+ (LOCKED•D)
UNLOCK = (PUSHED•9•C)

ECEn 224 17 ONEHOT © 2003-2008


Page 21 BYU
Other State Encoding Techniques

• You have learned the 2 extremes


– Fully encoded (8 states  3 state bits)
– One-hot encoded (8 states  8 state bits)
• A range of options exist in between

• A good choice of encoding


– Can minimize IFL and OFL complexity
– Algorithms have been developed for this…
– Beyond the scope of this class
ECEn 224 17 ONEHOT © 2003-2008
Page 22 BYU

You might also like