Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
xst.pdf
Скачиваний:
141
Добавлен:
11.06.2015
Размер:
5.64 Mб
Скачать

R

Finite State Machines (FSMs) HDL Coding Techniques

(ENUM_ENCODING)” constraint to assign a specific binary value to each state. For more information, see “XST Design Constraints.”

RAM-Based FSM Synthesis

Large FSMs can be made more compact and faster by implementing them in the block RAM resources provided in Virtex and later technologies. “FSM Style (FSM_STYLE)” directs XST to use block RAM resources for FSMs.

Values for “FSM Style (FSM_STYLE)” are:

lut (default)

XST maps the FSM using LUTs.

bram

XST maps the FSM onto block RAM.

Invoke “FSM Style (FSM_STYLE)” as follows:

Project Navigator

Select LUT or Block RAM as instructed in the HDL Options topics of ISE Help.

Command line

Use the -fsm_style command line option.

HDL code

Use “FSM Style (FSM_STYLE)”

If it cannot implement a state machine on block RAM, XST:

Issues a warning in the Advanced HDL Synthesis step of the log file.

Automatically implements the state machine using LUTs.

For example, if FSM has an asynchronous reset, it cannot be implemented using block RAM. In this case XST informs you:

...

====================================================================

* Advanced HDL Synthesis *

====================================================================

WARNING:Xst - Unable to fit FSM <FSM_0> in BRAM (reset is asynchronous).

Selecting encoding for FSM_0 ...

Optimizing FSM <FSM_0> on signal <current_state> with one-hot encoding.

...

Safe FSM Implementation

XST can add logic to your FSM implementation that will let your state machine recover from an invalid state. If during its execution, a state machine enters an invalid state, the logic added by XST will bring it back to a known state, called a recovery state. This is known as Safe Implementation mode.

To activate Safe FSM implementation:

In Project Navigator, select Safe Implementation as instructed in the HDL Options topic of ISE Help, or

XST User Guide

www.xilinx.com

243

10.1

Chapter 2: XST HDL Coding Techniques

R

Apply the “Safe Implementation (SAFE_IMPLEMENTATION)” constraint to the hierarchical block or signal that represents the state register.

By default, XST automatically selects a reset state as the recovery state. If the FSM does not have an initialization signal, XST selects a power-up state as the recovery state. To manually define the recovery state, apply the “Safe Recovery State (SAFE_RECOVERY_STATE)” constraint.

Finite State Machines Log File

The XST log file reports the full information of recognized FSM during the Macro Recognition step. Moreover, if you allow XST to choose the best encoding algorithm for your FSMs, it reports the one it chose for each FSM.

As soon as encoding is selected, XST reports the original and final FSM encoding. If the target is an FPGA device, XST reports this encoding at the HDL Synthesis step. If the target is a CPLD device, then XST reports this encoding at the Low Level Optimization step.

...

 

 

 

 

Synthesizing Unit <fsm_1>.

 

 

Related source file is

"/state_machines_1.vhd".

 

Found finite state machine <FSM_0> for signal <state>.

------------------------------------------------------

| States

 

|

4

|

| Transitions

 

|

5

|

| Inputs

 

|

1

|

| Outputs

 

|

4

|

| Clock

 

|

clk (rising_edge)

|

| Reset

 

|

reset (positive)

|

| Reset type

 

|

asynchronous

|

| Reset State

 

|

s1

|

| Power Up State

|

s1

|

| Encoding

 

|

automatic

|

| Implementation

|

LUT

|

------------------------------------------------------

Found 1-bit register

for signal <outp>.

 

Summary:

 

 

 

 

inferred

1 Finite State Machine(s).

 

inferred

1 D-type flip-flop(s).

 

Unit <fsm_1> synthesized.

========================================================

HDL Synthesis Report

Macro Statistics

 

 

# Registers

:

1

1-bit register

:

1

========================================================

========================================================

* Advanced HDL Synthesis *

========================================================

Advanced Registered AddSub inference ...

Analyzing FSM <FSM_0> for best encoding.

Optimizing FSM <state/FSM_0> on signal <state[1:2]> with gray encoding.

-------------------

244

www.xilinx.com

XST User Guide

 

 

10.1

R

Finite State Machines (FSMs) HDL Coding Techniques

State

| Encoding

-------------------

s1

| 00

s2

| 01

s3

| 11

s4

| 10

-------------------

=======================================================

HDL Synthesis Report

Macro Statistics

 

# FSMs

: 1

=======================================================

Finite State Machines Related Constraints

“Automatic FSM Extraction (FSM_EXTRACT)”

“FSM Style (FSM_STYLE)”

“FSM Encoding Algorithm (FSM_ENCODING)”

“Enumerated Encoding (ENUM_ENCODING)”

