Lesson 4 Fpga I/O: Topics
Lesson 4 Fpga I/O: Topics
FPGA I/O
TOPICS
A. Configuring FPGA I/O
B. FPGA I/O Palettes
C. I/O Types
D. Integer Math
E. Converting Binary Representations
F. Fixed-Point Math
ni.com/training
A. Configuring FPGA I/O
Unnecessary if FPGA Project
Wizard used to configure the
LabVIEW Project
• The FPGA Project Wizard
automatically adds all FPGA I/O
channels for you.
ni.com/training
A. Configuring FPGA I/O
If you did not use the FPGA Project Wizard to create your LabVIEW
Project, then you must add all FPGA I/O channels by hand.
If you would like to add the channels on your own, you must right-click
the FPGA target from the Project Explorer and select New»FPGA I/O
to launch the New FPGA I/O dialog box. Select I/O in the left pane of
the New FPGA I/O dialog box and click Add to add the I/O to the
project. You can name your I/O by clicking the default name and
entering a meaningful name for your application.
Some developers find it simpler to only have the project contain the
channels necessary for their application; whereas other develops prefer
to see all available channels at all times. Neither method creates more
efficient code than the other, so using or not using all FPGA I/O
channels is a matter of preference.
ni.com/training
Using FPGA I/O Nodes
ni.com/training
After adding the FPGA I/O node to the Project, drag
and drop the node from the Project Explorer to the
block diagram. to add the appropriate FPGA I/O node to
the block diagram.
You can also add an FPGA I/O node from the
Functions palette. To select your I/O, click the I/O
name portion of the FPGA I/O node and select your I/O.
You can also add additional I/O to your Project from the
FPGA I/O node. Click the node as mentioned previously
and select Add New FPGA I/O to launch the New
FPGA I/O dialog box.
ni.com/training
B. FPGA I/O Palettes
ni.com/training
B. FPGA I/O Palettes
The FPGA I/O palette includes the following functions for
configuring the I/O hardware.
• FPGA I/O Node—Reads or writes data from or to the FPGA
I/O.
• FPGA I/O Constant—Specifies an FPGA I/O item on the block
diagram.
• FPGA I/O Method Node—Invokes an I/O method for a specific
channel or C Series module.
• FPGA I/O Property Node—Reads or sets property attributes
of a specific channel or C Series module.
ni.com/training
C. I/O Types
ni.com/training
C. I/O Types
There are three basic FPGA I/O types in LabVIEW FPGA hardware: digital
lines, digital ports, and analog I/O. Digital lines are basic digital I/O. Digital
lines are bi-directional on all R Series devices and some CompactRIO
modules. Refer to the documentation for your specific device for more
information about digital enable and digital data functionality.
The Digital Port is a group of digital lines. The ports use a data type that is
dependent on the target. Ports for most I/O will be a group of 8 bits, but others
can be 16, or 32 bits. One bit is used for each line. The read and write
functions take data form all lines in a given port.
The analog input node reads data from the specified line. The analog output
node writes data to a given line. The values from the I/O lines are binary
values. The binary value is based on the resolution of the device. The device
resolution is divided into discrete values based on the range of the device. All
I/O values must be converted from a nominal value to a matching binary value
or vice versa to be correctly interpreted by the FPGA device.
ni.com/training
Creating Counters from Digital I/O
Minimum input pulse width detectable depends on loop period
ni.com/training
The FPGA devices do not have built-in counter hardware. All counters
must be programmed into the FPGA itself. The count register can be
32, 16, or 8 bits, depending on the type of integer selected for the
counter indicator. The loop period also determines the minimum
detectable pulse width. The example above has the following
specifications:
− About 10 ticks per iteration
− 250 ns to guarantee a high or low read
− 500 ns period = 2 MHz signals.
It can read a signal at a maximum of 2 MHz. It is important to
benchmark your counter before using it in a final application. Refer to
Toolkits and Modules»FPGA»Compact RIO/R Series» FPGA
Fundamentals»Counters in the NI Example Finder for related
examples.
ni.com/training
FPGA Mathematical Limitations
ni.com/training
When using an FPGA you cannot use the normal floating-
point numerical data types. Because the FPGA requires
fixed gates to be created for its logical pathways it cannot
handle data with floating mantissa and exponent data. If
you need to perform floating-point analysis it is typically
simplest to offload those calculations to the host for
processing.
However, not all calculations can or should be offloaded to
the host. Therefore if you wish to perform calculations with
the FPGA VI then all of those calculations will have to be
done with Integer Math or Fixed-Point Math.
ni.com/training
D. Integer Math
ni.com/training
D. Integer Math
Data returned from I/O channels is in binary
representation and must be handled with integer math.
As a result, some functions, such as divide, are not
included on the FPGA palette.
ni.com/training
Scaling Data in LabVIEW FPGA
For variable scaling, you can determine and set the scaling factor and
bit shift from the host application
ni.com/training
There are some ways to manipulate integer math functions
so that you can create ―floating-point‖ operations. The most
common techniques use the Scale By Power of 2 function
which essentially multiplies or divides by any power of 2.
This figure above shows an example of scaling data in
LabVIEW FPGA. We want to be able to scale the data by
.70. To get this scaling very close we multiply the analog
input by a scaling factor of 11500 then divide it by 16384
(use the Scale by the Power of 2 function to the –14th
power).
Additionally, you can divide numbers using the quotient and
remainder function, however, this can use many slices when
implemented.
ni.com/training
E. Converting Binary Representations
ni.com/training
E. Converting Binary Representations
When you configure the FPGA I/O Node to read an
analog input, the FPGA I/O Node initiates a conversion,
waits for the result, and returns the binary, uncalibrated
representation of the voltage as a signed integer. The
equation that converts the binary representation to a
physical quantity depends on the FPGA target and
transducer.
ni.com/training
E. Converting Binary Representations (cont.)
ni.com/training
Conversion to Binary Representation is hardware
dependent. Each hardware target has its own specific
voltage range, analog to digital converter precision,
offset and autozero values. By looking at the Help
documentation for the device that you are using you can
find these hardware-specific values and use the values
for conversion of the binary data on the host or by using
fixed-point math on the FPGA target.
ni.com/training
Demonstration
Devices.
ni.com/training
Open Example finder and Search Descriptions for 7831R.
Open the Examples Analog Input – R Series.lvproj and
Analog Output – R Series.lvproj. Point out how the
conversion factors are applied to the binary data on the host
side of the application.
For CompactRIO Targets show how the use of Binary to
Nominal.vi and Nominal to Binary.vi are used to take into
account the module specific properties. Search Keywords
for CompactRIO and open up the Analog Input –
cRIO.lvproj and Analog Output –cRIO.lvproj. Open the
Host VIs and show how the conversion VIs work. Feel free
to open the VIs to show that all the scaling information is in
those VIs and how the VIs ease the conversion process.
ni.com/training
F. Fixed-Point Math
ni.com/training
F. Fixed-Point Math
The fixed-point data type provides some of the flexibility of
the floating-point data type while maintaining the size and
speed advantages of integer arithmetic. By default, each
operation on the fixed-point data type generates a fixed-
point result that is large enough to hold all possible output
values specified by the input types.
Note FIFOs, memory, FPGA Math & Analysis VIs,
and some functions do not support the fixed-
point data type.
Caution If you wire a fixed-point number to an integer,
you might lose significant fractional bits.
ni.com/training
Setting the Desired Range
ni.com/training
Use the Data Type options on the Properties dialog box to
increase or decrease the resources a function uses. Right-click a
numeric constant, control, indicator, or function that accepts
fixed-point data and select Properties from the shortcut menu to
display the Properties dialog box. When you set the range on
inputs, the FPGA Module propagates the range throughout the
block diagram. The propagation reduces resources when possible.
The FPGA Module does not propagate through subVIs, so
coercion dots appear on the inputs of subVIs if the desired range
is different than the range being propagated.
Note If you set the Desired Range in places other than
the inputs, the VI might require additional
hardware resources.
ni.com/training
Selecting an Overflow and Quantization Mode
ni.com/training
Functions that support the fixed-point data type include modes to handle the overflow
and quantization. Use the Properties dialog box for the function to select the overflow
and quantization modes. Right-click a function and select Properties from the
shortcut menu to display the Properties dialog box.
The overflow modes affect the logic generated within the FPGA as follows:
Saturate—Requires additional hardware resources to determine if the input value is
within the desired range of the output type. Saturate is the default overflow mode. If
you specify a desired range other than the default minimum and maximum, the
Saturate mode performs a full comparison between the desired range and input value,
which might require additional clock cycles to complete. If you do not specify a
desired range, the Saturate mode checks all bits above the most significant bit of the
output type to ensure the output did not overflow.
Wrap—Does not require additional hardware resources.
Each of the quantization modes affect the logic generated within the FPGA as
follows:
Truncate—Removes fractional bit and therefore does not require any additional
hardware resources. However, this mode produces the largest mean error for most
data streams. This mode is the default for integer operations.
Round-Half-Up (Asymmetric)—Adds the least significant bit and therefore requires
an adder that is the width of the output type.
ni.com/training
Quiz
ni.com/training
Quiz
ni.com/training
Quiz
ni.com/training
1.False
FPGA I/O Nodes give access to all physical lines on the device.
2.Unsigned Integer, Fixed-Point, and Integer
Double and Complex Single are floating-point representations.
3.False
Although typically easier to convert on the host, you could convert the
binary value to a fixed-point number on the target by using some binary
math ‗tricks‘.
4.False
Binary values are dependent upon the specs for the hardware in use.
5.False
The same polymorphic mathematical functions can be used for all
numeric data types.
6.False
You must configure the appropriate range before using a fixed-point
number.
ni.com/training