Note: This tutorial was made for the Mojo v3 board using Xilinx ISE 14.6 on Windows 7. Important: Before following this tutorial, make sure you have your development environment set up properly. The guys at Embedded Micro do a much better job describing this process than I could. See their tutorials at: Also: All screenshots in this tutorial are clickable links to the full resolution captures! IntroductionThe tutorials on Embedded Micro do a very good job with setting up the development environment, but expect you to use a pre-designed ISE project. This document will teach you how to make your own project from scratch, without relying on the Mojo-Base file that ships with the device.The resulting project from this tutorial is not a replacement for the full-featured Mojo-Base project. However, once you have learned to configure your own project, you will be able to include the parts of the Mojo-Base code that you would like without problem!
Because of this, I still highly recommend following through the
Embedded Micro tutorials. Their tutorials will show you how to use some
of the unique features of this development board, such as the interface
to the onboard microcontroller. First, open the ISE Design Suite on your machine. Then, to create a new project, go to [File --> New Project...]. This will automatically close any open project, and open the creation wizard. Go ahead and give your project a name, and a location. The
"Working Directory" field can be left as the same path as the
"Location" field. However, if this is the case, all of the project build
files will be dumped in your project directory. This is no good! I put my project files in the "syn" (synthesis) directory within my project. Type out a description if you wish. ![]() When you're ready, go ahead and press Next. In
this window, you need to enter the specifications of the hardware
device the project is targeting. In this case, the Mojo board has a
Spartan6-XC6SLX9 onboard. The package used is a TQG144, and the speed
grade is "-2". You can also choose between Verilog and VHDL in this menu, in the "Preferred Language" field. - this tutorial uses Verilog. ![]() Once this is all set, go ahead and click Next, then Finish. Adding a Source FileNow that we have the project made, we have to add a source file to this. We do this by selecting [Project --> New Source...] from the top menubar.Since we are
working in Verilog, we want to create a new Verilog module. A module is
simply a description of hardware functionality. Sort of like a function
in procedural programming, a module encapsulates and abstracts some
logic in a "black box", with ports that allow input and output. You
can give the module any name that you would like. However, there are
some reserved characters that the wizard will accept, but do not
compile! I learned the hard way that '-' (dash) is an invalid module
name. I put my module file
at the top directory of my project. However, if you wanted to keep
things all organized and stuff, you're welcome to put it in a "src"
subdirectory (or any other name you choose). ![]() Make sure that the "Add to project" box is checked, and then click Next. In
the next window, you can define ports. These are the inputs and outputs
of your module. For this example, we are going to create a port for the
reset button, and a port for a single LED on the board. To do so, we
will create a port named RESET_N (the _N is to indicate that the port is
inverted - that is, the reset button produces a HIGH signal when
unpressed, and a LOW signal when pressed). Make sure this port's direction is an input. Then, make another port named LED, and mark it as an output. ![]() In
the righthand frame of the IDE, there should now be a blank module
created with the ports that you described. We have the freedom to use
these ports however we like inside the module. For this tutorial, we are
just going to connect them together such that pressing the reset button
turns the LED on. We just need to add a single line of code before the
EndModule line. The code to do this is as follows: assign LED = ~RESET_N; This
is almost the simplest line that can be written in Verilog. It simply
takes the state of the RESET_N port inverts it (~ is a bitwise NOT), and
assigns it to the LED port. This means that whenever the button is HIGH
(not pressed), the LED is LOW (off), and whenever the button is LOW
(pressed), the LED is HIGH (on). Perfect! Remember, if you want to double check that your code looks right, you can just click on the screenshot above. Assigning the PinsNow,
we have a problem though. ISE doesn't know what external pins the LED
and button are connected to. In order to tell it, we create a file to
instruct the synthesizer how to connect our module ports to the physical
hardware. This is done in a file called the Implementation Constraints
File or the User Constraints File. These names seem to be used
interchangeably. In order to
create the .UCF file, we again use [Project --> Add Source...]. This
time, instead of picking the Verilog module, we choose the
Implementation Constraints File. I named mine mojo_pinout, but again,
any name is fine. Make sure it's located in the project (or a project
subdirectory, if you want). Again, check that Add to project is selected, and then click Next, and then Finish. The
.UCF file is used to describe a lot of different constraints for your
project. ISE provides a variety of tools and wizards to help you
configure this automatically. However, for now, we only need two very
simple constraints, and so we are going to write them in manually. Attaching a port (or NET, in the file syntax) to a pin follows the following syntax: NET "name" LOC = Pn; where
the "name" exactly matches the port name in the module, and Pn refers
to the pin number on the part. These are labeled on the Mojo board, and
additionally are documented in the pinout specification document for the part, or the package and pinout pdf file
available from Xilinx. However, there is no information on the board or
in the documentation for which pins on the FPGA are already used on the
Mojo board! If you're looking for this pinout information, please see my Mojo pinout tutorial! However, for this tutorial, we're going to use the switch on pin 38, and the LED on pin 123. So, the content of the .UCF file will be: NET "RESET_N" LOC = P38; NET "LED" LOC = P123; ![]() At this point, our code is all set to go! However,
we still need to configure a setting inside ISE to make sure we generate
the correct output. To do so, first make sure your module file is
highlighted in the file hierarchy in the top left of your screen. Next, in the bottom left, go to the "design" tab, and right click on "Generate Programming File". ![]() Clock on "Process Properties..." In
this menu, we need to tell ISE to generate a binary file. This file is
what we will load into the FPGA through the mojo_loader application. To
do this, check the box on the "-g Binary:" row under general options.
This will enable output of a .bin file during synthesis. ![]() Select OK. Now,
we are ready to synthesize our programming file. To do this,
double-click on "Generate Programming File", in the Design tab in the
lower-left portion of your screen. ![]() This
process will take several minutes. When it is complete, switch to the
mojo_loader application you installed during the Mojo setup process. In
this application, select the serial port your Mojo is plugged into.
Unless you have multiple USB-serial devices plugged in, there will
probably be only one option in this menu. Then, click "Open Bin File", and navigate to the project working directory folder. ![]() With "Store to Flash" and "Verify Flash" checked, click Load, and wait for Done to appear in the bar. Now, when you press the button on your Mojo, the LED closest to the button should light! Thank
you for following this tutorial. If you have any questions about it, or
something didn't work right, don't hesitate to reach out to me from the
Contact page! |
Tutorials > Mojo FPGA Tutorials >