Maxplus2 Tut v3.0

32
MAX+PLUS II Tutorial Manual Version 3.0 304-487 Computer Architecture Laboratory Prepared by: Albert Au Victor Tyan Boonchuay Supmonchai Prof. Ted Szymanski January 18, 1999 Email: [email protected] Website: www.ece.mcgill.ca/courses/304-487 Acknowledgement : Partial software and hardware support from the "Altera University Program" is gratefully acknowledged.

Transcript of Maxplus2 Tut v3.0

Page 1: Maxplus2 Tut v3.0

MAX+PLUS II Tutorial ManualVersion 3.0

304-487Computer Architecture Laboratory

Prepared by:

Albert AuVictor Tyan

Boonchuay SupmonchaiProf. Ted Szymanski

January 18, 1999

Email: [email protected]: www.ece.mcgill.ca/courses/304-487

Acknowledgement :

Partial software and hardware support fromthe "Altera University Program" is gratefully acknowledged.

Page 2: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 1 January 12, 2001

Table of Contents1. Introduction

1.1 Running MAX+PLUS II .................................................21.2 Overview of MAX+PLUS II .............................................3

2. Creating a design in VHDL2.1 Example: A binary sorting node ..........................................42.2 Entering VHDL code ......................................................62.3 Checking your VHDL code ...............................................6

3. Compiling your VHDL code3.1 Brief description of compiler stages .....................................73.2 Setting compiler options ..................................................8

3.2.1 Selecting a device family .........................................83.2.2 Selecting a global project logic synthesis style ................93.2.3 Turning on the smart recompile command .....................93.2.4 Enabling compilation for VHDL-93 ...........................10

3.3 Running the compiler ....................................................10

4. MAX+PLUS II Simulator4.1 Function simulation versus Timing simulation .......................114.2 Timing simulation using a simulator channel file (.SCF) ............12

4.2.1 Editing a SCF ....................................................134.3 Timing simulation using a vector file (.VEC) .........................14

5. MAX+PLUS II Timing Analyzer5.1 Registered performance ..................................................155.2 Determining the critical path .............................................165.3 Using the Delay Matrix ..................................................17

6. Analyzing synthesis results (.RPT file) ...............................18

7. Changing compiler settings7.1 Viewing logic synthesis equations .....................................197.2 Optimizing logic synthesis for speed ...................................19

8. Guidelines ......................................................................20

9. Resources ......................................................................22

Appendix A VHDL Description .......................................................23

Appendix B Vector file: binary_sort.vec .........................................29

Appendix C Conventions on writing VHDL documentation ......................30

Appendix D FAQ Table of Content ...................................................31

Page 3: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 2 January 12, 2001

1. IntroductionYour approach to creating an electronic design in MAX+PLUS II can have a major impact on both thequality of your design and your productivity in creating the design. At the beginning of the design creationprocess, you should focus on the key design creation issues that affect overall quality, keeping in mind thetasks necessary to successfully complete your design. You should consider the following issues and tasks:

• Carefully planning your design.• Building design hierarchy in VHDL.• Checking design syntax and connectivity.• Testing and simulating each module.• Simulating with different test benches.

1.1 Running MAX+PLUS II

To start Maxplus2 (version 9.0), the following steps are necessary.

However, there is small problem with the system variable settings, which you have to workaround until theproblem is fixed. Each time you logon, you will need to override the variables TEMP and TMP byfollowing these steps. You only have to perform these steps once per logon session.

• From the Start Menu, select Settings -> Control Panel.

• Double-click on the System icon. Select the Environment tab.

• In the User Variable window, select variable "temp" and in the Value field at the bottom, replace "d:\temp" with "f:\temp". Click the Set button.

• Repeat the above step for the user variable "tmp".

• Click the OK button to exit. Close the Control Panel.

• To run Maxplus2, select "Start Menu -> Programs -> MAX+PLUS II -> Maxplus2 9.0".

Page 4: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 3 January 12, 2001

1.2 Overview of MAX+PLUS II

MAX+PLUS II software consists of several application programs and the MAX+PLUS II Manager. Thefollowing describes some of the application programs that will be used in this course.

• Hierarchy Display - Displays the current hierarchy of files as a hierarchy tree with branchesthat represent sub-designs. You can tell at a glance which files are currently open and you canalso directly open or close one or more files in a hierarchy tree.

• Text Editor - The Text Editor lets you create and edit text based logic design files such asVHDL.

• Compiler - Processes logic projects targeted for Altera device families (e.g. FLEX 10K). Itperforms most tasks automatically. However, you can customize all or part of the compilationprocess.

• Waveform Editor - Serves as a tool for entering test vectors and viewing simulation results.

• Simulator - Enables you to test the logical operation and internal timing of your logic circuit.Functional simulation, timing simulation, and linked multi-device simulation are available.

• Timing Analyzer - Analyzes the performance of your logic circuit after it has beensynthesized and optimized by the Compiler.

