Embedded Software and Systems - TOPICS

Wednesday, May 23, 2007

Designing an FPGA to USB Interface


By Blake Henry, Bitwise Systems
------------------------------------------
1.Introduction
I’m going to give you the lowdown on how to interface an FPGA to USB. You know
that every solution has its strengths and its limitations. I’ll help you understand the strengths of FPGAs and the USB and also give you an idea of their limitations as well. Then, you decide for yourself if they’re a good fit for your project or not.

2.Faster than a Speeding Micro
One reason that an embedded designer would incorporate a Field Programmable Gate Array (FPGA) into their design is because of the raw processing performance that FPGAs have to offer. FPGAs deliver user programmable wire-speed multiprocessing capability unequalled by any microcontroller.

In an FPGA, multiple wire-speed processes can be executed concurrently and exclusively by the FPGA. No task switching, threads or interrupts. FPGAs give you multiple digital circuits that operate in parallel with no interruptions at all. So at any point in time, an FPGA can concurrently read an ADC, update an LCD, write to a DAC, perform part of an FFT and drive a video display scan line by scan line all at the same time and never ever miss a
single clock cycle. That’s performance.

Since their arrival on the embedded scene as an ASIC replacement back in the late 1980s, FPGAs have grown in capability to such a degree that today they are a cost competitive and attractive alternative to microcontrollers for embedded systems
.
Today’s FPGAs boast the following:
• Low cost
• Low power
• Fast circuit speed
• Large on-chip memories
• Easy to use design software
• A large portfolio of customizable IP

3. So Why Aren’t FPGAs More Popular?
With all these great attributes, you might wonder why FPGAs don’t yet dominate the
embedded space. In my opinion, the key reason is that today’s FPGA design flow is
still a digital logic design process.

You can enter your design as schematics or you can use a Hardware Description
Language (HDL)
such as VHDL or Verilog, but regardless of the design flow you choose, it’s still a hardware design process. You’re just moving around flip-flops in a sea of gates. All the disciplines required to design digital logic are still required to design for FPGAs.

In my view, as long as these conditions persist, FPGA based embedded designs will
largely remain limited to those which demand the performance that FPGAs can
deliver and can afford an FPGA design specialist on the project.

4. The Universal Serial Bus (USB)
You probably have one of those cool USB flash drives and everyone uses USB to sync their iPod or MP3 player with the PC, so you know how easy it is to use USB. That’s the big sell. And it’s not just hype.

Every PC manufactured has at least one USB port and all the operating systems support USB because it’s the de-facto standard PC peripheral interface. USB is a well engineered and implemented interface that provides adequate performance and a consistent user experience.

What you may not be aware of is that implementing a USB peripheral is not trivial.
Some have described the process as just plain hard work. The convenience and
performance that the user enjoys was paid for behind the scenes by hard working
engineers. As far as serial ports go, USB is a complex bus with lots of
implementation details that just have to be perfect.

Here’s the technical overview: The USB is a host/device (i.e. master/slave) bus. All USB transactions are initiated by the host; a device cannot interrupt the host. The USB requires devices to identify themselves to the host and provide the information necessary to properly configure, power and operate the device. Each device type is required to be uniquely identifiable so that the proper drivers can be loaded tocommunicate with it.

The USB can run at up to three speeds, low speed (1.5 Mbps), full speed (12 Mbps)
and Hi-Speed (480 Mbps).

There are four types of USB transfers: control, interrupt,bulk and isochronous. Today, a Hi-speed USB 2.0 devices can transfer reliable (CRC-
16 checked) data at a maximum theoretical rate of 54 MB/sec over a bulk pipe,
however that transfer rate is not guaranteed. In practice, the transfer rate will be
between 20-30 MB/sec. Data is transferred with guaranteed latency via an isochronous pipe, but is not retransmitted on a CRC failure.

Because the USB is a packet oriented bus and it’s most common implementation is on a non-real time operating system, the bus is subject to inter-packet delays which are manifested at the system level as variable transfer latency. Therefore USB streaming applications typically require a latency buffer. In addition, if the host application software uses data transfer worker threads utilizing asynchronous driver calls to minimize OS generated delays, the latency buffer depth can be minimized.

So in summary, USB is complex to implement and some special care must be taken
for transfer rate critical applications to avoid data loss.

Now for the good news: Thanks to the USB-IF and a wealth of other resources, the
USB is very well documented and supported. ‘USB Complete’ by Jan Axelson is a very useful book that explains all the technical details of implementing a USB device.

There are a number of very good USB device chips available. You can also file lots of USB resources on the web like free IP cores, USB development kits and USB modules
that you can design right into your board.

5. The FPGA + USB Killer Application
With the advent of inexpensive, ubiquitous PCs with Hi-Speed USB ports, powerful
FPGAs and a plethora of sensors and data converters, a new trend in embedded
system design has emerged. This trend is to create what I might characterize as
‘hybrid’ embedded/PC-based systems that combine a sensor or converter with an
FPGA and a USB interface to form a USB device. The USB device is then coupled with
PC software to form an instrument that can often duplicate or exceed the
performance of a ‘pure’ embedded system costing many times more.
Some common examples of systems like this are the popular USB logic analyzers and oscilloscopes and USB Cameras.

Some devices can be integrated with COTS modeling packages like MatLab. This capability allows the user to acquire real world data from the USB device directly into the analysis software for immediate analysis without writing a custom software
application.

0 comments:

Google