15.01.2013 Views

U. Glaeser

U. Glaeser

U. Glaeser

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIGURE 12.6<br />

An example of a simple state machine is shown in Fig. 12.6. The state diagram shows that the state<br />

machine has three states with two inputs and one output that is active only in state B. The state machine<br />

resets to state A. Most FPGAs offer some advantages for Moore type state machines (i.e., output a function<br />

of state only) with one-hot encoding (i.e., one flip-flop per state) since they contain a register-rich<br />

architecture with limited gating logic. One-hot state machines are also less prone to timing problems<br />

and are the default encoding used in many FPGA synthesis tools. Since there are undefined states, a reset<br />

should always be provided to force the state machine into a known state. Most FPGAs automatically clear<br />

all flip-flops at power up. The first step in each model is to declare inputs and outputs. An internal signal,<br />

state, is then declared and used to hold the current state. Note that the actual encoding of the three states<br />

is not specified in VHDL, but it must be specified in the Verilog model. The first VHDL PROCESS and<br />

Verilog ALWAYS block are sensitive to the rising clock edge; so positive edge-triggered flip-flops are<br />

synthesized to hold the state signal. Inside the first PROCESS or ALWAYS block, if a synchronous reset<br />

occurs the state is set to state A. If there is no reset, a CASE statement is used to assign the next value of<br />

state based on the current value of state and the inputs. The new assignments to state will not take effect<br />

© 2002 by CRC Press LLC<br />

VHDL Model of State Machine Verilog Model of State Machine<br />

entity state_mach is<br />

port(clk, reset : in std_logic;<br />

input1, input2 : in std_logic;<br />

Output1 : out std_logic);<br />

end state_mach;<br />

architecture A of state_mach is<br />

type STATE_TYPE is (state_A, state_B, state_C);<br />

signal state: STATE_TYPE;<br />

begin<br />

process (reset, clk)<br />

begin<br />

if reset = '1' then<br />

state

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!