# Cool Cap Engineer

## Mojo Makes FPGA Board Design Open Source

Last January, I’ve been learning how to use FPGAs, which I talked about in my Getting Started With FPGAs post.  To learn how to use FPGAs, I brought FPGA development boards, which can cost up to $110, from Digilent.com. Fast forward to March, and I found Mojo, an open source$75 FPGA development board, on Kickstarter.com. Based on what I’ve seen and tested thus far, I honestly think the Mojo board is a great introduction to digital design for electronic hobbyists and electrical engineering students.

What’s Under The Hood?
Unlike the Basys 2 that I commonly use, the Mojo uses a Spartan 6 XC6SLX9 FPGA. The Spartan 6 uses a 50MHZ clock, which is 10MHZ higher than the maximum clock frequency that a PIC18F can run.  In layman terms, it can run faster than most of my microcontroller/FPGA boards. The board can accept between 5V-12V, but can only output 3.3V for each digital I/O pin. Because of the Mojo’s 3.3V limitation, you’ll need extra hardware to use electronic items like servos, solenoids, etc. Finally, the Mojo uses an Atmega16U4 for the USB connection among other things.

What’s So Special About The Mojo?

The Mojo board is geared towards making digital design easy for hobbyists and electrical engineering students by taking advantage of the board’s Atmega16U4 microcontroller, which is used to implement your digital designs on to the board. However, the Atmega16U4 is not just used for uploading your designs to the Mojo. The Atmega16U4 is used to communicate serial objects like serial LCDs, XBee wireless modules, and even Sparkfun’s FTDI breakout boards, with the Mojo.  You can even use the analog to digital converters included with the Atmega16U4 to allow the Mojo to take in analog signals.

What I Love About The Mojo ?

Although this seems like a petty thing, one of the key qualities I look for in a FPGA development board these days is the number of accessible I/O pins.  When I first heard that the Mojo will offer 84 accessible I/O lines, I immediately gave my pledge for the project  In fact, the lack of accessible pins for the Basys 2 FPGA board severely limited me in terms of FPGA projects. Embedded Micro even added 8 LEDs on the board for FPGA beginners to use. These LEDs are prefect for beginners as they implement simple modules using these LEDs. During the early stages of testing the board, not only did I create a blinking module for one LED, but I also used the same module to control the other seven LEDs on the board.

Despite the sheer number of I/O pins available, one cannot forget the fact that the Mojo is open hardware, which simply means that the Mojo’s schematic is available to view. This is crucial if you want to create your own FPGA development board, but do not know where to start. In fact, I will probably use the Mojo’s schematic in the future.

Work Done Thus Far ?

Currently, I do not have any project plans for the Mojo board. My focus has been learning how to effectively use the Mojo board. Recently, I learned how to control a servo using the Mojo board, even though most servos can only powered using 5V. I was able to control the servo by connecting one of the Mojo’s pins to the optoisolator’s input pin, and the servo’s signal pin to the optoisolator’s Vo pin. Although I could not find a power supply around, I used my Arduino board to provide the right power to the servo.

Where Can I Learn How To Use The Mojo Board?

Although I am planning to write tutorials on how to use the Mojo board for this blog, you can visit Embeddedmicro.com, where you can read tutorials on how to implement serial communication, servo control, and other digital modules onto the Mojo. If you want to purchase your own Mojo board, then visit this URL. Please keep in mind that the Mojo board only cost \$75.

## Tutorials: Getting Started With FPGAs

So today, I thought I would talk about something other than microcontrollers. Today, I will talk about how to get started with FPGAs.

# What is a FPGA?

An FPGA is a field programmable gate array. Instead of programming a FPGA  like your standard microcontroller, you actually “implement” digital circuits using a hardware description language (HDL). The two common hardware description languages includes VHDL and Verilog. For today’s tutorial, we’ll implement our design using Verilog.

# FPGA vs Microcontrollers

So what are the advantages of using a FPGA rather than a microcontroller?  The problem with microcontrollers is that they cannot run co-currently, or only run sequentially, and very time limited. A FPGA runs in parallel, or able to run multiple things at once, and much faster than microcontrollers.  However, FPGAs are very space limited and initially does not come with all of the fancy peripherals that microcontrollers have. Things like timers, UART, and SPI must be implemented by hand on the FPGA. Also, to have your design stay with the FPGA,  you have to use a re-programmable flash memory IC.

# Parts List

To get started, you need only the following items

Hardware

Software

