Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

How Do I Convert A Raw Value To Fixed Point In FPGA?

Primary Software: LabVIEW Modules>>FPGA Module
Primary Software Version: 8.6.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I am using a function in FPGA that only outputs raw data. But my IO Node is configured for fixed point data. How can I convert my raw values to fixed point?

Solution:
You must know the exact configuration of the fixed point data your IO Node needs. In particular, you must know what the integer word length is and the total word length.

The first step is to convert your raw integer into an intermediate fixed point data type large enough for the entire integer and fractional data. For example, if you have a 16 bit integer value, you will need to convert this to a fixed point value with at least 16 bits of integer word length.

You must also ensure that the intermediate fixed point data type has enough fractional digits to contain the entire fractional portion of your data. For example, if your IO Node has a fixed point data type of 20 word bits and 5 integer word bits, you will need an intermediate fixed point data type that has at least 15 bits of fractional data.

Continuing the example where your raw data is 16 bits and the IO Node fixed point data type is 20 word bits with 5 integer word bits, you would need an intermediate fixed point data type of 31 bits (16 bits of raw data + 15 bits of fractional data.)



Once the data has been converted to the intermediate fixed point data type, you must shift the appropriate data bits into the fractional component of the intermediate fixed point data type. In the case of our above example, the 16 bit raw data must contain 5 bits of integer data and 11 bits of fractional data (16 bits – 5 integer word bits = 11 bits of fractional data.) Use the Scale By a Power of 2 VI to shift the fixed point integer data into the fractional portion of the data type (in our above example, the input would be -11.)

Finally, you must trim the intermediate fixed point data type to the correct IO Node data type size. In our continuing example, the final fixed point conversion should be 20 bits of word length and 5 bits of integer word length. This will effectively trim the excess integer bits above the sign bit (if present) and remove the excess fractional bits below the precision supported by the device.

For the example used throughout this knowledge base, the final block diagram my look something like this.



Related Links:
KnowlegeBase 4L5B754H: Switching Between Calibrated Fixed-Point and Raw Integer Modes for CompactRIO I/O
NI Developer Zone Community: Convert Sine Wave Generator Raw Output to Fixed Point

Attachments:





Report Date: 05/05/2009
Last Updated: 08/29/2009
Document ID: 4X4J3EMO

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit