SlideShare a Scribd company logo
1 of 21
Download to read offline
Click to add Title
Efficient Code Writing For FSM in
Verilog
e-Infochips Institute of Training Research and Academics Limited
Prepared By:
Dhrumil Patel
Contents
• What is FSM?
– Different Types of FSM
• Mealy FSM
• Moore FSM
• Different Types of coding FSM
– Binary coding
– One Hot Coding
– Gray Coding
• Comparison Table
• References
05-Feb-15 2
What is FSM?
• A finite-state machine (FSM) or simply a state
machine, is a mathematical model of computation
used to design both computer programs and
sequential logic circuits.
• The machine is in only one state at a time; the state
it is in at any given time is called the current state. It
can change from one state to another when initiated
by a triggering event or condition; this is called a
transition.
• A particular FSM is defined by a list of its states, and
the triggering condition for each transition.
05-Feb-15 3
Types of FSM
• Mealy Machine
– Mealy machine is a finite-state machine whose
output values are determined both by its
current state and the current inputs.
• Moore Machine
– Moore machine is a finite-state machine whose
output values are determined solely by its
current state.
05-Feb-15 4
Types of Coding
• There are several methods of encoding the state
assignments when designing finite state machines (FSM).
The decision on which method to use is a function of
design constraints such as speed, area, power
consumption, and the type of programmable logic device
targeted to.
• This is an important decision to be made by the designer
in order to satisfy the design requirements. There are
some general guidelines one can use depending on
design objectives. A wrong decision may result in a state
machine that uses too much logic, too slow, or both.
05-Feb-15 5
• Most research reports and other materials devoted
to searching of the “optimal” coding of the internal
states are based on the minimal number of states
and sometimes also on the minimal number of flip-
flops used in the hardware implementation
• On above basis there are some different encoding
style.
05-Feb-15 6
Different Coding Style
• Binary coding
• Gray coding
• One hot coding
05-Feb-15 7
Binary Coding
• In a binary encoding scheme, the relationship between
the number of state variables (q) and number of states
(n) is given by the equation q=log 2 (n).
• With this formula, one can easily determine the
minimum number of state variables required for a
binary-encoded state machine. Clearly, the number of
flip-flops used is equal to the number of state variables
(q).
• In this technique, the states are assigned in binary
sequence where the states are numbered starting from
binary 0 and up.
05-Feb-15 8
05-Feb-15 9
Why binary coding?
• Binary encoding uses fewer flip-flops/registers
than one-hot encoding. For example, binary
encoding requires only seven (flip-flops) registers
to implement a 100-state machine while a one-hot
encoding needs 100 flip-flops.
• Binary encoding uses the minimum number of state
variables (flip-flops) to encode a machine since the
flip-flops are maximally utilized.
• It is usually the preferred method when
implementing machines that are fewer than 8
states.
05-Feb-15 10
• The disadvantages of using a binary encoded FSM
include the fact that more than one bit can flip at
any time and can result in a glitch (hazard). It also
requires a more complex decoding logic to
determine the present state.
• If power consumption is an issue, then this
technique may not be suitable since the more
registers/flip-flop changes, the more power the
device consumes
05-Feb-15 11
One Hot Coding
• In the one-hot encoding (OHE) only one bit of the
state variable is “1” or “hot” for any given state.
All other state bits are zero. Therefore, one flip-
flop (register) is used for every state in the machine
i.e. n states uses n flip-flops.
• State decoding is simplified, since the state bits
themselves can be used directly to indicate whether
the machine is in a particular state.
05-Feb-15 12
One Hot Coding
05-Feb-15 13
Why use one hot coding?
• One-hot encoding (OHE) is better suited for flip-
flop-rich architectures of the higher gate count
filed-programmable gate arrays (FPGAs), such as
offered by Xilinx, Actel, and others.
• One-hot state machines are typically faster. Speed
is independent of the number of states, and instead
depends only on the number of transitions into a
particular state.
05-Feb-15 14
• One-hot increases the flip-flop usage (one per state) and
decreases the width of combinatorial logic. It makes it
easy to decode the next state, resulting in large FSMs.
And finally, since one hot code state assignment reduces
the area (area optimization) by using less logic gates, it
consumes less power.
05-Feb-15 15
Gray Coding
• Gray code assignment is a state assignment in
which consecutive states codes only differ by one
bit In other words, only one flip-flop changes at a
time when changing consecutive states.
• In this encoding, the number of flip-flops (register)
used is also determined by:
Number of state variables = number of flip-flops =
log 2 (number of states)
05-Feb-15 16
Gray Coding
05-Feb-15 17
Why Gray Coding?
• Gray code uses the same number of register (flip-flops)
as the binary coding technique and the decoding logic
can also be as complex if not more. Therefore, gray code
assignment is also ideal for PLA and CPLD applications
since they have wide gates and a large amount of
combinatorial logic per register.
• Gray encoding has minimal switching between
consecutive states. After choosing the gray state
(assignment) encoding, then further improvements can be
done in order to reduce the area of the combinatorial
logic involved and thus minimizing power consumption.
05-Feb-15 18
Comparison Table
Binary Coding Gray Coding One-Hot Coding
It have less FF and reg
comparing to gray
coding.
Make register toggle less
with one hot, you can
easily detect if you're in
an illegal state.
One bit can flip at any
time and can result in a
glitch
Overcome problems in
binary coding like
transition to dead
unwanted
Circuit fast
It is usually the preferred
method when
implementing machines
that are fewer than 8
states.
Decoding speed is high It takes one FF for each
state
Disadvantages is more
Hardware.
05-Feb-15 19
References
1. Clifford E. Cummings’ “State Machine Coding Style
for Synthesis” , SNUG 1998
2. Koegst, M., Franke, G., and Feske, K., “State
Assignment for FSM Low Power Design”, FhG
IISErlangen – Department EAS Dresden, EURO-DAC
’96 with EURO-VHDL ’96.
3. http://www.testbench.in/TB_04_STATE_MACHINE_
BASED_TB.html
4. http://www.asicworld.com/tidbits/verilog_fsm.html
05-Feb-15 20
Thank you
05-Feb-15 21