# Installing Xilinx Web ISE

• To learn how to install the Xilinx Web ISE, I highly recommend visiting this URL .They have all the necessary information on properly installing the ISE.

• To program the Basys 2 board, you need to download Adept from Digilent’s website. Just follow the on screen prompts for proper installation.

# Starting A Project

• To create a new project, go to file->new project
• At the create project screen, select a name and location for the project. For this example, let’s name the project “First_Project” and set the location to any location on your computer. Make sure you select “HDL” as your Top-level source type.
• For project settings, make sure you have the following set…
1. Family is set to Spartan3E
2. Device is XC3S100E
3. Package is CP132
4. Speed is ~4
5. Synthesis Tool is XST (VHDL/Verilog)
6. Simulator is ISim (VHDL/Verilog)
7. Preferred Language is Verilog

• At Project Summary, select Finish.

# Creating Verilog Module

• At the project menu, you should see x3s100e-4cp132. Right click on this and select “New Source”
• At the new source menu, select Verilog module and set the name to blink.
• When prompted at the define module, just click next. We’ll define the inputs and outputs later on. Afterwards select finish.
• In your blink.v file, copy and paste the following code into the file.
• Make sure to hit save.

# Creating UCF File

Although we created the module, the FPGA does not know which pins on it should be connected to the module’s inputs and outputs. This is where the UCF file comes in.

• Right click you blink.v file and select “New Source”
• In your new source menu, select ” Implementation Constraints File.” We’ll name this file “blink”. Don’t worry, this will not replace the blink.v file.

• Hit next and select finish
• Make sure to hit save.

# Creating Bit File

Okay, so we’re almost ready to program- I mean ” implement”- our digital design on the FPGA. FPGAs are usually programmed using a bit file. We’re going to create a bit file using the Web ISE.

• Your should see ” Generate Programming File” in the Processes menu. Click on it.

• Wait for a little bit for the ISE to finish creating the bit file.

# Checking Connections

It is very important to check to see if the FPGA really routed the inputs and outputs correctly. To do this…

• In the Processes menu, select ” Design Summary/Reports”
• In Design Overview click on ” Pinout Report”
• Check to see if “clk_in” is connected to B8 and “out” is connected to M5.

• As shown above, the ISE did not correctly route the connections. This can be solved by resaving your UCF file and clicking the “Generate Programming File” option again.

We’re at the final part of the tutorial!

• Connect the Basys 2 to your computer and turn on it on.

• You can upload the bit file to the main FPGA or the board’s re-programmable flash memory. Since we want the board to remember the bit file whenever we turn on or off the board, we’ll program the bit file to the reprogrammable flash (PROM)
• Click browse button next to the PROM option
• Navigate to your project folder.  The bit file should be inside the folder.
• Hit “program” next to browse
• After the bit file is uploaded to the board, turn off then turn on your board. You should see  LD0 blink every 500ms.

# How does it work?

First thing, we need to use the 50MHZ clock on the board to tell the FPGA when 500ms has occurred. But how? Well, frequency is really counts per second. Using unit conversion and an onboard counter , we can find how many counts it takes for 500ms to occur.

$\frac{50,000,000}{seconds}*500ms=25,000,000$

Now that we know the counts, how do we use it in our design? We can use a register, a variable inside verilog, to function as our counter.  During the positive edge of the clock, we tell the design to increment the counter by 1. When counts reaches 25 million, the design resets the counter to 0 then invert the output of the LED, which is initially set to off.

I remembered my professor at RPI had a famous saying about RF electronics: “Once you build an RF transmitter from scratch that can transmit 50 feet, then you’re ready to get a P.H.D.” The point she was trying to make is that RF electronics is one of the toughest electronics engineering fields out there.  It requires a lot of impedance matching, fabricating printed circuit boards, and choosing the right amplifier just to make a RF transmitter. Rather than trying to build an RF transmitter/receiver from scratch, Digi sells the X-Bee Wireless Radio, which is specifically designed to work with microcontrollers. Today’s tutorial will show you how to get started using X-Bee Radios. Although I typically use PIC microcontrollers for my tutorials and this tutorial can be revised for any microcontroller, I will use an Arduino Mega board this time.

# Parts List

Hardware

1. Arduino Mega (1x)
2. FTDI Programmer (1x)
4. X-Bee Radio Breakout Boards (2x)
6. 3.3V Voltage Regulator (1x)

Software

# First things, first

