« Close

Datasheets and User Guides

App Notes

Software & Driver

 

LJLog/Stream Scaling Equations

Overview

Scaling equations should be in the form "y=a", where "y" is the scaled output and "a" is the input voltage of the 1st row.  "b" through "p" would be the input voltage of the rest of the rows.  Everything after "//" is ignored, so use for comments.  Common examples:

y=c                           // scaled output will be the raw reading from the 3rd row
y=c+d                      // add the voltages from the 3rd and 4th row
y=c+273.15                 // deg C to deg K
y=100*c                     // EI-1034/LM34 voltage to deg F
y=55.56*c - 17.78       // EI-1034/LM34 voltage to deg C
y=55.56*(c-32)           // EI-1034/LM34 voltage to deg C
y=55.56*c + 255.37    // EI-1034/LM34 voltage to Kelvin
y=100*c                                   // EI-1022/LM335 voltage to Kelvin
y=100*c – 273.15                     // EI-1022/LM335 voltage to deg C
y=((100*c)-273.15)*1.8 + 32    // EI-1022/LM335 voltage to deg F
y=c^2                       // c*c or c-squared
y=c-273.15                // deg K to deg C
y=((c-273.15)*9/5)+32    // deg K to deg F
y=(1.8*c)-459.67       // deg K to deg F rearranged

Note that it does not matter which row an equation is in.  The equation "y=100*c" will can be in any row, and always will scale the raw voltage from the 3rd row.

 

Thermocouples

There is special support for the thermocouple function from the UD driver.  The form is "TCVoltsToTemp[type:volts:CJtempK]".  Type should be B, E, J, K, N, R, S, or T (must be capital).  Volts is the thermocouple voltage, and can be a formula.  CJtempK is the cold junction temperature in degrees K, and can be a formula.

y=TCVoltsToTemp[K:c:298.15]        // Type K, t/c voltage from 3rd row, CJ temp is fixed at 25 deg C
y=TCVoltsToTemp[K:c:a]                // CJ temp from 1st row, where raw value is deg K
y=TCVoltsToTemp[K:c:55.56*a+255.37]    // CJ temp from 1st row, where raw value is EI-1034/LM34
y=TCVoltsToTemp[K:c-0.0002:d]     // Subtracting 200uV offset from t/c voltage 
y=2*TCVoltsToTemp[K:c:d] - 2.5    // Apply slope & offset to t/c value.

The LJM driver (T-series devices) has a similar function to handle thermocouple math, but it is not supported by LJLogM or LJStreamM.  Rather you must use command-response mode only (LJLogM not LJStreamM), use the AIN-EF Thermocouple Feature to do the math, and read the temperature from AIN#_EF_READ_A.

 

Digital Inputs, Counters, and Timers

There are special channel numbers (U3, U6, UE9) that allow digital inputs, counters, and timers, to be acquired with analog input functions, and thus acquired with LJLog/LJStream.  A common application is to use "Config Defaults" in LJControlPanel to cause timers and counters to be enabled and configured at power-up, and then use the special channels to read them.

Channel 193 returns a value where each bit corresponds to FIO0-EIO7.  If all 16 bits read high you get 65535.  If all 16 bits read low you get 0.  If FIO0 & FIO1 read high, and all others read low, that is b0000000000000011 which would appear as 3 in decimal.  Following are example formulas for a bit test.  Assume the 3rd row ("c") is acquiring +Ch=193 which is the FIO/EIO digital inputs.  These formulas test bits 2 (FIO2) and 9 (EIO1):

y=floor(c/2^2) - 2*floor(c/2^3)      // 1 if bit 2 is set and 0 if bit 2 is clear
y=floor(c/2^9) - 2*floor(c/2^10)    // 1 if bit 9 is set and 0 if bit 9 is clear

The "DIO" registers on T-series devices are similar in that each bit of the value corresponds to a bit of digital I/O.

 

Counter values and many timer values are 32 bits, so reads from them are split into 2 channels where the upper 16 bits are always read using the capture channel 224.  For example, to read Counter0 you could set +Ch=210 in the 3rd row ("c") and set +Ch=224 in the 4th row ("d"), and then use the following scaling equation in any row:

y=c + d*65536    // combine LSW and MSW of unsigned 32-bit integer into a single value

If the Counter0 value above is from a 360 ppr encoder, and you want the value to roll every 360 counts so you get a sawtooth, you could use the following:

y=(c+(d*65536)) - 1440*floor((c+(d*65536))/1440)

Note that a timer in quadrature mode returns a signed 32 bit value (2's complement).  There is a special function SignedLSWMSW[lsw:msw] provided to handle this.  Assume Timer0/Timer1 are configured for quadrature and in LJLog/Stream you set +Ch=200 in the 3rd row and +Ch=224 in the 4th row, the scaling equation to get the combined signed 32-bit value is:

y=SignedLSWMSW[c:d]

With T-series devices, the above only applies to stream mode in LJStreamM.  In LJLogM reading DIO0_EF_READ_A (for example) will return all 32 bits, but in LJStreamM you must use the capture register STREAM_DATA_CAPTURE_16 to get the upper 16-bits.

 

Thermistors & RTDs

See the LJTick-Resistance Datasheet for more information about measuring resistance, and see the Temperature Sensors App Note to decide if their might be a better type of sensor to measure temperature for your application.

The equation to convert the LJTR voltage reading to resistance is:

y = (2.5-c)*1000/c    // LJTR-1k using the 2.5V reference

 

For a PT100 RTD we expect that it will be 100.0 ohms at 0 degC and the resistance will change about 0.385 ohms/degC (most common coefficient), so R = 100 + TempC * 0.385, or TempC = (R-100) / 0.385.  So in LJLog to convert from volts to degrees C:

y = ( (2.5-c)*1000/c) -100) / 0.385  //  LJTick-Resistance-1k, PT100 volts to degrees C

 