More Related Content

What's hot

What's hot (20)

Logic families
Logic familiesLogic families
Logic families
 
CMOS LOGIC STRUCTURES
CMOS LOGIC STRUCTURESCMOS LOGIC STRUCTURES
CMOS LOGIC STRUCTURES
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
VERILOG HDL :: Blocking & NON- Blocking assignments
VERILOG HDL :: Blocking & NON- Blocking assignments VERILOG HDL :: Blocking & NON- Blocking assignments
VERILOG HDL :: Blocking & NON- Blocking assignments
 
Convolution Codes
Convolution CodesConvolution Codes
Convolution Codes
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Dynamic logic circuits
Dynamic logic circuitsDynamic logic circuits
Dynamic logic circuits
 
M ary psk modulation
M ary psk modulationM ary psk modulation
M ary psk modulation
 
Sta by usha_mehta
Sta by usha_mehtaSta by usha_mehta
Sta by usha_mehta
 
Nyquist criterion for distortion less baseband binary channel
Nyquist criterion for distortion less baseband binary channelNyquist criterion for distortion less baseband binary channel
Nyquist criterion for distortion less baseband binary channel
 
Chapter 5 introduction to VHDL
Chapter 5 introduction to VHDLChapter 5 introduction to VHDL
Chapter 5 introduction to VHDL
 
Field Programmable Gate Array: Building Blocks and Interconnections
Field Programmable Gate Array: Building Blocks and InterconnectionsField Programmable Gate Array: Building Blocks and Interconnections
Field Programmable Gate Array: Building Blocks and Interconnections
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
Placement and algorithm.
Placement and algorithm.Placement and algorithm.
Placement and algorithm.
 
Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)
 
Advanced communication lab manual
Advanced communication lab manual Advanced communication lab manual
Advanced communication lab manual
 
Convolutional codes
Convolutional codesConvolutional codes
Convolutional codes
 
Mosfet Operation and Charecteristics.
Mosfet Operation and Charecteristics.Mosfet Operation and Charecteristics.
Mosfet Operation and Charecteristics.
 
Verilog full adder in dataflow & gate level modelling style.
Verilog full adder in dataflow  & gate level modelling style.Verilog full adder in dataflow  & gate level modelling style.
Verilog full adder in dataflow & gate level modelling style.
 
Pll ppt
Pll pptPll ppt
Pll ppt
 

Viewers also liked

КРЕЧЕТ Беспилотные аэрофотосъёмочные системы
КРЕЧЕТ Беспилотные аэрофотосъёмочные системыКРЕЧЕТ Беспилотные аэрофотосъёмочные системы
КРЕЧЕТ Беспилотные аэрофотосъёмочные системы
kulibin
 
Tips on how to get followers on keek
Tips on how to get followers on keekTips on how to get followers on keek
Tips on how to get followers on keek
rock635
 
Cp knowledge: 31 fbt presentation ankit
Cp knowledge: 31 fbt presentation ankitCp knowledge: 31 fbt presentation ankit
Cp knowledge: 31 fbt presentation ankit
Pavan Kumar Vijay
 