Solder the X-Bees to the X-Bee breakout board. The X-Bee modules cannot fit onto a breadboard due to the pitch spacing and the breakout boards allow the modules to be placed on a breadboard.

# Setting Up The X-Bee For The Computer

Wire the FTDI programmer, 3.3V voltage regulator, and X-Bee Radio to the breadboard as shown in the figure below.

Make sure that…

1. GND of the FTDI programmer is connected to GND (pin 1) of the voltage regulator and GND ( pin 10) of the X-Bee module
2. VCC of the FTDI programmer is connected to VIN (pin 3) of the voltage regulator.
3. VOUT (pin 2) of the voltage regulator to Vin (pin 1) of the X-Bee module.
4. RX of the FTDI programmer to Dout (pin 2) of the X-Bee module.

Now connect a USB cable to your FTDI programmer. From there, open up X-CTU.

Select one of the COM ports (for me, my FTDI programmer was connected to COM6) and select Test/Query. This just checks to make sure your FTDI programmer is properly connected to X-CTU. You should receive this message if the FTDI programmer is successfully connected to the computer.

If you did not receive this prompt, then it could mean the following…

1. One of the connections is loose. Make sure your connections are solid.
2. The COM port is in use. Disconnect the programmer and reconnect it to the computer. If that does not work, then restart the computer and try again.
3. You could have a bad programmer if 1 and 2 does not work.

Now click on terminal. Leave this open! We will come back to this later.

# Setting Up The Arduino Mega

Now upload the following code to the Arduino Mega.

void setup()
{
Serial2.begin(9600);
}

void loop()
{
Serial2.print("Hello World \r\n");
delay(1000);

}


While your Arduino is connected, make the following connection.

Make sure that….

1. 3V3 of the Arduino Mega is connected to VCC (pin 1) of the X-Bee
2. RX2 of the Arduino Mega is connected to Din (pin 3) of the X-Bee
3. GND of the Arduino Mega is connected to GND (pin 10) of the X-Bee

# Now For Some Action!

Navigate back to your X-CTU terminal window. You should start to see “Hello World” printed on the screen multiple times.

# Couple Key Things To Keep In Mind

1. The X-Bees in this tutorial  can only work with a baudrate of 9600. If you want a X-Bee with a higher baudrate, then look at this one.
2. X-Bees can only work with 3.3V power. DO NOT CONNECT ANYTHING HIGHER! IT WILL NOT WORK.
3. X-Bees can work with any microcontroller. Just connect the microcontroller TX line to the X-Bees Din to allow your microcontroller to transmit data. If you want your microcontroller to recieve data, then connect its RX line to the X-Bee’s Dout line.

Well that’s it for me! Feel free to post a comment underneath this post for any comments or suggestions. See you guys later!

## Projects: Face Tracking Turret Update #2

Hey guys! I finally have some time to update the blog. So, I figure today’s blog post will be an update on my face tracking turret project. In my last post, I mentioned I ran into some difficulty with figuring out a way to implement the image tracking in Matlab.  However, I ran into an article that will jump start this project.

In an article posted by Sparkfun, they implemented a face tracker using Processing, an open source programming language developed by the folks who worked on the Arduino. The interesting thing is that there is an Open CV library, in Processing. For those who do not know, Open CV is an open source computer vision library that can be implemented in C++, Java, Python, and even Android. I’m 100% certain I will be utilizing the Open CV library for this project.

As for the decision to go with the USB missile launcher or the water pump, I decided that the only way to decide is by buying the USB missile turret and reverse engineer it. In other words, I will take it apart and learn how to control it using the Arduino. If it is possible to control it using the Arduino, then I will use the USB missile turret. If not, then I will use a water pump instead. I will buy the missile turret sometime next week. I will let you guys know what I found from USB missile turret breakdown and a way to control it manually from your Arduino.

## Projects: Face Tracking Turret Update #1

Hey guys! Long time no chat. Sorry for my lack of updates lately, but I’m not only swapped with school work, but I have a ton of research work as well. A couple weeks ago, I mentioned to you guys about my new project, the face tracking turret. Well, it turns it might be more difficult than I imagined. Not only because I never did image tracking before, but because my original idea on how to do the face tracking is probably not going to work.

My original idea for the face tracker is to connect the camera to Matlab 2012b, use its image processing library and computer vision library. I knew for a fact that Matlab can do image processing without any problems. The problem? Well…the computer vision library costs an arm and leg. That’s no problem, right? My school’s Matlab license should cover it? Nope. The library is so expensive, that even my school refused to add it to our Matlab 2012b installation. I will try to see if the computer vision library is in the Matlab 2012a installation but I doubt it. However, there is another option. I looked into OpenCV, an image processing library for not only Android phones, but Python as well! So project is far from over.

