Stay in touch with EE Times Asia

EE Times-Asia > FPGAs/PLDs

FPGAs/PLDs

# Performing math operations in FPGAs (Part 2)

Posted: 07 Jan 2014     Print Version

Keywords:FPGA  binary coded decimal  BCD  general-purpose device  mathematical operations

In my previous article, I discussed some simple methods to multiply and divide by 10 in any general-purpose device, not just in an FPGA. Some readers asked why in the heck I would even consider doing such a thing (as opposed to sticking with binary representations). Well, the answer is along the lines of "We are base-10 creatures living in a base-10 world." Much of what we do is related to the decimal system, so we often find the need to multiply and divide by 10. Let's figure out some ways to do it quickly and efficiently. Sometimes this can lead to things that work better in the base-2 world of numerical machines.

I think I mentioned this last time, but my quick investigation into such frivolity didn't work out for me. I didn't find an easier way to do the math. It was time for me to get back in the box and conform to binary (drat).

What to do? There are plenty of ways to represent real numbers in a binary system. I would guess the three most common are probably binary coded decimal (BCD), floating point, and fixed point. Each has its strengths and weaknesses, depending on your end game. As such, I guess this issue will feature a brief discussion of these three representations and perhaps will touch on their strengths, weaknesses, and implementations.

Let's start with BCD. It's not used as much as it once was, but we can still find it hither and yon—mostly in applications where the data will be directly driving a display of some sort (e.g., a seven-segment display). And this, of course, is the beauty of BCD. The individual digits not only represent the decimal system with which we are naturally comfortable, but they can also be treated as separate circuits for mathematical operations. There's another positive ramification to this representation: We can represent any number exactly if we are willing to allocate the bits to do so. For instance, 0.2 in BCD is 0.2, but in binary, it might be 00110011... (in, say, a fractional-only fixed-point representation).

Let's take a quick look at just what BCD is. There are, in fact, multiple formats for this representation, but (ignoring compressed and uncompressed) the most common usage is shown in the following table.

Now that we know what it is, how do we use it? In an FPGA, I would imagine that the most likely use might be in output and input encoding to some external (human) user. With that thought in mind, let's talk about how we might go about interfacing to the outside world.

Let's consider the case where we want to do all our manipulations in binary. In this case, we will want to convert our BCD encoded data into binary. This can be achieved as illustrated below.

1 • 2 • 3

 Related Articles Editor's Choice
Article Comments - Performing math operations in FPGAs ...
Comments: *  You can enter [0] more charecters.

Top Ranked Articles

Webinars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.