Basic HDL Coding Techniques Part1 - 2
Basic HDL Coding Techniques Part1 - 2
Part 1
Welcome
If you are new to FPGA design, this module
will help you build good HDL code that is
optimized for an FPGA
These design techniques promote fast and
efficient FPGA designs
Breakthrough Performance
Three steps to achieve breakthrough performance
1. Utilize dedicated resources
2009
2007 Xilinx, Inc. All Rights Reserved
Virtex-6 FPGA
Performance Meter
DSP48E Slice
FIFO
Dual-Port
BRAM
Statistics
Interface
Rx
Stats
Mx
Proce
ssor
Interfa
DCR Busce
Host Bus
2009
2007 Xilinx, Inc. All Rights Reserved
Tx
Stats
Mx
EMAC
Core
Host
Interface
EMAC Core
Phy
Interface
Client Interface
Examples
Timing Closure
2009
2007 Xilinx, Inc. All Rights Reserved
2009
2007 Xilinx, Inc. All Rights Reserved
FPGA Resources
Can be inferred by all synthesis
tools
Shift register LUT (SRL16E/
SRLC32E)
F7 and F8 multiplexers
Carry logic
Multipliers and counters using the
DSP48E
Global clock buffers (BUFG)
SelectIO (single-ended) interface
I/O registers (single data rate)
Input DDR registers
2009
2007 Xilinx, Inc. All Rights Reserved
Suggested Instantiation
Xilinx recommends that you instantiate the following elements
Memory resources
Block RAMs specifically (use the CORE Generator software to build large
memories)
2009
2007 Xilinx, Inc. All Rights Reserved
Suggested Instantiation
Why does Xilinx suggest
this?
Easier to port your HDL
to other and newer
technologies
Fewer synthesis
constraints and
attributes to pass on
START
UP
OBUF
IBUFG
DCM
BUFG
IBUF
Top-Level
Block
OBUF
OBUF
2009
2007 Xilinx, Inc. All Rights Reserved
Hierarchy Management
Synplify and XST software
The basic settings are
Flatten the design: Allows total combinatorial optimization across all
boundaries
Maintain hierarchy: Preserves hierarchy without allowing optimization of
combinatorial logic across boundaries (recommended)
If you have followed the synchronous design guidelines, use the setting
-maintain hierarchy
If you have not followed the synchronous design guidelines, use the
setting -flatten the design.
Consider using the keep attribute to preserve nodes for testing
2009
2007 Xilinx, Inc. All Rights Reserved
2009
2007 Xilinx, Inc. All Rights Reserved
Multiplexers
Multiplexers are generated from IF and CASE statements
IF/THEN statements generate priority encoders
Use a CASE statement to generate complex encoding
2009
2007 Xilinx, Inc. All Rights Reserved
IF/THEN Statement
Priority Encoder
Most critical input listed first
Least critical input listed last
do_e 0
do_c 1
IF (crit_sig) THEN oput <= do_d ;
do_b
cond_c
2009
2007 Xilinx, Inc. All Rights Reserved
do_a
cond_b
do_d
cond_a
oput
crit_sig
2009
2007 Xilinx, Inc. All Rights Reserved
CASE Statements
CASE statements in a combinatorial process (VHDL) or always
statement (Verilog)
Latches are inferred if outputs are not defined in all branches
Use default assignments before the CASE statement to prevent latches
2009
2007 Xilinx, Inc. All Rights Reserved
CASE Statements
Register the select inputs if possible (pipelining)
Can reduce the number of logic levels between flip-flops
Determine how your synthesis tool synthesizes the order of the select
lines
If there is a critical select input, this input should be included last in the
logic for fastest performance
2009
2007 Xilinx, Inc. All Rights Reserved
CASE Statement
This Verilog code describes a 6:1
multiplexer with binary-encoded
select inputs
This uses fewer LUTs, but requires
multiple LUTs in series on the
timing critical path
2009
2007 Xilinx, Inc. All Rights Reserved
CASE Statement
This is the same code with one-hot
select inputs
This used more LUTs, but requires
fewer logic levels on the timing
critical path
This yields a greater benefit when
the mux is larger
2009
2007 Xilinx, Inc. All Rights Reserved
2009
2007 Xilinx, Inc. All Rights Reserved
Not using a synchronous element will not save silicon and it wastes money
Waste performance
2009
2007 Xilinx, Inc. All Rights Reserved
Ken Chapman
(Xilinx UK) 2003
Q = D_IN;
if (RESET)
Q = 0;
else
Q = D_IN;
FPGA and ASIC Technology
Comparison - 22
2009
2007 Xilinx, Inc. All Rights Reserved
Clock Enables
Coding style will determine if clock enables are used
VHDL
Verilog
FF_AR_CE: process(ENABLE,CLK)
begin
if (CLKevent and CLK = 1) then
if (ENABLE = 1) then
Q <= D_IN;
end if;
end if;
end process
2009
2007 Xilinx, Inc. All Rights Reserved
Summary
Use as much of the dedicated hardware resources as possible to ensure
optimum speed and device utilization
Plan on instantiating clocking and memory resources
Try to use the Core Generator tool to create optimized components that
target dedicated FPGA resources (BRAM, DSP48E, and FIFO)
Maintain your design hierarchy to make debugging, simulation, and
report generation easier
2009
2007 Xilinx, Inc. All Rights Reserved
Summary
CASE and IF/THEN statements produce different types of multiplexers
CASE statements tend to build logic in parallel while IF/THEN statements
tend to build priority encoders
2009
2007 Xilinx, Inc. All Rights Reserved
Xilinx Training
www.xilinx.com/training
2009
2007 Xilinx, Inc. All Rights Reserved
Trademark Information
Xilinx is disclosing this Document and Intellectual Propery (hereinafter the Design) to you for use in the development of designs to operate on, or interface
with Xilinx FPGAs. Except as stated herein, none of the Design may be copied, reproduced, distributed, republished, downloaded, displayed, posted, or
transmitted in any form or by any means including, but not limited to, electronic, mechanical, photocopying, recording, or otherwise, without the prior written
consent of Xilinx. Any unauthorized use of the Design may violate copyright laws, trademark laws, the laws of privacy and publicity, and communications
regulations and statutes.
Xilinx does not assume any liability arising out of the application or use of the Design; nor does Xilinx convey any license under its patents, copyrights, or any
rights of others. You are responsible for obtaining any rights you may require for your use or implementation of the Design. Xilinx reserves the right to make
changes, at any time, to the Design as deemed desirable in the sole discretion of Xilinx. Xilinx assumes no obligation to correct any errors contained herein or
to advise you of any correction if such be made. Xilinx will not assume any liability for the accuracy or correctness of any engineering or technical support or
assistance provided to you in connection with the Design.
THE DESIGN IS PROVIDED AS IS" WITH ALL FAULTS, AND THE ENTIRE RISK AS TO ITS FUNCTION AND IMPLEMENTATION IS WITH
YOU. YOU ACKNOWLEDGE AND AGREE THAT YOU HAVE NOT RELIED ON ANY ORAL OR WRITTEN INFORMATION OR ADVICE,
WHETHER GIVEN BY XILINX, OR ITS AGENTS OR EMPLOYEES. XILINX MAKES NO OTHER WARRANTIES, WHETHER EXPRESS, IMPLIED,
OR STATUTORY, REGARDING THE DESIGN, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, TITLE, AND NONINFRINGEMENT OF THIRD-PARTY RIGHTS.
IN NO EVENT WILL XILINX BE LIABLE FOR ANY CONSEQUENTIAL, INDIRECT, EXEMPLARY, SPECIAL, OR INCIDENTAL DAMAGES,
INCLUDING ANY LOST DATA AND LOST PROFITS, ARISING FROM OR RELATING TO YOUR USE OF THE DESIGN, EVEN IF YOU HAVE
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THE TOTAL CUMULATIVE LIABILITY OF XILINX IN CONNECTION WITH
YOUR USE OF THE DESIGN, WHETHER IN CONTRACT OR TORT OR OTHERWISE, WILL IN NO EVENT EXCEED THE AMOUNT OF FEES
PAID BY YOU TO XILINX HEREUNDER FOR USE OF THE DESIGN. YOU ACKNOWLEDGE THAT THE FEES, IF ANY, REFLECT THE
ALLOCATION OF RISK SET FORTH IN THIS AGREEMENT AND THAT XILINX WOULD NOT MAKE AVAILABLE THE DESIGN TO YOU
WITHOUT THESE LIMITATIONS OF LIABILITY.
The Design is not designed or intended for use in the development of on-line control equipment in hazardous environments requiring fail-safe controls, such as
in the operation of nuclear facilities, aircraft navigation or communications systems, air traffic control, life support, or weapons systems (High-Risk
Applications). Xilinx specifically disclaims any express or implied warranties of fitness for such High-Risk Applications. You represent that use of the
Design in such High-Risk Applications is fully at your risk.
2009 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
FPGA and ASIC Technology
Comparison - 27
2009
2007 Xilinx, Inc. All Rights Reserved