Tinkering part 2

T

The last installment I mentioned how I branched out in my tinkering, and bought a basic FPGA board to play with. While the major makers (Alterra (now Intel) and Xilinx both have prototype boards, they are typically focused on the high end, and are quite expensive. I bought the Embedded Micro “Mojo” board, a modestly priced unit with a suitably powerful Xilinx Spartan6 FPGA.

I did get the IDE working, it is a pretty simple Java application, however, it requires a pretty hefty development package from Xilinx, their ISE Design Suite tools. As that is supported only on Windows and Linux, it does force me to keep a functioning Windows system around. Following the instructions was pretty straightforward, and I had to apply for a webPACK license (free) to use the toolchain. Simple, but it was a monstrous download (about 7 gigabytes).

The Mojo IDE is essentially a front end to the ISE Design Suite, that keeps track of the source and module files.

After installing, I did a quick sample project (it just tied the reset button to one of the on-board LED’s) and all was functional.

Differences between Arduino and Mojo.

Apart from the form factor, there really isn’t much to say they are similar.

The board has 3 dense connectors (think old IDE disc cables), some built in LEDs a micro-USB connector (for IO and downloading .bin files) and a 5v DC input. Apart from the Spartan6, there is an arduino chip to handle the setup and IO, and flash ram for storage of bin files between power cycles.

If you have experience with procedural programming (in C, Python, Basic, or whatever), you are in for a shock. FPGA’s are not microprocessors. There aren’t registers, and opcodes, and cache memory, heck, there isn’t even “memory” unless you make it yourself.

The Arduino chip is programmed with pretty much straight C code. It is built and compiled via their IDE. You can import libraries and headers that allow it to interface with a plethora of devices (sensors, stepper motor controls, displays, radios, cameras, etc.)

FPGA’s allow the configuration (and reconfiguration by reloading a .bin file) of digital circuits. Built from logic units. AND gates, OR gates, XOR gates, operators like NOT, and other boolean constructs, they are combined into a circuit, that behaves exactly as if you build a breadboard out of discrete components. Transistors, gates, and even larger blocks. The function is built around the actual circuitry, no programming in the usual sense. The circuits are built around the concept of TTL digital logic.

My last exposure to digital circuits was way back in college, a physics electronics class, where I probably knew more about boolean logic than the prof (Dr. Duggan), so “rusty” doesn’t describe my knowledge. Still, I do know how the gates function, how to build a truth table, and the like. But I never picked up on it after than one class, oh so many years ago.

So the tutorials are useful, but somewhat frustrating.

Complexities

First is the language used. The default language for the IDE is something called LUCID. It was apparently developed in the 1980s as a way to describe logical functions, and for the bulk of the work it is pretty straightforward. However, the syntax, and the application is a bit mind bending, especially for someone who can hack a bit in C, Python, and other languages.

Second is the fact that it is so different than programming. You are really building a circuit, something that for each cycle of the clock, the designed application “happens”. If something isn’t working right, you can’t add statements for debugging, extra diagnostic code, or test units. It just doesn’t work, and like a bread board, you have to go figure it out.

If I ever got serious at this, I would need to invest in a logic analyzer, as that is the tool to help debug a circuit. Probably not going to happen though.

The first lesson of synchronous circuitry, we use a flip-flop circuit, tied to a clock that we used to flash a LED. Where on an Arduino board, you would use a delay() function to set the frequency of blinking, on an FPGA you use a series of flip-flops to count clock cycles (50MHz) and use the flip-flops to count the cycles, and when a bit goes high, or low, you turn the LED on or off. Actually, you don’t use the bit to turn it on or off, you just tie the LED to that bit, and when it is set or reset, the LED is on or off.

Mind-bending.

In the Lucid language, you use a predefined construct, dff for this flip-flop, and the tutorial was pretty weak in describing it, so it seemed like magic (ok, it wasn’t week, but it assumed that you had familiarity, so I had to go do some digging).

D Flip-Flop latch circuitdff stands for a D Flip-Flop. It is a circuit that has some element of “memory” as in the value on the D line is copied to the Q line and it stays there until the next rising edge of the clock signal. A lot of very useful circuits ar built from this.

For the blinker tutorial, we string 25 of them together as a series counter. Each clock cycle adds one to the counter, and when you get to 225 clock cycles, it returns to all 0’s and begins again. Thus for a 50MHz clock, the most significant bit will flip from 0 to 1 and back to 0 at approximate intervals of 0.6 seconds.

Then you just instantiate the flip-flop, tie the Q to the D line, connect the 25th bit to one of the onboard LEDs, and magically, you have a simple circuit that blinks the LED.

I spent a lot of time fiddling with it. Make it 20 bits wide instead of 25 (uh, now it blinks faster than the eye can see), or 30 bits wide (it blinks with a period of minutes). I will admit that it took me FAR too long to understand the concept of a latch or flip-flop. I must be dense. But I did finally grok it, a light went off.

Final Thoughts

As I will be writing much more, I won’t spend too much on this simple summary, but I now have an understanding why FPGA’s don’t do floating point. Unlike a microprocessor, where there are logic and arithmetic units, and since the late 1990’s, floating point units. FPGA’s really have just logic cells and circuit connections. Sure, you could build a CPU, and many people have (heck, Xilinx on their high end FPGAs have the ability to “drop” in a PowerPC processor).

I am sure I am never going to do anything serious with it, but I am enjoying learning. I sure wish I had access to kit like this when I was in my late teens and early 20’s.

About the author

gander

Product Manager in Tech. Guitar player. Bicycle Rider. Dog rescuer. Techie.

By gander

Subscribe to Tralfaz via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 4 other subscribers
July 2017
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Spam Blocked