Page 5: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 4 January 12, 2001

2. Creating a design in VHDLIn this section, you will learn how to enter a VHDL design in text format into the MAX+PLUS II softwareand to check whether the VHDL code you have entered is correct.

2.1 Example : A Binary Sorting Node

The example you are going to explore is the design of a binary sorting node. Figure 1 shows thefunctional block diagram of such a node. It consists of two input D-flipflops, two output D-flipflops, twomultiplexors, and a state machine that controls the two multiplexors. The VHDL code that describes itstructurally is given in Appendix A. Before you continue, please spend some time reading the conventionson writing VHDL code in Appendix C.

DFF

DFF

statemachine

clock

mux

mux

S

S

exchange

x_in

y_in

0

1

0

1

x_out= min (x_in, y_in)

y_out= max (x_in, y_in)

DFF

DFF

reset

upper

lower

x

y

Figure 1 : Functional Block Diagram of a binary sorting node

Note : clock and reset signals go to every flipflop and the state machine

Page 6: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 5 January 12, 2001

After the node is reset, all flipflops and the state machine are cleared. The data are then clocked serially intothe input flipflops with most significant bit first. For every clock cycle, a bit from each input is comparedwith each other inside the state machine which will determine the states of the sorting node.

There are three states in the state machine, "X_equal_Y", "X_less_than_Y", and "X_greater_than_Y", asshown in figure 2.

• If the incoming bits from both signals are equal, the state machine remains in the X_equal_Y state andthe multiplexor’s control signals are set such that x_in connects to x_out and y_in connects to y_out.

• If the bit from x_in is less than the bit from y_in, the state machine will be locked at the X_less_than_Ystate so that the subsequent results of bit comparison would not alter the setting of the multiplexors.

• On the other hand, if the bit from x_in is greater, the node will be locked at the X_greater_than_Y statewith x_in connected to y_out and y_in connected to x_out.

Figure 2 shows the state diagram of the state machine whose behavioral description is given in AppendixA. We will talk more about the approaches that we can describe a design in VHDL in the next assignment.

X_equal_Y

X_less_than_Y

(upper = lower) reset / exchange = '0'

reset reset

upper > lower / exchange = '1'upper < lower / exchange = '0'

X_greater_than_Y

Figure 2 : State diagram of the state machine in a binary sorting node.

Page 7: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 6 January 12, 2001

2.2 Entering VHDL code

To enter this design into MAX+PLUS II

• Choose NEW (File menu), select Text Editor file, and choose OK to open an untitled TextEditor window.

• If necessary maximize the Text Editor window by clicking Maximize button on the top rightcorner of the Text Editor title bar. Type in the VHDL description for the binary sorting nodegiven in Appendix A.

• Choose Save As (File menu). Enter binary_sort into the File Name box and change theAutomatic File Extension to .vhd. Click on OK. Remember that the name of the file has to bethe same as the name of the entity.

• Repeat the steps shown above until you enter all the files in Appendix A. Make sure that yousave all VHDL files in the same directory.

Figure 3: Save As dialog box

2.3 Checking your VHDL code

The next step is to quickly check the correctness of your design using the compiler.

• Make sure that you select the window Text Editor - binary_sort. Choose Project Save &Check (File menu).

• A dialog box will appear asking whether you want to change the current project name to the fileyou are going to compile. Click on YES. Observe what happens.

• Choose OK when the compiler completes its process. If there are no errors and warnings goon to the next subsection.

• If the Message window appears, check for error and warning messages. At this point, errors areusually violations of VHDL syntax. Correct the errors and repeat the process.

Page 8: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 7 January 12, 2001

3. Compiling your VHDL code

3.1 Brief Description of Compiler Stages

The MAX+PLUS II Compiler is a highly automated design processor that transforms design files intooutput files for device programming, simulation, and timing analysis. When you start the compiler, itbegins a series of processes that ultimately creates one or more programming files. While the compiler cancompile a project with minimal assistance, it also allows you to customize processing for a particularproject. The following are brief descriptions of some compiler stages that you should know. For moredetails on the compiler stages and their options, please consult the MAX+PLUS II On-line Help or theAltera MAX+PLUS II Getting Started Manual.

• Compiler Netlist Extractor. The compiler first extracts information that defines thehierarchical connections between design files, then checks the overall project for errors.

• Database Builder. After the Compiler creates an organizational map of your project, itcombines all design files into a fully flattened database for fast and efficient processing.

• Logic Synthesizer. The Compiler applies a range of techniques to increase the efficiency ofyour project and minimize device resource usage. The optional Design Doctor utility checksproject logic reliability both before and after logic synthesis.

• Partitioner. If a project is too large to fit into a single device, the Compiler partitions it amongmultiple devices from the same device family, either automatically or according to yourspecifications.

• Fitter. The Fitter generates a customizable Report File that details resource usage anddescribes how the project will be implemented in one or more device(s).