“Safe Implementation (SAFE_IMPLEMENTATION)”

“Safe Recovery State (SAFE_RECOVERY_STATE)”

Finite State Machines Coding Examples

The coding examples in this section are accurate as of the date of publication. Download updates from ftp://ftp.xilinx.com/pub/documentation/misc/examples_v9.zip.

“FSM With One Process”

“FSM With Two Processes”

“FSM With Three Processes”

FSM With One Process

This section discusses FSM With One Process, and includes:

“FSM With One Process Pin Descriptions”

“FSM With One Process VHDL Coding Example”

“FSM With Single Always Block Verilog Coding Example”

Table 2-92: FSM With One Process Pin Descriptions

IO Pins

Description

 

 

clk

Positive-Edge Clock

 

 

reset

Asynchronous Reset (Active High)

 

 

x1

FSM Input

 

 

outp

FSM Output

 

 

XST User Guide

www.xilinx.com

245

10.1

Chapter 2: XST HDL Coding Techniques

FSM With One Process VHDL Coding Example

--

-- State Machine with a single process.

--

library IEEE;

use IEEE.std_logic_1164.all; entity fsm_1 is

port ( clk, reset, x1 : IN std_logic;

outp

: OUT std_logic);

end entity;

 

architecture beh1 of fsm_1 is

type state_type is (s1,s2,s3,s4); signal state: state_type ;

begin

process (clk,reset) begin

if (reset ='1') then state <=s1; outp<='1';