Mapas conceptuales acto creativo n 2
Mapas conceptuales acto creativo n 2Mapas conceptuales acto creativo n 2
Mapas conceptuales acto creativo n 2
IE Simona Duque
 
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
ICZN
 
戏剧文学艺术鉴赏
戏剧文学艺术鉴赏戏剧文学艺术鉴赏
戏剧文学艺术鉴赏
wall1999
 
อาร์ม รูปโมลานิซ่า
อาร์ม  รูปโมลานิซ่าอาร์ม  รูปโมลานิซ่า
อาร์ม รูปโมลานิซ่า
Mos BirDy
 

Viewers also liked (20)

КРЕЧЕТ Беспилотные аэрофотосъёмочные системы
КРЕЧЕТ Беспилотные аэрофотосъёмочные системыКРЕЧЕТ Беспилотные аэрофотосъёмочные системы
КРЕЧЕТ Беспилотные аэрофотосъёмочные системы
 
NICC: 5 inbraken in laatste 5 jaar
NICC: 5 inbraken in laatste 5 jaarNICC: 5 inbraken in laatste 5 jaar
NICC: 5 inbraken in laatste 5 jaar
 
Tips on how to get followers on keek
Tips on how to get followers on keekTips on how to get followers on keek
Tips on how to get followers on keek
 
社會回饋
社會回饋社會回饋
社會回饋
 
Actu Défense du 12 janvier
Actu Défense du 12 janvierActu Défense du 12 janvier
Actu Défense du 12 janvier
 
Certificate_MCP 1
Certificate_MCP 1Certificate_MCP 1
Certificate_MCP 1
 
Learning about Social Security
Learning about Social Security Learning about Social Security
Learning about Social Security
 
Entry form Flying Phantom Series Cannes 2016
Entry form Flying Phantom Series Cannes 2016 Entry form Flying Phantom Series Cannes 2016
Entry form Flying Phantom Series Cannes 2016
 
Coworklisboa 2014
Coworklisboa 2014Coworklisboa 2014
Coworklisboa 2014
 
Cp knowledge: 31 fbt presentation ankit
Cp knowledge: 31 fbt presentation ankitCp knowledge: 31 fbt presentation ankit
Cp knowledge: 31 fbt presentation ankit
 
W:\Jane Smith\Biodiversity Heritage Library News From Europe Ala2010
W:\Jane Smith\Biodiversity Heritage Library News From Europe Ala2010W:\Jane Smith\Biodiversity Heritage Library News From Europe Ala2010
W:\Jane Smith\Biodiversity Heritage Library News From Europe Ala2010
 
Perfil credibilidad persuasion etica- ¿que factores hacen que un cliente teng...
Perfil credibilidad persuasion etica- ¿que factores hacen que un cliente teng...Perfil credibilidad persuasion etica- ¿que factores hacen que un cliente teng...
Perfil credibilidad persuasion etica- ¿que factores hacen que un cliente teng...
 
Natural Europe - BHL Europe Liaison meeting 2011
Natural Europe - BHL Europe Liaison meeting 2011Natural Europe - BHL Europe Liaison meeting 2011
Natural Europe - BHL Europe Liaison meeting 2011
 
Mapas conceptuales acto creativo n 2
Mapas conceptuales acto creativo n 2Mapas conceptuales acto creativo n 2
Mapas conceptuales acto creativo n 2
 
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
Sherborn: Scholz - BHL-Europe: Tools and Services for Legacy Taxonomic Litera...
 
Understanding the Books.Quia Homework 2012
Understanding the Books.Quia Homework 2012Understanding the Books.Quia Homework 2012
Understanding the Books.Quia Homework 2012
 
ARRA-Management-Retail
ARRA-Management-RetailARRA-Management-Retail
ARRA-Management-Retail
 
戏剧文学艺术鉴赏
戏剧文学艺术鉴赏戏剧文学艺术鉴赏
戏剧文学艺术鉴赏
 
อาร์ม รูปโมลานิซ่า
อาร์ม  รูปโมลานิซ่าอาร์ม  รูปโมลานิซ่า
อาร์ม รูปโมลานิซ่า
 
Mobile world Summit - 2014
Mobile world Summit - 2014Mobile world Summit - 2014
Mobile world Summit - 2014
 

Similar to Coding of FSM

COMBINATIONAL PLD-BASED STATE MACHINES
COMBINATIONAL PLD-BASED STATE MACHINESCOMBINATIONAL PLD-BASED STATE MACHINES
COMBINATIONAL PLD-BASED STATE MACHINES
daxesh chauhan
 