• Timing SNF Extractor. The optional Timing SNF Extractor creates an SNF file whichcontains the timing data for timing simulation and timing analysis.

• Functional SNF Extractor. The optional Functional SNF Extractor creates the functionalSimulator Netlist File (.snf) required for functional simulation. The functional SNF does notcontain timing information, thus it is generated quicker than the Timing SNF.

• Assembler. The Assembler generates one or more files for device programming.

Figure 4: Compiler window

Page 9: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 8 January 12, 2001

3.2 Setting Compiler Options

In this section, you will learn to change some useful options in the compiler such as Devices and LogicSynthesis Options in order to achieve your design goal. Introduced here are only frequently-used compileroptions. For other options, you must refer to the MAX+PLUS II On-line Help or the Altera MAX+PLUSII Getting Started Manual.

3.2.1 Selecting a Device Family

You can select any MAX+PLUS II- supported device family for your project. You can also allow theCompiler to automatically choose the most appropriate device within a particular family.

To specify the device family

• Choose Device (Assign menu). The Device dialog box is displayed.

• Look at the Device Family supported by the MAX+PLUS II by clicking on the arrow at the endof the Device Family box. Select FLEX10K if it has not been selected.

• Check on the device in the Devices box. Then turn on the option Show Only Fastest SpeedGrades, and observe.

• Choose AUTO in the list of Devices and click OK.

Figure 5: Devices window

Page 10: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 9 January 12, 2001

3.2.2 Selecting a Global Project Logic Synthesis Style

You can select a logic synthesis style for the project that guides the Compiler’s Logic Synthesizer moduleduring compilation. The two main styles are "minimization of silicon resource" and "minimization ofdelay". The default logic synthesis style for a new project is “Normal” . The logic option settings in thisstyle optimize your project logic for minimum silicon resource usage.

To select a logic synthesis style for the project.

• Choose Global Project Logic Synthesis (Assign menu). The Global Project LogicSynthesis dialog box is displayed.

• Move the Optimize scroll bar to the middle (5) and click OK.

Figure 6: Global Project Logic Synthesis window

3.2.3 Turning on the Smart Recompile Command

When the "smart" recompile feature is turned on, the Compiler saves extra database information for thecurrent project for use in subsequent compilations. During “smart” compilation, the Compiler candetermine which modules are not needed to recompile the project, and will skip them during recompilation,thereby reducing compilation time.

To turn on the smart recompile feature:

• Choose Compiler (MAX+PLUS II menu). The Compiler window is displayed.

• Choose Smart Recompile (Processing menu).

Page 11: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 10 January 12, 2001

3.2.4 Enabling Compilation for VHDL-93

VHDL is a standard (VHDL-1076) developed by IEEE (Institute of Electrical and Electronics Engineers).It was standardized in 1987 and hence the designation std 1076-1987 or VHDL-87. The standard wasrevised in 1993 to produce std 1076-1993 or VHDL-93.

By default, MAX+PLUS II will use VHDL-87. To enable compilation for VHDL-93:

• Choose Compiler (MAX+PLUS II menu). The Compiler window is displayed.

• Choose VHDL Netlist Reader Settings (Interfaces menu).

• Select the VHDL 1993 button and click OK.

Note that you must repeat these steps for each VHDL file you compile.

Figure 7: VHDL Netlist Reader Settings dialog box

3.3 Running the Compiler

To compile the project:

• Choose the Start button in the Compiler window. As the Compiler processes the project, anyinformation, error, or warning messages appear in a Message Processor window that opensautomatically.

Page 12: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 11 January 12, 2001

4. MAX+PLUS II SimulatorThe MAX+PLUS II Simulator provides flexibility and control for modeling single or multi-device projects.The Simulator uses a binary simulation netlist file that is generated during compilation to performfunctional, timing, or combined linked multi-device simulation for a project.

You can either define input stimuli with a straightforward vector input language or you can draw waveformsdirectly with the MAX+PLUS II Waveform Editor. Simulation results can be viewed in the WaveformEditor and printed as waveform files.

Figure 8: Simulator window

4.1 Functional Simulation versus Timing Simulation

The MAX+PLUS II Simulator supports functional simulation to test the logical operation of a projectbefore it is synthesized, thereby allowing the designer to quickly identify and correct logical errors. Notethat in functional simulation mode, output logic levels change at the same time as the input vectors i.e., nopropagation delays are used. You can turn on functional simulation by choosing Compiler (MAX+PLUSII menu) and selecting Functional SNF Extractor (Processing menu).

In a timing simulation, the MAX+PLUS II Simulator tests the project after it has been fully synthesizedand optimized. Timing simulation is performed at 0.1ns resolution. You can turn on timing simulation bychoosing Compiler (MAX+PLUS II menu) and selecting Timing SNF Extractor (Processing menu).

Page 13: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 12 January 12, 2001

