U6-Pro analog inputs freeze after trying to output a voltage from the DAC while using a gainIndex other than 0

5 posts / 0 new
Last post
rwilbur's picture
U6-Pro analog inputs freeze after trying to output a voltage from the DAC while using a gainIndex other than 0

I am using a U6 Pro using Labjack Python. While using a gainIndex of 0 I have no issues reading from the analog inputs or outputting voltages from the DAC. As soon as I set the gainIndex to anything other than 0 I can read the analog values but as soon as I try to set a DAC voltage the inputs will only return 1 number. This number is always the same for AIN0 and AIN1 and never changes. I can only fix it by reinitializing the LabJack.

Has anyone else encountered anything like this?

LabJack Support
LabJack Support's picture
I am having a tough time

I am having a tough time coming up with anything that would cause what you are seeing.. Can you share your python code with us? You can send it to [email protected] if you would rather not post it on the forums.

rwilbur's picture
To make some commands a bit

To make some commands a bit easier I wrote a wrapper for everything. The LabJack initialization looks like this:

class LabJack:
    ## Constructor with settings for different numbers of channels, resolution, gain, settling, and if you are
    # using differential inputs
    # @param numChannels: number of analog inputs you are using
    # @param resolutionIndex: The resolution you are using
    # @param gainIndex: The gain you are using
    # @param settlingFactor: How long to wait to let the value settle when getting an analog reading
    # @param differential: If we are using analog inputs as differential inputs

    def __init__(self, numChannels=1, resolutionIndex=0, gainIndex=0,settlingFactor=0,differential=True):
            ## Labjack U6 objecct, this is from LabJack Python
            self.lj = u6.U6()
            ## Number of AIN channels we are using
            self.numChannels = numChannels
            ## Resolution index
            self.resolutionIndex = resolutionIndex
            ## How much gain are you using, 0=x1, 1=x10, 2=x100, 3=x1000
            self.gainIndex = gainIndex
            ## Settling factor for reading the values
            self.settlingFactor = settlingFactor
            ## Are we using the analog ins as differential inputs
            self.differential = differential

            self.lj.getCalibrationData()  # Get the stored calibration values for the labjack
            # Sets the directions of the inputs and outputs
            self.lj.getFeedback(u6.PortDirWrite(Direction=[0, 0, 0], WriteMask=[0, 0, 15]))
            ## Feedback arguments stores the commands that you send it as well the responses
            self.feedbackArguments = []
            for i in range(numChannels):
                self.feedbackArguments.append(u6.AIN24(i, resolutionIndex, gainIndex, settlingFactor, differential))

        except Exception as e:
            print("Unable to connect to the LabJack")

Getting the analog voltages looks like this:

## Gets a vector of all of the analog inputs. If you are looking for differential
# inputs then check the lowest number in the pair of analog inputs.
# (if using AIN0 and AIN1 as differential inputs, check AIN0)
# @return Vector of analog input values

def getAnalogVoltages(self):
    analogInValues = []
    results = self.lj.getFeedback(self.feedbackArguments)
    for j in range(self.numChannels):
        analogInValues.append(self.lj.binaryToCalibratedAnalogVoltage(self.gainIndex, results[1+j]))
    return analogInValues

Setting the outputs looks like this:

## Sets the DAC0 and DAC1 voltage
# @param DMvolt: Voltage difference between outputs (DAC1 is + terminal)
# @param CMvolt: Voltage common to the two outputs
def setDACDiffVoltage(self,DMvolt, CMvolt):
    if(CMvolt+abs(DMvolt/2) > 5):
        print("Error: DAC 5V maximum")
    elif (CMvolt < abs(DMvolt / 2)):
        print("Error: DAC 0V minimum")
    self.lj.getFeedback(self.lj.writeRegister(5000, -DMvolt / 2 + CMvolt),
                        self.lj.writeRegister(5002, DMvolt / 2 + CMvolt))

Calling the constructor via the python command line works, calling getAnalogVoltages works, and calling setDACDiffVoltage and then checking the output with getAnalogVoltages works with different values as long as the gainIndex for the constructor is set to 0, otherwise the analog input readings are always frozen at a certain value. If it wouldl help I can get the value that it freezes at.

LabJack Support
LabJack Support's picture
In setDACDiff, change this:

In setDACDiff, change this:

self.lj.getFeedback(self.lj.writeRegister(5000, -DMvolt / 2 + CMvolt),
                        self.lj.writeRegister(5002, DMvolt / 2 + CMvolt))

To this:

self.lj.writeRegister(5000, -DMvolt / 2 + CMvolt)
self.lj.writeRegister(5002, DMvolt / 2 + CMvolt)

writeRegsiter is a method that performs a Modbus command-response, and are setting the two DACs. The getFeedback call is not getting FeedbackCommand objects with what you are doing, but you are setting the DACs through writeRegister still.

Here are the gainIndexes and their corresponding voltage ranges:

0 = ±10 V
1 = ±1 V
2 = ±0.1 V
3 = ±0.01 V

So, for example, if you are reading from AIN0 or AIN0-AIN1 differential with gainIndex 1, and the voltage for that single-ended or differential reading is 3 V, the reading will be 1 V because of the gain and its maximum voltage. Perhaps that is what you are seeing with the "frozen" value, the maximum or minimum voltage for the configured gain?

If that is not the case, provide the numChannels, resolutionIndex, gainIndex, settlingFactor, and differential settings that can cause the "frozen" issue? What connections do you have on your U6? What is the "frozen" voltage reading and what is the expected voltage reading?

rwilbur's picture
Thank you for your help, when

Thank you for your help, when I originally was seeing that problem I had setDACDiff to what you just said there and I was still seeing the frozen values.

I tried to reproduce the issue with the frozen values I was seeing so I could tell you the values I was getting with different gains. I tried setting the gain to different values and set the differential voltage so that it would saturate the inputs but still never saw any frozen values. I don't believe saturation was the issue I was seeing because I could set both DACs to be the same value to get a differential output of 0V but the value I was reading in wouldn't change.

The connections that I had set up were the DAC 0 and 1 outputs going through an attenuator and then reading the output of that with AIN0 and AIN1. When the outputs were frozen I tried setting a very wide range of differential voltages as well as commanding DAC0 and DAC1 individually and saw no change at all until I reinitialized the LabJack. Since I could not reproduce the fozen values at all today I guess I will just wait until I maybe see them at some other point and make note of the cirumstances in which it happens.