elsif (clk='1' and clk'event) then case state is

when s1 => if x1='1' then state <= s2; outp <= '1';

else

state <= s3; outp <= '0';

end if;

when s2 => state <= s4; outp <= '0'; when s3 => state <= s4; outp <= '0'; when s4 => state <= s1; outp <= '1';

end case; end if;

end process;

end beh1;

FSM With Single Always Block Verilog Coding Example

//

// State Machine with a single always block.

//

module v_fsm_1 (clk, reset, x1, outp);

input

clk, reset, x1;

output

outp;

reg

outp;

reg

[1:0] state;

parameter s1 = 2'b00; parameter s2 = 2'b01; parameter s3 = 2'b10; parameter s4 = 2'b11;

initial begin state = 2'b00;

end

R

246

www.xilinx.com

XST User Guide

 

 

10.1

R

Finite State Machines (FSMs) HDL Coding Techniques

always@(posedge clk or posedge reset) begin

if (reset) begin

state <= s1; outp <= 1'b1;

end else

begin

case (state) s1: begin

if (x1==1'b1) begin

state <= s2; outp <= 1'b1;

end

else

begin

state <= s3; outp <= 1'b0;

end

end s2: begin

state <= s4; outp <= 1'b1;

end s3: begin

state <= s4; outp <= 1'b0;

end s4: begin

state <= s1; outp <= 1'b0;

end

endcase

end

end

endmodule

XST User Guide

www.xilinx.com

247

10.1

Chapter 2: XST HDL Coding Techniques

R

FSM With Two Processes

This section discusses FSM With Two Processes, and includes:

“FSM With Two Processes Diagram.”

“FSM With Two Processes Pin Descriptions”

“FSM With Two Processes VHDL Coding Example”

“FSM With Two Always Blocks Verilog Coding Example”

To eliminate a register from the outputs, remove all assignments outp <=… from the Clock synchronization section. This can be done by introducing two processes as shown in “FSM With Two Processes Diagram.”

 

Next

RESET

 

 

 

State

Output

Outputs

 

State

 

Register

Function

 

 

Inputs

Function

 

CLOCK

 

 

 

 

 

 

 

 

Only for Mealy Machine

 

 

PROCESS 1

PROCESS 2

 

 

 

X8986

 

 

Figure 2-76: FSM With Two Processes Diagram

Table 2-93: FSM With Two Processes Pin Descriptions

 

 

 

 

 

IO Pins

 

Description

 

 

 

 

 

clk

 

Positive-Edge Clock

 

 

 

 

 

reset

 

Asynchronous Reset (Active High)

 

 

 

 

 

x1

 

FSM Input

 

 

 

 

 

outp

 

FSM Output

 

 

 

 

 

FSM With Two Processes VHDL Coding Example

--

-- State Machine with two processes.

--

library IEEE;

use IEEE.std_logic_1164.all; entity fsm_2 is

port ( clk, reset, x1 : IN std_logic;

outp

: OUT std_logic);

end entity;

 

architecture beh1 of fsm_2 is

type state_type is (s1,s2,s3,s4); signal state: state_type ;

begin

248

www.xilinx.com

XST User Guide

10.1

R

Finite State Machines (FSMs) HDL Coding Techniques

process1: process (clk,reset) begin

if (reset ='1') then state <=s1; elsif (clk='1' and clk'Event) then

case state is

when s1 => if x1='1' then state <= s2;

else

state <= s3; end if;

when s2 => state <= s4; when s3 => state <= s4; when s4 => state <= s1;

end case; end if;

end process process1;

process2 : process (state) begin

case state is

when s1 => outp <= '1'; when s2 => outp <= '1'; when s3 => outp <= '0'; when s4 => outp <= '0';

end case;

end process process2;

end beh1;

FSM With Two Always Blocks Verilog Coding Example

//

// State Machine with two always blocks.

//

module v_fsm_2 (clk, reset, x1, outp);

input

clk, reset, x1;

output

outp;

reg

outp;

reg

[1:0] state;

parameter s1 = 2'b00; parameter s2 = 2'b01; parameter s3 = 2'b10; parameter s4 = 2'b11;

initial begin state = 2'b00;

end

always @(posedge clk or posedge reset) begin

if (reset) state <= s1;

else begin

case (state)

s1: if (x1==1'b1) state <= s2;

else

XST User Guide

www.xilinx.com

249

10.1

Chapter 2: XST HDL Coding Techniques

R

state <= s3; s2: state <= s4; s3: state <= s4; s4: state <= s1;

endcase

end

end

always @(state) begin

case (state)

s1: outp = 1'b1; s2: outp = 1'b1; s3: outp = 1'b0; s4: outp = 1'b0;

endcase

end

endmodule

FSM With Three Processes

This section discusses FSM With Three Processes, and includes:

“FSM With Three Processes Diagram.”

“FSM With Three Processes Pin Descriptions”

“FSM With Three Processes VHDL Coding Example”

“FSM With Three Always Blocks Verilog Coding Example”

You can also separate the NEXT State function from the state register.

 

Next

RESET

 

 

 

State

Output

Outputs

 

State

 

Register

Function

Inputs

Function

 

CLOCK

 

 

 

 

 

 

 

Only for Mealy Machine

 

PROCESS 1

PROCESS 2

PROCESS 3

X8987

Figure 2-77: FSM With Three Processes Diagram

Table 2-94: FSM With Three Processes Pin Descriptions

IO Pins

Description

 

 

clk

Positive-Edge Clock

 

 

reset

Asynchronous Reset (Active High)

 

 

250

www.xilinx.com

XST User Guide

10.1

R

Finite State Machines (FSMs) HDL Coding Techniques

Table 2-94: FSM With Three Processes Pin Descriptions

IO Pins

Description

 

 

x1

FSM Input

 

 

outp

FSM Output

 

 

FSM With Three Processes VHDL Coding Example

--

-- State Machine with three processes.

--

library IEEE;

use IEEE.std_logic_1164.all; entity fsm_3 is

port ( clk, reset, x1 : IN std_logic;

outp

: OUT std_logic);

end entity;

 

architecture beh1 of fsm_3 is

type state_type is (s1,s2,s3,s4); signal state, next_state: state_type ;

begin

process1: process (clk,reset) begin

if (reset ='1') then state <=s1;

elsif (clk='1' and clk'Event) then state <= next_state;

end if;

end process process1;

process2 : process (state, x1) begin

case state is

when s1 => if x1='1' then next_state <= s2;

else

next_state <= s3; end if;

when s2 => next_state <= s4; when s3 => next_state <= s4; when s4 => next_state <= s1;

end case;

end process process2;

process3 : process (state) begin

case state is

when s1 => outp <= '1'; when s2 => outp <= '1'; when s3 => outp <= '0'; when s4 => outp <= '0';

end case;

end process process3;

end beh1;

XST User Guide

www.xilinx.com

251

10.1

Chapter 2: XST HDL Coding Techniques

FSM With Three Always Blocks Verilog Coding Example

//

// State Machine with three always blocks.

//

module v_fsm_3 (clk, reset, x1, outp); input clk, reset, x1;

output outp; reg outp;

reg [1:0] state;

reg [1:0] next_state;

parameter s1 = 2'b00; parameter s2 = 2'b01; parameter s3 = 2'b10; parameter s4 = 2'b11;

initial begin state = 2'b00;

end

always @(posedge clk or posedge reset) begin

if (reset) state <= s1; else state <= next_state;

end

always @(state or x1) begin

case (state)

s1: if (x1==1'b1) next_state = s2;

else

next_state = s3; s2: next_state = s4; s3: next_state = s4; s4: next_state = s1;

endcase

end

always @(state) begin

case (state)

s1: outp = 1'b1; s2: outp = 1'b1; s3: outp = 1'b0; s4: outp = 1'b0;

endcase

end

endmodule

R

252

www.xilinx.com

XST User Guide

 

 

10.1

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]