4.2 Timing Simulation using a Simulator Channel File (.SCF)

The simulator channel file contains some or all of the nodes in the compiled project. This SCF file is thenused to provide inputs and to view the results of the simulation.

To create an SCF file for the binary sorting node:

• Make sure that the design of the binary sorting node has been compiled with the Timing SNFExtractor option turned ON (see section 4.1).

• Choose New (File menu), select Waveform Editor file, select the .scf extension from the listbox and click OK to invoke the Waveform Editor with a new, untitled file.

• Choose End Time (File menu) and type 2us for 2 microseconds. The end time determineswhen the simulator will stop applying input vectors. Choose Grid Size (Options menu), type50ns for 50 nanoseconds and click OK.

• Choose Enter Nodes from SNF (Node menu) to display the dialog box. Turn off the Groupoption under Type (The Inputs and Outputs options should remain turned on). Click List todisplay the available input (I) and output (O) nodes.

Figure 9: Enter Nodes from SNF window

• Press the mouse button on the topmost node in the Available Nodes & Groups box and dragthe mouse to highlight all the inputs and outputs. Choose the right direction button (=>) tocopy the selected nodes. Alternatively, you may double-click on a node to select it.

• Click OK. The selected nodes appear in the Waveform Editor window. All input waveformshave default logic 0. All output waveforms have default undefined (X) states.

Page 14: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 13 January 12, 2001

• To rearrange a node, press the mouse button on the handle to the left of the node name andmove the pointer. A horizontal line displays the current position. Order the nodes in thissequence x_in, y_in, reset, clock, x_out, y_out.

• Choose Save As (File menu). The name binary_sort.scf appears automatically in the FileName box. Click OK to save the file.

4.2.1 Editing a Simulator Channel File

You must edit the input waveforms to provide the input vectors for simulation. As you simulate the project,the simulator overwrites the undefined output waveforms.

To edit the input waveform for clock:

• Move the pointer and press the mouse button on the Value field for the clock input node. Thishighlights the entire waveform for this node. Click on the Overwrite Clock button from the toolpalette on the left side of the window or choose Overwrite Clock (Edit menu). To create aclock waveform at the current grid size (50ns), click OK to accept the default values. Note thatthe clock period is actually 100ns.

You can increase/decrease the scale of the waveforms by choosing Zoom In/Zoom Out (View menu) orclicking on the magnifying glass buttons from the tool palette.

To edit the input waveform for reset:

• Reset is an active high signal. Use the pointer to highlight the interval from 0ns to 100ns (2grid units). Click the Overwrite High (1) button from the tool palette. Repeat this step to asserta logic high for the interval 800ns to 900ns. To assert logic low, click the Overwrite Low (0)button. These commands can also be found in the Edit menu.

To edit the input waveform for x_in:

• Input the value 1101 after the first reset pulse with the most significant bit first. Repeat this stepto input the value 1101001 after the second reset pulse.

To edit the input waveform for y_in:

• Input the value 0111 after the first reset pulse with the most significant bit first. Repeat this stepto input the value 1101111 after the second reset pulse.

Page 15: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 14 January 12, 2001

Some of the final waveforms are shown below:

Figure 10: Sample input waveforms

• Save the changes by choosing Save (File menu) or simply click on the disk button in thehorizontal toolbar.

• Choose Simulator (MAX+PLUS II menu).

• Click on Start to start the timing simulation.

4.3 Timing Simulation using a Vector File (.VEC)

In this part of the tutorial you will perform a timing simulation of the binary sorting node using a vectorfile. Note that this is an alternative procedure to the one outlined above that uses a Simulator Channel File.

• Make sure that the design of the binary sorting node has been compiled with the Timing SNFExtractor option turned ON (see section 4.1).

• Choose New (File Menu), select Text Editor File and choose OK to open an untitled TextEditor window.

• Choose Save As (File Menu). Type binary_sort.vec in the File Name box. Choose OK.

• Type in the vector file as shown in Appendix B of this tutorial.

• Choose Save (File Menu).

• Choose Simulator (MAX+PLUS II menu).

• Click on Simulation input.

• Select binary_sort.vec as the input file and choose OK. The simulator will generate an SCFfile. Choose OK to continue.

• Click on Start to start the timing simulation.

• Choose OK to continue. If there are any errors or warnings you must go back and check thatyou entered the vector file correctly.

• Click on Open SCF to view the results of the timing simulation.

• Choose Fit in Window (View menu) to fit the entire simulation in the Waveform Editor.

Page 16: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 15 January 12, 2001

5. MAX+PLUS II Timing AnalyzerThe MAX+PLUS II Timing Analyzer permits you to analyze the performance of a design after it issynthesized by the Compiler. You can use the Timing Analyzer to calculate a matrix of point-to-pointdevice delays, determine setup and hold time requirements at device pins, and calculate maximum clockfrequency.

5.1 Registered Performance