TRACK D: A breakthrough in logic design drastically improving performances fr...
TRACK D: A breakthrough in logic design drastically improving performances fr...TRACK D: A breakthrough in logic design drastically improving performances fr...
TRACK D: A breakthrough in logic design drastically improving performances fr...
chiportal
 

Similar to Coding of FSM (20)

COMBINATIONAL PLD-BASED STATE MACHINES
COMBINATIONAL PLD-BASED STATE MACHINESCOMBINATIONAL PLD-BASED STATE MACHINES
COMBINATIONAL PLD-BASED STATE MACHINES
 
Programmable logic array
Programmable logic arrayProgrammable logic array
Programmable logic array
 
Module 2 ARM CORTEX M3 Instruction Set and Programming
Module 2 ARM CORTEX M3 Instruction Set and ProgrammingModule 2 ARM CORTEX M3 Instruction Set and Programming
Module 2 ARM CORTEX M3 Instruction Set and Programming
 
Pitfalls of virtual machine introspection on modern hardware
Pitfalls of virtual machine introspection on modern hardwarePitfalls of virtual machine introspection on modern hardware
Pitfalls of virtual machine introspection on modern hardware
 
AI Infra Day | Composable PyTorch Distributed with PT2 @ Meta
AI Infra Day | Composable PyTorch Distributed with PT2 @ MetaAI Infra Day | Composable PyTorch Distributed with PT2 @ Meta
AI Infra Day | Composable PyTorch Distributed with PT2 @ Meta
 
Programmable logic devices
Programmable logic devicesProgrammable logic devices
Programmable logic devices
 
PDA and Turing Machine (1).ppt
PDA and Turing Machine (1).pptPDA and Turing Machine (1).ppt
PDA and Turing Machine (1).ppt
 
interfacing ports.pptx
interfacing ports.pptxinterfacing ports.pptx
interfacing ports.pptx
 
verilog_fsm.pdf
verilog_fsm.pdfverilog_fsm.pdf
verilog_fsm.pdf
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
TRACK D: A breakthrough in logic design drastically improving performances fr...
TRACK D: A breakthrough in logic design drastically improving performances fr...TRACK D: A breakthrough in logic design drastically improving performances fr...
TRACK D: A breakthrough in logic design drastically improving performances fr...
 
eMMC Embedded Multimedia Card overview
eMMC Embedded Multimedia Card overvieweMMC Embedded Multimedia Card overview
eMMC Embedded Multimedia Card overview
 
B sc e5.2 mp unit 3 interfacing
B sc e5.2 mp unit 3 interfacingB sc e5.2 mp unit 3 interfacing
B sc e5.2 mp unit 3 interfacing
 
CrySys guest-lecture: Virtual machine introspection on modern hardware
CrySys guest-lecture: Virtual machine introspection on modern hardwareCrySys guest-lecture: Virtual machine introspection on modern hardware
CrySys guest-lecture: Virtual machine introspection on modern hardware
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Microprocessor 8086 and Microcontoller
Microprocessor 8086 and MicrocontollerMicroprocessor 8086 and Microcontoller
Microprocessor 8086 and Microcontoller
 
Spark Summit EU talk by Miha Pelko and Til Piffl
Spark Summit EU talk by Miha Pelko and Til PifflSpark Summit EU talk by Miha Pelko and Til Piffl
Spark Summit EU talk by Miha Pelko and Til Piffl
 
VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...
VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...
VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...
 
Low power
Low powerLow power
Low power
 
Effective coding styles
Effective coding stylesEffective coding styles
Effective coding styles
 

Recently uploaded

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 