For a thermistor, to convert resistance to temperature we use the Steinhart-Hart equation TempK = 1 / ( A + B*ln(R/R25) + C*ln(R/R25)^2 + D*ln(R/R25)^3 ).  "R" is the actual thermistor resistance and "R25" is the nominal thermistor resistance at 25 degrees C.  The coefficients A, B, C, and D are needed, so for the NTCLE100E3103 10k thermistor (for example) the datasheet tells us A=0.003354016, B=0.000256985, C=0.000002620, and D=0.00000006383.  The following assume we are using the LJTR-10k so Rfixed=10000.

If R/R25 = 1, the result of the above should be 25.0 deg C, which is 298.15 deg K, so we can test the equation in LJLog using:

y = 1 / (  0.003354016 + 0.000256985*ln(1) + 0.000002620*ln(1)^2 + 0.00000006383*ln(1)^3 )

Seeing that it returns 298.15K, we move on to the actual equation to convert the resistance to degrees K:

y = 1 / (  0.003354016 + 0.000256985*ln(((2.5-c)*10000/c)/10000) + 0.000002620*ln(((2.5-c)*10000/c)/10000)^2 + 0.00000006383*ln(((2.5-c)*10000/c)/10000)^3 )

Now a quick offset to convert K to C:

y = (1 / (  0.003354016 + 0.000256985*ln(((2.5-c)*10000/c)/10000) + 0.000002620*ln(((2.5-c)*10000/c)/10000)^2 + 0.00000006383*ln(((2.5-c)*10000/c)/10000)^3 )) - 273.15

Or a slope and offset to convert K to F:

y = 1.8*(1 / (  0.003354016 + 0.000256985*ln(((2.5-c)*10000/c)/10000) + 0.000002620*ln(((2.5-c)*10000/c)/10000)^2 + 0.00000006383*ln(((2.5-c)*10000/c)/10000)^3 )) - 459.67

It is tough to edit these big equations in the little box in LJLog.  Rather we suggest using some sort of text editor to type them up and edit them, and then copy/paste into LJLog.

A screenshot from LJLogM is attached showing thermistor scaling.  The first 6 rows are:

0:  Voltage reading from AIN0 scaled to resistance in ohms.
1:  Thermistor equation with fixed R/Rref=1 such that it always returns 298.15K (25C).
2:  Full voltage to temperature equation in K.
3:  Full voltage to temperature equation in C.
4:  Full voltage to temperature equation in F.
5:  AIN-EF read to directly get thermistor temperature from the T7.

The equations in rows 0/2/3/4 of the screenshot are all using the voltage "a", so the raw reading from the 1st row.  The read in the 6th row is using the AIN-EF feature of the T7 where it has been configured to do the math in hardware.

 

Internally in the LJLog/LJStream code, the scaling equations use the "Formula Node" capability of LabVIEW, so for more advanced functionality see this list of functions and list of operators from NI.  Note that LJLog/LJStream are using floating point numbers so integer related functions and operators (e.g. mod(), rem(), %, &) will not work and will result in the output stuck at 0.0 (which indicates a formula error).  We have also found that any function from the linked page that takes 2 inputs does not work.  A simple way to test any function of interest is to simply use constants ... for example put in y=log(2) will result in Scaled=0.301030.

 

8 comments

Hi,

   When I try scaling equation in UD mode, it workes. But in Stream mode, it doesn't work. Any help please. Thank you .

Why is there a 2* for the last example function for thermocouple conversion?

I changed the comment.  I think that line is just trying to show that you can do normal scaling math around the thermocouple function.

Do I understand correctly that all of the functions and operators described in

"Internally in the LJLog/LJStream code, the scaling equations use the "Formula Node" capability of LabVIEW, so for more advanced functionality see this list of functions and list of operators from NI."

are available for use in LJLogUD (v1.18)?

If not, then can you please provide information on the supported subset.

Best regards,

Joseph

Following up on my earlier comment regarding scaling equations:

Using LJLogUD (v1.18), U6-Pro and Windows XP I have determined that many of the functions on the http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/formula_node_... page operate correctly in this environment with the exception of functions requiring more than one argument.

For example, "y=abs(a)" and "y=log(b+0.001)" return the expected numerical results.

However, "y=max(a,b)", "y=max(2,3)" and "y=pow(2,8)" all return zero.

I have checked replacing the comma "," with colon ":" and obtained the same zero result. I have also checked replacing parentheses "()" with square brackets "[]" and obtained the same zero result. I have also checked both of these simultaneously and obtained the same zero result.

My immediate interest is in using the max(x,y) function in a scaling equation.

Best regards,

Joseph

We don't exclude anything, as we just pass the formula to the LabVIEW Formula Node, but I agree that LabVIEW does not seem to support everything in the list.  Perhaps because the list linked above is for LabVIEW 2011, but we are currently compiling with LabVIEW 7.1?  Your method of testing with constants, such as trying y=max(2,3), is a good way to quickly test.  I find that none of the functions with 2 arguments work, and find that binary functions do not work.

Thanks for the confirmation - at least this is one fewer reason to question my insanity. ;)

Is there a plan for a new release that is compiled against the newer LabView library?

Joseph

No plans.  We keep our LabVIEW code in older versions so it is compatible with those and everything newer.

My suspicion is that it would not make a difference.  My guess is that 2 parameter functions, like the binary functions, are not supported by the type of formula functions we are using, and anyone could confirm that by opening the source (included in the LabVIEW_LJUD archive) in a newer version of LabVIEW and testing it with y=max(2,3).

Consider using DAQFactory if you want something more flexible.