The Timing Analyzer’s Registered Performance Display shows the worst-case registered performance, i.e.,the maximum clock frequency for every clock signal in the circuit. The Registered Performance Displaymeasures the maximum delay from the Q output of all flip-flops to the data and clock enable of all otherflip-flops, including:

• Clock-to-output delay of the source flip-flop.

• Combinatorial and interconnect delays between the source and destination flip-flops.

• Internal setup time of the destination flip-flop.

Figure 11: Registered performance window

Page 17: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 16 January 12, 2001

5.2 Determining the Critical Path

• Choose Timing Analyzer (MAX+PLUS II menu).

• Choose Registered Performance (Analysis menu).

• Click on Start to run the timing analyzer.

• Record the maximum operating frequency of the binary sorting node and determine where thelongest delay path (critical path) occurs in the circuit.

Note: You can use the options in the Time Restrictions dialog box (Options menu) to list either all pathsthat fail to meet a specified clock frequency or a specified number of paths. After the Timing Analyzerfinds the longest delay paths, you can view the information on the paths by choosing List Paths. You canchoose Locate to locate and highlight each signal path in your VHDL file.

Q1: What is the maximum operating frequency of the binary sorting node?

Q2: Where is the longest delay path (critical path) in the circuit? State briefly where this path lies in theblock diagram. Report all of them, if there are more than one path.

Figure 12: Time restrictions window

Page 18: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 17 January 12, 2001

5.3 Using the Delay Matrix

The Delay Matrix display shows the minimum/maximum propagation delays between source nodes anddestination nodes in the current project. A single delay time means all delay paths are of the same length.To exclude the minimum or maximum delays from the display, and to restrict the lengths of the delay pathsused for the analysis, follow the notes in section 5.2 about setting the options in the Time Restrictions(Option menu).

• Choose Timing Analyzer (MAX+PLUS II menu).

• Choose Delay Matrix (Analysis menu).

• Click on Start to run the timing analyzer.

• Record the maximum propagation delay in the circuit and locate where it occurs. If there aremore than one path, record all of them.

Q3: What is the maximum propagation delay in the binary sorting node? What maximum operatingfrequency does this delay imply? Look for the meaning of this type of delay in the On-line Help.

Q4: Where is this maximum delay located? State briefly where this path lies in the block diagram.Report all paths if there are more than one path.

Q5: Are the maximum operating frequencies obtained from Q1 and Q3 the same? Which frequency willyou use to clock the circuit and why?

Figure 13: Delay matrix display

Page 19: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 18 January 12, 2001

6. Analyzing Synthesis Results (.RPT file)The report file is a text file which contains useful information on how a design is implemented in a targetprogrammable logic device. To view the .RPT file, click on the RPT icon corresponding to the entity in thehierarchy tree of the current project. Alternatively, you may double-click on the report file icon in thecompiler window.

Information on the project as a whole (e.g. name of the target device, no. of user I/O pins, percentage of theresources used in the device) and project compilation messages are listed first.

Next, the device specific information follows. A pin-out diagram of the target device shows the mapping ofuser I/O, VCC, GND and special purpose signals to the physical pins on the chip. The resource usagesection provides a concise description of how the device uses available resources. The fan-in and fan-outstatistics of all input, output, buried (internal), clock and clear signals are listed.

At the end of the .RPT file is a summary of the compilation and logic synthesis settings used for thecurrent design.

Q6: What is the percentage of resources (e.g., Logic Cells, I/O pins) that are used for the binary sortingnode? Include only appropriate sections of the report file.

Page 20: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 19 January 12, 2001

7. Changing Compiler Settings

7.1 Viewing logic synthesis equations

Optional sections can be included in the report file. A more detailed report file can help you locate errors ina project that does not compile successfully.

• Invoke the Compiler and choose Report File Settings (Processing menu). Turn on theEquations option to include the synthesized logic equations in the report file.

• Recompile the project and view the report file.

The Equations section provides the results of extensive logic synthesis. Since synthesis minimizes the logicrequired to implement a design, redundant or unnecessary logic in the original design may not appear in thereport file.

Hint: Since the Equations section in the report file can be very lengthy, it is generally sufficient to turn ononly the User Assignments and File Hierarchy options in the Report File Settings.

7.2 Optimizing logic synthesis for speed

Hardware designers are often faced with the speed-area trade-off. Here, we briefly look at the effect ofoptimizing the synthesis of the design for speed.

• Choose Global Project Logic Synthesis (Assign Menu) to display its dialog box.

• Under Optimize, move the scroll bar towards Speed until it reads 10. Click OK to confirmchanges.

• Recompile the project.

Q7: What are the effects of this optimization on the timing performance (registered performance anddelay matrix) and resource usage? Give a brief explanation on your answer.

Page 21: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 20 January 12, 2001

8. Guidelines

Here are some guidelines that might be useful while using the MAX+PLUS II development system.

