« Close

Datasheets and User Guides

App Notes

Software & Driver

 

4.3.3 - Analog Inputs

The IOTypes to retrieve a command/response analog input reading are:


LJ_ioGET_AIN       //Single-ended.  Negative channel is fixed as 31/199.
LJ_ioGET_AIN_DIFF  //Specify negative channel in x1.

The following are special channels, used with the get/put config IOTypes, to configure parameters that apply to all analog inputs:


LJ_chAIN_RESOLUTION     //QuickSample enabled if TRUE.
LJ_chAIN_SETTLING_TIME  //LongSettling enabled if TRUE.
LJ_chAIN_BINARY

Following is example pseudocode to read analog inputs:


//Execute the pin_configuration_reset IOType so that all
//pin assignments are in the factory default condition.
//The ePut function is used, which combines the add/go/get.  
ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);

//Configure FIO1, FIO2, and FIO6 as analog, all others as
//digital (see Section 4.3.2).  b01000110 = 0x46 = d70.
//The ePut function is used, which combines the add/go/get.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 70, 16);


//Now, an add/go/get block to execute multiple requests.

//Request a single-ended read from AIN2.
AddRequest (lngHandle, LJ_ioGET_AIN, 2, 0, 0, 0);

//Request a differential read of AIN1-AIN6.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 6, 0);

//Request a differential read of AIN1-Vref.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 30, 0);

//Request a single-ended read of AIN1.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0,199, 0);

//Request a read of AIN1 using the special 0-3.6 volt range.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 32, 0);

//Execute the requests.
GoOne (lngHandle);

//Since multiple requests were made with the same IOType
//and Channel, and only x1 was different, GetFirst/GetNext
//must be used to retrieve the results.  The simple
//GetResult function does not use the x1 parameter and
//thus there is no way to specify which result is desired.
//Rather than specifying the IOType and Channel of the
//result to be read, the GetFirst/GetNext functions retrieve
//the results in order.  Normally, GetFirst/GetNext are best
//used in a loop, but here they are simply called in succession.

//Retrieve AIN2 voltage.  GetFirstResult returns the IOType,
//Channel, Value, x1, and UserData from the first request.
//In this example we are just retrieving the results in order
//and Value is the only parameter we need.
GetFirstResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN1-AIN6 voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN1-Vref voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN1 voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN1 voltage (special 0-3.6 volt range).
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);

6 comments

I was confused by the 70 in the ioPUT_ANALOG_ENABLE_PORT call (the 2nd ePut() above) until I realized it was a decimal value.  Showing it as 0x46 either in the code or in the comments would have been helpful.

 

Added a little something to the comment to help clarify.

Hi, I'm working with LABJACK U3-HV on the platform of MATLAB, I would like to know what the GetResult command to a differential analog read. For example, on a simple reading for AIN0 the command is

[ljerror,dblValue] = ljudObj.GetResult(ljhandle,LabJack.LabJackUD.IO.GET_AIN,0,0)

See the 5th paragraph in Section 2.6.  We can't provide a calibration that works for all differential readings on the high-voltage analog inputs, so they will return binary values.

You can't just change GetResult.  The Get commands are reading the result of executing requests that you added used Add commands.  See Section 4.1 for a good overview of how the UD library works.

To get a differential reading, you need to use a function (eAIN) or iotype (LJ_ioGET_AIN_DIFF shown above) that allows you to set the negative channel.  You can see from Section 2.6.1 that a negative channel of 199 means single-ended.

So if you want to use AddRequest/GoOne/GetResult, then do an AddRequest with iotype LJ_ioGET_AIN_DIFF as shown above, then do Get Result with the same iotype.

The easiest way to get a single differential reading is with the easy-function eAIN.  See the easy function example for Matlab.

 

Thanks for the information, but i have problems again.

If i use the command eAIN get the wrong result.

I'm using:

                               [ljerror,dblVoltage]=ljudObj.eAIN(ljhandle,2,3,0,0,0,0,0);

                                valor=dblVoltage

with 3.5V on AIN2 and 1V on AIN3, and "valor" returns 36752

See the 5th paragraph in Section 2.6.  We can't provide a calibration that works for all differential readings on the high-voltage analog inputs, so they will return binary values.  You will have to do your own calibration and apply it in software.