Another important issue I started to think about was the turret’s defense mechanism. Originally I thought about using USB missile launchers, but there’s no documentation on how to take these things apart. I have two options: take the usb missile launcher apart myself and post the documentation online, or have the turret shoot water at its victims. I’m still thinking about it.

In the past, I always used PIC microcontrollers in a heartbeat. However, I think I will stick with the Arduino this time. Most specifically, the Arduino Mega 2560. You know the best part? I got it for free from my Mechatronics research. Another reason why I might use the Arduino Mega is the fact Simulink, Matlab’s graphical GUI interface program, fully supports Arduino. So, if I find a way to do image processing using the Matlab, then I can easily create Arduino system blocks in Simulink to create the turret. I am kinda of disappointed that I do not have any tangible results for you guys, but I am still planning for this project. Stay tuned for more details.

## Projects: Face Tracking Turrent

Hey guys! School is going okay-ish. I have fewer classes to take this semester, but I have a part- well contractual- time job, a lab assistant position, and a private tutor positions this semester. Not to mention an undergraduate research project to do. Speaking of which, I figured out my next project!

So the research I mentioned before is a mechatronics research. My friend and I are responsible for testing the new Mechtronics kits this semester. What’s cool about these kits is the fact that they use primarily Arduino, a Lego NXT motor and Matlab. Although I primarily use PIC microcontrollers, my experience with Arduino is much stronger than my experience with PIC microcontrollers. Lately, I came across a lot of tutorials which people are able to track their face using Matlab. Then I saw this beauty.

To make a long story short, I WANT TO CREATE THAT! I want to create a face tracking turret. Although my default choice is to use a PIC microcontroller, I might open the project to Arduino. One of the reasons I want to work on this project is not only the fact it’s wicked, but I have a final project to do for my Mechatronics class. You read that right. I’m doing Mechatronics research and taking a Mechatronics class at the same time. Ironic isn’t it (if not cheating according to my multiple friends)?

Keep in mind; I have no experience with image processing. In other words, I need to learn how to use the image processing library in Matlab. I already know how to communicate microcontrollers yo Matlab using serial communication, so I can just skip that step. What I need to figure out is whether I want my device to shoot out water, or to shoot nerf darts. This is going to be a fun project! I’ll see you guys later!

## Electronics: MAX619

One of things I remembered doing a lot last semester at RPI was building various analog circuits in my free time. One of my good friends who’s a lab technician for one of the labs at RPI, had reels of ICs that never been used. He even had 3 reels of Motorloa’s microprocessors that came out in the 1980s. However, one IC that I found extremely useful was the MAX619 IC. The Max619 IC accepts voltages between 2.7 and 3.6 volts, and converts it to 5 volts using charge pumping.

# Max619 Pinout

To be honest, the pinout is really straight forward and I will not go into much detail.

C1+ (Pin 1) and C1- (Pin 8): This is where you connect your .22uF capacitor to.
In (Pin 2): This is where you connect your input voltage to. As I stated before, the input voltage range from 2.7 to 3.6 volts.
Out (Pin 3): 5V output of Max619
C2+ (Pin 4) and C2- (Pin 5): This is where you connect your second .22uF capacitor to.
GND (Pin 6): Connect this pin to 0V of your power supply
SHDN (Pin 7): To make sure the IC is properly working, connect this pin to 0V. Otherwise, the chip will not turn on.

# Circuit Diagram

Although there’s an example schematic in the datasheet, I decided to create a quick schematic in Eagle Cad to show where you should connect your capacitors to. Please note: the IC will not work if you connect a capacitor from C1+ to C2+ and from C1- to C2-.

# Increasing Output Current

Although the voltage will increase from 2.7-3.6 volts to 5v, the output current will be really low. When I first tested the IC, I got around 90ma. If you need to power more beefier devices, then you can connect two or more MAX619′s in parallel. In fact, the picture above shows me building a two level multi-level DC to DC converter using two MAX619 ICs. The output current of the converter was around 180ma. Since you’re increasing the output current of the device, you’ll also increase the input current the device needs. My advice is to use the chip with hi-current batteries such as Lithuim Ion batteries.

That’s all I have for you guys today. If you guys have any questions or concerns, feel free to post a comment!