• You are strongly encouranged to use the resources on the course web page. The URL is on thefront page of this manual.

• MAX+PLUS II on-line help contains all of the MAX+PLUS II documentation that comes withthe development system. Therefore, you should consult the on-line help whenever youencounter a problem.

• Use only lower case characters for all filenames.

• The entity name in your VHDL description must be the same as the filename.

• Do not label any signal I/O port with the same name as an entity.

• Use the Compiler's Design Doctor utility to check the reliability of your design against one ormore selected design rules.

• Introduction to the toolbar shortcuts:

1 2 3 4 5 6 7 8 9

The toolbar is located along the top of the MAX+PLUS II window. When you put the mousepointer over any button in the toolbar, a one-line description of the button function will appear atthe lower-left corner of the MAX+PLUS II window. Clicking on toolbar buttons allow you toquickly access various MAX+PLUS II applications and options.

Button 1: Opens the Hierachy Display window.

Button 2: Opens the Floorplan Editor window, which allows you to view and edit pin andlogic cell assignments for the current design.

Button 3: Opens the Compiler window.

Button 4: Opens the Simulator window.

Button 5: Opens the Timing Analyzer window.

Button 6: Opens the Programmer window, which together with the appropriate hardwareallows you to program Altera devices.

Button 7: Changes the name of the current project.

Button 8: Sets the current file to be the current project.

Button 9: Opens the top-level file of the current project.

Page 22: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 21 January 12, 2001

• You may use the Altera VHDL library to implement standard functions such as counters,multiplexors, shift registers etc. Select the Old-Style Macrofunctions option (Help menu) toget more details. All VHDL component declarations of the standard library can be found in:

/local/maxplus2/vhdl93/altera/maxplus2.vhd.

To reduce development time, you should use MAX+PLUS II's Library of ParameterizableModules (also called LPM functions). By specifying a set of parameters, known as generics,you can customize these modules to the specification or functionality of the components in yourdesign (e.g. the no. of I/O ports, the width of each port). For more details, select theMegafunctions / LPM option (Help menu).

• MAX+PLUS II only supports a subset of the VHDL language. Therefore, you must checkwhether a certain feature is supported by MAX+PLUS II before you can use it. You can do thisby selecting the VHDL option (Help menu).

• MAX+PLUS II provides VHDL templates as an easy and accurate way for you to enter VHDLsyntax. Once you have inserted a template into VHDL file, you must replace all variables withyour own logic. Each variable name start with double underscore (__) and each keyword iscapitalized. To insert a VHDL construct, position your cursor at the desired location in yourVHDL file. Select VHDL Template (Templates menu) to bring up the VHDL Template dialogbox. Then choose the desired construct from the list.

• Syntax Coloring highlights comments, keywords, identifiers etc. in different colours on thescreen. Hence, it may be useful when editing and debugging your code. To enable this feature,select the Syntax Coloring option from the Options menu.

Page 23: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 22 January 12, 2001

9. Resources• Altera Data Book 1996• Altera MAX+PLUS II Getting Started• Altera MAX+PLUS II VHDL• Altera MAX+PLUS II On-line Help• "A VHDL Primer", Revised Edition, by Jayaram Bharsker, 1995.• "The Designer's Guide to VHDL", by Peter J. Ashenden, Morgan-Kaufman Publishers, 1995.• "Digital Systems Design and Prototyping Using Field Programmable Logic", by Zoran Salcic

and Asim Smailagic, Kluwer Academic Publishers, 1997.• "VHDL and FPLDs in Digital Systems Design, Prototyping and Customization", by Zoran

Salcic, Kluwer Academic Publishers, 1998.• Computer Architecture Lab home page (www.ece.mcgill.ca/~ta487)• Altera home page (www.altera.com)

Page 24: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 23 January 12, 2001

Appendix A - VHDL Description

------------------------------------------------------------------------------- Filename : binary_sort.vhd-- Title : Binary Sorting Node Entity-- Authors : Boonchuay Supmonchai & Ted Szymanski-- Date : May 1996-- Revision : None-- Description : See figure 1 on page 3 of this manual-----------------------------------------------------------------------------

LIBRARY ieee;USE ieee.std_logic_1164.ALL; -- definitions for allowable logic signals, etc.

ENTITY binary_sort ISPORT (

x_in, y_in : IN STD_LOGIC; -- Group of inputs x_out, y_out : OUT STD_LOGIC; -- Group of outputs reset : IN STD_LOGIC; -- Group of controls clock : IN STD_LOGIC

);END binary_sort;

ARCHITECTURE structure OF binary_sort IS

-- Components shown in Figure 1 : Functional Block Diagram

-- COMPONENT statements declare the I/O ports of entities to-- be used without instantiating any of the entities.

-- In Altera's MAX+PLUS II, the VHDL code for each component-- must be saved in a file of the same name with postfix ".vhd"

