HDL Synthesis Coding Guidelines
Lattice Semiconductor
for Lattice Semiconductor FPGAs
15-6
Initialization and Default State
A state machine must be initialized to a valid state after power-up. This can be done at the device level during
power up or by including a reset operation to bring it to a known state. For all Lattice Semiconductor FPGA devices,
the Global Set/Reset (GSR) is pulsed at power-up, regardless of the function defined in the design source code. In
the above example, an asynchronous reset can be used to bring the state machine to a valid initialization state. In
the same manner, a state machine should have a default state to ensure the state machine will not go into an
invalid state if not all the possible combinations are clearly defined in the design source code. VHDL and Verilog
have different syntax for default state declaration. In VHDL, if a CASE statement is used to construct a state
machine, “When Others” should be used as the last statement before the end of the statement, If an IF-THEN-
ELSE statement is used, “Else” should be the last assignment for the state machine. In Verilog, use “default” as the
last assignment for a CASE statement, and use “Else” for the IF-THEN-ELSE statement.
Full Case and Parallel Case Specification in Verilog
Verilog has additional attributes to define the default states without writing it specifically in the code. One can use
“full_case” to achieve the same performance as “default”. The following examples show the equivalent representa-
tions of the same code in Synplify. LeonardoSpectrum allows users to apply Verilog-specific options in the GUI set-
tings.
“Parallel_case” makes sure that all the statements in a case statement are mutually exclusive. It is used to inform
the synthesis tools that only one case can be true at a time. The syntax for this attribute in Synplify is as follows:
// synthesis parallel_case
Using Pipelines in the Designs
Pipelining can improve design performance by restructuring a long data path with several levels of logic and break-
ing it up over multiple clock cycles. This method allows a faster clock cycle by relaxing the clock-to-output and
setup time requirements between the registers. It is usually an advantageous structure for creating faster data
paths in register-rich FPGA devices. Knowledge of each FPGA architecture helps in planning pipelines at the
When Others in VHDL
...
architecture lattice_fpga of FSM1 is
type state_typ is (deflt, idle, read, write);
signal next_state : state_typ;
begin
process(clk, rst)
begin
if (rst='1') then
next_state <= idle; dout <= '0';
elsif (clk'event and clk='1') then
case next_state is
when idle =>
next_state <= read; dout <= din(0);
when read =>
next_state <= write; dout <= din(1);
when write =>
next_state <= idle; dout <= din(2);
when others =>
next_state <= deflt; dout <= '0';
end case;
end if;
end process;
...
Default Clause in Verilog
...
// Define state labels explicitly
parameter deflt=2'bxx;
parameter idle =2'b00;
parameter read =2'b01;
parameter write=2'b10;
reg [1:0] next_state;
reg dout;
always @(posedge clk or posedge rst)
if (rst) begin
next_state <= idle;
dout <= 1'b0;
end
else begin
case(next_state)
idle: begin
dout <= din[0]; next_state <= read;
end
read: begin
dout <= din[1]; next_state <= write;
end
write: begin
dout <= din[2]; next_state <= idle;
end
default:
begin
dout <= 1'b0; next_state <= deflt;
end
…
case (current_state)
// synthesis full_case
2’b00 : next_state <= 2’b01;
2’b01 : next_state <= 2’b11;
2’b11 : next_state <= 2’b00;
…
case (current_state)
2’b00 : next_state <= 2’b01;
2’b01 : next_state <= 2’b11;
2’b11 : next_state <= 2’b00;
default : next_state <= 2bx;