Coding of FSM

  • 1. Click to add Title Efficient Code Writing For FSM in Verilog e-Infochips Institute of Training Research and Academics Limited Prepared By: Dhrumil Patel
  • 2. Contents • What is FSM? – Different Types of FSM • Mealy FSM • Moore FSM • Different Types of coding FSM – Binary coding – One Hot Coding – Gray Coding • Comparison Table • References 05-Feb-15 2
  • 3. What is FSM? • A finite-state machine (FSM) or simply a state machine, is a mathematical model of computation used to design both computer programs and sequential logic circuits. • The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. • A particular FSM is defined by a list of its states, and the triggering condition for each transition. 05-Feb-15 3
  • 4. Types of FSM • Mealy Machine – Mealy machine is a finite-state machine whose output values are determined both by its current state and the current inputs. • Moore Machine – Moore machine is a finite-state machine whose output values are determined solely by its current state. 05-Feb-15 4
  • 5. Types of Coding • There are several methods of encoding the state assignments when designing finite state machines (FSM). The decision on which method to use is a function of design constraints such as speed, area, power consumption, and the type of programmable logic device targeted to. • This is an important decision to be made by the designer in order to satisfy the design requirements. There are some general guidelines one can use depending on design objectives. A wrong decision may result in a state machine that uses too much logic, too slow, or both. 05-Feb-15 5
  • 6. • Most research reports and other materials devoted to searching of the “optimal” coding of the internal states are based on the minimal number of states and sometimes also on the minimal number of flip- flops used in the hardware implementation • On above basis there are some different encoding style. 05-Feb-15 6
  • 7. Different Coding Style • Binary coding • Gray coding • One hot coding 05-Feb-15 7
  • 8. Binary Coding • In a binary encoding scheme, the relationship between the number of state variables (q) and number of states (n) is given by the equation q=log 2 (n). • With this formula, one can easily determine the minimum number of state variables required for a binary-encoded state machine. Clearly, the number of flip-flops used is equal to the number of state variables (q). • In this technique, the states are assigned in binary sequence where the states are numbered starting from binary 0 and up. 05-Feb-15 8
  • 10. Why binary coding? • Binary encoding uses fewer flip-flops/registers than one-hot encoding. For example, binary encoding requires only seven (flip-flops) registers to implement a 100-state machine while a one-hot encoding needs 100 flip-flops. • Binary encoding uses the minimum number of state variables (flip-flops) to encode a machine since the flip-flops are maximally utilized. • It is usually the preferred method when implementing machines that are fewer than 8 states. 05-Feb-15 10
  • 11. • The disadvantages of using a binary encoded FSM include the fact that more than one bit can flip at any time and can result in a glitch (hazard). It also requires a more complex decoding logic to determine the present state. • If power consumption is an issue, then this technique may not be suitable since the more registers/flip-flop changes, the more power the device consumes 05-Feb-15 11
  • 12. One Hot Coding • In the one-hot encoding (OHE) only one bit of the state variable is “1” or “hot” for any given state. All other state bits are zero. Therefore, one flip- flop (register) is used for every state in the machine i.e. n states uses n flip-flops. • State decoding is simplified, since the state bits themselves can be used directly to indicate whether the machine is in a particular state. 05-Feb-15 12
  • 14. Why use one hot coding? • One-hot encoding (OHE) is better suited for flip- flop-rich architectures of the higher gate count filed-programmable gate arrays (FPGAs), such as offered by Xilinx, Actel, and others. • One-hot state machines are typically faster. Speed is independent of the number of states, and instead depends only on the number of transitions into a particular state. 05-Feb-15 14
  • 15. • One-hot increases the flip-flop usage (one per state) and decreases the width of combinatorial logic. It makes it easy to decode the next state, resulting in large FSMs. And finally, since one hot code state assignment reduces the area (area optimization) by using less logic gates, it consumes less power. 05-Feb-15 15
  • 16. Gray Coding • Gray code assignment is a state assignment in which consecutive states codes only differ by one bit In other words, only one flip-flop changes at a time when changing consecutive states. • In this encoding, the number of flip-flops (register) used is also determined by: Number of state variables = number of flip-flops = log 2 (number of states) 05-Feb-15 16
  • 18. Why Gray Coding? • Gray code uses the same number of register (flip-flops) as the binary coding technique and the decoding logic can also be as complex if not more. Therefore, gray code assignment is also ideal for PLA and CPLD applications since they have wide gates and a large amount of combinatorial logic per register. • Gray encoding has minimal switching between consecutive states. After choosing the gray state (assignment) encoding, then further improvements can be done in order to reduce the area of the combinatorial logic involved and thus minimizing power consumption. 05-Feb-15 18
  • 19. Comparison Table Binary Coding Gray Coding One-Hot Coding It have less FF and reg comparing to gray coding. Make register toggle less with one hot, you can easily detect if you're in an illegal state. One bit can flip at any time and can result in a glitch Overcome problems in binary coding like transition to dead unwanted Circuit fast It is usually the preferred method when implementing machines that are fewer than 8 states. Decoding speed is high It takes one FF for each state Disadvantages is more Hardware. 05-Feb-15 19
  • 20. References 1. Clifford E. Cummings’ “State Machine Coding Style for Synthesis” , SNUG 1998 2. Koegst, M., Franke, G., and Feske, K., “State Assignment for FSM Low Power Design”, FhG IISErlangen – Department EAS Dresden, EURO-DAC ’96 with EURO-VHDL ’96. 3. http://www.testbench.in/TB_04_STATE_MACHINE_ BASED_TB.html 4. http://www.asicworld.com/tidbits/verilog_fsm.html 05-Feb-15 20