COMPONENT state_machine PORT ( upper, lower : IN STD_LOGIC; exchange : OUT STD_LOGIC; reset : IN STD_LOGIC; clock : IN STD_LOGIC

);END COMPONENT;

COMPONENT mux21 PORT ( a, b : IN STD_LOGIC; c : OUT STD_LOGIC;

select1 : IN STD_LOGIC);

END COMPONENT;

Page 25: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 24 January 12, 2001

COMPONENT dffr PORT (

D : IN STD_LOGIC;Q : OUT STD_LOGIC;reset : IN STD_LOGIC;clock : IN STD_LOGIC

);END COMPONENT;

-- Define "binary_sort" entity's internal nets or wires

SIGNAL exchange : STD_LOGIC;SIGNAL upper, lower : STD_LOGIC;SIGNAL x, y : STD_LOGIC;

-- In the next section, we have a "structural" description of the circuit shown-- in figure 1. We instantiate the seven components and interconnect these-- components by entering the appropriate signals in the I/O list of each-- component

BEGIN

UPPER_INPUT: dffr PORT MAP (x_in, upper, reset, clock); LOWER_INPUT: dffr PORT MAP (y_in, lower, reset, clock);

STATE_MACHINE1: state_machine PORT MAP (upper, lower, exchange, reset, clock);

UPPER_MUX : mux21 PORT MAP (upper, lower, x, exchange); LOWER_MUX : mux21 PORT MAP (lower, upper, y, exchange);

UPPER_OUTPUT : dffr PORT MAP (x, x_out, reset, clock); LOWER_OUTPUT : dffr PORT MAP (y, y_out, reset, clock);

END structure;

Page 26: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 25 January 12, 2001

------------------------------------------------------------------------------- Filename : state_machine.vhd-- Title : State Machine of the Binary Sorting Node Entity-- Authors : Boonchuay Supmonchai & Ted Szymanski-- Date : May 1996-- Revision : None-- Description : See figure 2 on page 4 of this manual.-----------------------------------------------------------------------------

LIBRARY ieee;USE ieee.std_logic_1164.ALL; -- definitions for allowable logic signals, etc.

ENTITY state_machine ISPORT (

upper, lower : IN STD_LOGIC; exchange : OUT STD_LOGIC; reset : IN STD_LOGIC; clock : IN STD_LOGIC

);END state_machine;

ARCHITECTURE behavior OF state_machine IS

TYPE STATE_TYPE IS (X_equal_Y, X_less_than_Y, X_greater_than_Y); SIGNAL present_state, next_state : STATE_TYPE;

-- In the next section, we have a "behavioral" description of the finite state-- machine shown in figure 2 of this manual

BEGIN

PROCESS(present_state, upper, lower) BEGIN

CASE present_state IS

WHEN X_equal_Y => IF (upper > lower) THEN next_state <= X_greater_than_Y; ELSIF (upper < lower) THEN next_state <= X_less_than_Y; ELSE next_state <= X_equal_Y; END IF;

WHEN X_less_than_Y => next_state <= X_less_than_Y;

WHEN X_greater_than_Y => next_state <= X_greater_than_Y;

END CASE;

END PROCESS;

Page 27: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 26 January 12, 2001

PROCESS(clock, reset) BEGIN

