What Are Custom Scales and How Do I Use Them?

Updated Jun 14, 2018

Reported In

Driver

  • NI-DAQmx

Issue Details

I am using a device that measures signal values according to a defined scale. How can I use an NI-DAQmx Custom Scale to work directly with the scaled units of my device?

Solution

NI-DAQmx includes built-in support for many of the most common transducers, sensors, and actuators. However, if NI-DAQmx does not explicitly support your transducer or actuator, you can create an NI-DAQmx Custom Scale that specifies a conversion from the pre-scaled units measured by a channel to the scaled units associated with the sensor. Using a custom scale does not modify the physical measurement; only the way the data is interpreted. 

Pre-scaled Versus Scaled Units 
Pre-scaled refers to values expressed in the unit of the channel prior to the custom scale being applied. Usually, pre-scaled units are volts or amps since most channels will natively measure or generate signals of this kind. However, it is possible to associate a scale with a channel that contains a transducer explicitly supported by NI-DAQmx. In this case, the pre-scaled units are those used by the supported transducer channel. For example, if you associate a scale with an analog input resistance channel, the pre-scaled units would be ohms and the scale would specify how to convert from ohms to the desired scaled units. 

Scaled refers to values expressed in the final unit after NI-DAQmx applies the custom scale. You are able to define scaled units however you see fit for your application. For example, if you assign a linear-position-to-voltage scale on a voltage output channel, the pre-scaled samples are in volts while the scaled samples could be specified in meters. 

NI-DAQmx Custom Scale Types
NI-DAQmx provides four scale types:
  • Linear
    The linear custom scale type uses the equation y = m * x + b, where x is a pre-scaled value, and y is a scaled value. The equation is identical for input and output.

  • Map Ranges
    The map ranges custom scale type scales values proportionally from a range of pre-scaled values to a range of scaled values.

  • Polynomial
    The polynomial custom scale type uses an nth order polynomial equation. NI-DAQmx requires both a polynomial to convert pre-scaled values to scaled values (forward) and a polynomial to convert scaled values to pre-scaled values (reverse). If you only know one set of coefficients, use the DAQmx Compute Reverse Polynomial Coefficients VI to generate the other set.

  • Table
    The table custom scale type maps pre-scaled values to their corresponding scaled values. NI-DAQmx applies linear interpolation to values that fall between the values in the table. Read operations will clip samples that are outside the maximum and minimum scaled values found in the table. Write operations generate errors for samples that are outside the minimum and maximum scaled values found in the table.


Using NI-DAQmx Custom Scales 
NI-DAQmx Custom Scales can be created and applied in Measurement & Automation Explorer (MAX), the DAQ Assistant, or programmatically in LabVIEW or LabWindows™/CVI™. In LabVIEW, custom scales created in NI MAX can be applied in two ways:
 
  • DAQmx Create Virtual Channel
    The DAQmx Create Virtual Channel VI may have a terminal where custom scale names can be provided. This VI is polymorphic, so whether this terminal is present or not depends on the channel type. If the terminal is not present, custom scales are not applicable to the channel type. If a custom scale is used, the Units must be specified as From Custom Scale.
  • DAQmx Channel Property Node
    DAQmx Channel Property Nodes may also be used to implement a custom scale. As with DAQmx Create Virtual Channel, units must be specified as From Custom Scale

Applying custom scales in LabWindows™/CVI™ is very similar. To apply a custom scale while creating a channel, specify the Units argument as From Custom Scale and specify your custom scale namein the Custom Scale Name argument. To apply a custom scale with properties, use DAQmx GetChanAttribute to set the Custom Scale Name property to your custom scale name and to set the Units property to From Custom Scale.

Custom scales can also be created and applied programmatically.

Custom scales can be applied to both input and output channels:
  • Input channels
    The scale takes pre-scaled analog signal values and converts them to the scaled units specified by the custom scale. For example, a scale could convert a voltage to a linear position. When you read samples from a channel associated with a scale, the samples are in scaled units. 
     
  • Output channels
    The scale takes the specified unit values as an input and outputs a corresponding analog signal value to write to the output channel. For example, a scale could convert a linear position to a voltage. When you write samples to a channel associated with a scale, the samples are in scaled units.
You can also use scales to calibrate samples read or written so that the final scaled units are identical to the pre-scaled units of the channel. After a scale is assigned to a channel, the scale applies to all attributes normally expressed in the pre-scaled units of the channel. This includes the maximum and minimum values assigned to the channel. For example, if a custom scale, which converts volts to meters, is assigned to a voltage channel, the channels minimum and maximum attributes are expressed in meters. 

Example - Converting Volts to Revolutions/Minute
Imagine that you have connected an analog output voltage channel to a motor whose speed is proportional to the generated voltage, and you want to create a scale that specifies this conversion. The pre-scaled units in this case would be volts and the scaled units could be revolutions/minute. You would then specify the equation, table, or map that converts from volts to revolution/minute. After you have created this scale, you would associate the scale with an analog output voltage channel. Rather than having to convert between volts and revolutions/minute manually or with additional code, you can simply write the samples in units of revolutions/minute directly to the channel associated with the scale and NI-DAQmx automatically performs the specified conversions. Scales can simplify your code and improve the usability of your application.
 

Additional Information

Traditional NI-DAQ includes linear, polynomial, and table scaling in the form of Traditional NI-DAQ Custom Scales. These custom scales operate similarly to the NI-DAQmx Custom Scales described in this article.

Avoid using string constants to wire in a scale from NI MAX to DAQmx Create Virtual Channel. Instead, right-click the terminal and Create >> Constant so that you can select the available scales from the drop-down menu that appears.

WAS THIS ARTICLE HELPFUL?

Not Helpful