IF (reset = '1') THEN present_state <= X_equal_Y; ELSIF (clock'EVENT) AND (clock = '1') THEN present_state <= next_state; END IF;

END PROCESS;

-- exchange is the control signal for multiplexor

exchange <= '1' WHEN next_state = X_greater_than_Y ELSE '0';

END behavior;

Page 28: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 27 January 12, 2001

------------------------------------------------------------------------------- Filename : dffr.vhd-- Title : D-Flipflop with asynchronous reset (clear)-- Authors : Boonchuay Supmonchai & Ted Szymanski-- Date : May 1996-- Revision : None-- Description: See section 2.1 of the manual-----------------------------------------------------------------------------

LIBRARY ieee;USE ieee.std_logic_1164.ALL;

ENTITY dffr IS PORT ( D : IN STD_LOGIC; Q : OUT STD_LOGIC;

reset : IN STD_LOGIC; clock : IN STD_LOGIC );END dffr;

ARCHITECTURE behavior OF dffr IS

-- In the next section, we have a "behavioral" description of a D-flipflop

BEGIN

D_FF : PROCESS (clock, D, reset) BEGIN

IF (reset ='1') THEN Q <= '0'; ELSIF clock'event AND (clock = '1') THEN Q <= D; END IF;

END PROCESS D_FF;

END behavior;

Page 29: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 28 January 12, 2001

------------------------------------------------------------------------------- Filename : mux21.vhd-- Title : One-bit-wide 2-to-1 Multiplexor-- Authors : Boonchuay Supmonchai & Ted Szymanski-- Date : May 1996-- Revision : None-- Description : See section 2.1 on page 3 of this manual-----------------------------------------------------------------------------

LIBRARY ieee;USE ieee.std_logic_1164.ALL;

ENTITY mux21 ISPORT (

a, b : IN STD_LOGIC; c : OUT STD_LOGIC; select1 : IN STD_LOGIC );END mux21;

ARCHITECTURE behavior OF mux21 IS

-- In this section, we have a "behavioral" description of a 2-to-1 Multiplexor

BEGIN

MULTIPLEXOR : PROCESS(a, b, select1) BEGIN

IF (select1 = '1') then c <= b; ELSE c <= a; END IF;

END PROCESS MULTIPLEXOR;

END behavior;

Page 30: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 29 January 12, 2001

Appendix B - Vector File: binary_sort.vec

% Units default to ns. Input values are interpreted in hexadecimal format bydefault. %

% Specify start and stop time of simulation. %

START 0;STOP 2000;

% Clock ticks every 50 ns i.e., clock period = 100 ns. %

INTERVAL 50;INPUTS clock;PATTERN0 1; % Relative vector values %

INPUTS reset;PATTERN0> 1100> 0 % Absolute time vector values %800> 1900> 0;

INPUTS x_in;PATTERN0> 0100> 1300> 0400> 1500> 0900> 11100> 01200> 11300> 01500> 11600> 0;

INPUTS y_in;PATTERN0> 0200> 1500> 0900> 11100> 01200> 11600> 0;

% Output traces %

OUTPUTS x_out y_out;

Page 31: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 30 January 12, 2001

Appendix C - Conventions on writing VHDL documentation

In a large project with multiple contributors it is essential to have well documented professional code. Thecode should be easy to locate, understand and maintain by a person other than the original author. The codeshould facilitate "re-use", i.e., it should be structured into modules which can be reused by other membersin other parts of the project. The following conventions are expected in your assignments and projects.

Convention 1: Each VHDL file will start with a consistent professional-style header.

Convention 2: The entity and corresponding architecture description must be kept in the same file.

Convention 3: The name of the file should match the entity name with a .vhd suffix to facilitate easylocation and maintenance.

Convention 4: When applicable, the name of the architecture should be the same as the entity plus themodelling style. If the entity name is "toto" and the architectural modelling style is "structural", then thearchitecture name would be "toto_struct".

Convention 5: The header for an entity with a structural description will refer the reader to a structuraldiagram in the report, unless the entity is trivial. The structural diagram will illustrate every internalcomponent and every I/O of the entity. An entity with a behavioral description may not have a structuraldiagram. In this case, the entity must be a component of some higher level entity that does have a structuraldiagram containing this entity. The header will refer the reader to the appropriate higher level entity'sstructural diagram.

Convention 6: For highly repetitive blocks, do not use signals to interconnect. Use port connectionsdirectly. This will minimize the amount of VHDL code and be easier to understand and maintain.

Convention 7: Instantiations using the generate statement should be port mapped positionally, not usingnamed association, i.e., no arrows.

Convention 8: In an entity definition, the ports of the entity should be grouped and listed in the followingsequence: inputs, outputs and control.

Page 32: Maxplus2 Tut v3.0

487 Computer Architecture Lab Page 31 January 12, 2001

Appendix D - FAQ Table of Content

Frequently Asked Questions - GENERAL

1. About MAX+PLUS II (Lab version) 2. About Altera DSP Kit ver. 1.0 3. How do I simulate vectors? 4. How do I print to the printer in 818 from MAX+PLUS II? 5. Design Methodology 6. Useful Hints 7. Reducing Compilation Time - Global Synthesis Options 8. Reducing Compilation Time - Compiling to AHDL 9. Using Long Filenames in Maxplus2 7.21 10. How do I change the font in the Text Editor? 11. How do I change the position of the Tab Stops? 12. What is Syntax Coloring? 13. How do I get the Motif/Windows look? 14. How do I simulate multiple devices? 15. How do I use MAX+PLUS II's command line mode? 16. Is there a template for IEEE format papers?

Frequently Asked Questions - VHDL

1. How do I use MAX+PLUS II VHDL Library Components 2. How do I use MAX+PLUS II LPM Components 3. How do I use AHDL Floating Point Components 4. Where can I find VHDL language references? 5. How do I initialize signals? 6. How do I access bits within a STD_LOGIC_VECTOR? 7. How do I shift bits in a STD_LOGIC_VECTOR? 8. How do I perform arithmetic on a STD_LOGIC_VECTOR? 9. How do I use VHDL variables? 10. How do I create VHDL packages? 11. How do I create VHDL functions and procedures? 12. How do I use VHDL revision 1993? 13. How do I use hexadecimal notation in VHDL? 14. How do I use STD_LOGIC_2D? 15. How do I implement a state machine? 16. How do I check for a signal's rising or falling edge? 17. What VHDL libraries are available in MAX+PLUS II? 18. How do I find MAX+PLUS II's VHDL examples?