Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Reading DO voltage

pulse u3-lv read write io

  • Please log in to reply
23 replies to this topic

#1 DSpen

DSpen
  • Members
  • 12 posts

Posted 15 February 2015 - 05:36 PM

Hello, sorry if this has been posted before, I tried searching and reading through, but couldn't see anything clear enough for me.

I'm used to doing more high level programming in python, very little in low level controls.

 

I'm using a LJ U3-LV, and I have a pulse detector sending a DO that I'm  trying to read it through FIO6

 

I was having difficulty in understanding the user guides for the device (many terms I am unfamiliar with). How would I go about reading voltage being sent to FIO6?

 

Once I can get a stream of the voltage readings, I'll simply be plotting it out on a graph.

 

Thank you in advance, and sorry if this seems like a basic question.



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 February 2015 - 01:21 PM

What range of pulse rates (hz) do you expect?

 

What is the max/min high time of your signal?  And the max/min low time of your signal?

 

Does your sensor provide a driven output (what voltages?) or open-collector?

 

http://labjack.com/s...s-guide/2.8.1.1

http://labjack.com/s...s-guide/2.8.1.2

 

Do you have access to a Windows computer?  It will be easiest for us to have you do initial testing with the test panel in LJControlPanel.



#3 DSpen

DSpen
  • Members
  • 12 posts

Posted 10 March 2015 - 01:33 PM

Sorry for the late response

 

The pulse train is to synchronize with a heart beat, so approx 2hz (120bpm). And the Pulse width can be varied through a onboard potentiometer.

 

high at .25s, low for .5s (at 120bpm) - again can be varied

 

My sensor should provide ~ 0.25s of a 4.5v signal when a beat occurs, and provide 0v otherwise.

 

I run on windows, and can provide screenshots/details as needed.



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 March 2015 - 07:52 AM

So you want to view the waveform?  Try reading the signal as an analog input first.  It will rail at the normal low-voltage analog input rail of ~2.4V, but otherwise you will see the waveform.  So connect the positive to FIO6 (which will be used as AIN6 in this case) and the negative to GND.

 

If you have a 3 Hz max signal that you want to view on the screen, you could use command-response mode or stream mode:

 

http://labjack.com/s...3/users-guide/3

 

With command-response mode, you could make a loop in Python that is software timed to execute every 10ms, and each loop you read FIO6/AIN6.  Go here to get started with Python and the U3:

 

http://labjack.com/s...t/labjackpython

 

You could use the following call in your loop to get the reading each time:

 

d.getAIN(6)

 

http://labjack.com/s...ython/low-level

 

 

 

As a quick way to initially view your waveform, try LJStreamUD, which uses stream mode:

 

http://labjack.com/s...t/ud/ljstreamud

 

It defaults to streaming 4 channels at 500 scans/second.  Just set +Ch=6 in the one of the first 4 rows, then click Start Stream.  Perhaps change Graph History to 5000 so you will be looking at 10 seconds of data on the chart.

 

 

 

Note that if you want to count or time the pulses, you would probably use a digital input configured as a counter or timer, rather than reading as an analog input:

 

https://forums.labja...?showtopic=1105

 

http://labjack.com/s...users-guide/2.9



#5 DSpen

DSpen
  • Members
  • 12 posts

Posted 15 March 2015 - 06:30 PM

Thank you for the quick response!

 

I'm having trouble with picking up the correct voltages from the pulse sensor it seems. With my board connected, looping through d.getAIN(6) is getting a constant 2.4423988165v reading. (showing up in LJStreamUD at this values too, which is good)

 

Is this value supposed to remain constant until I setup a scan? Or does this seem to be something to do with my pulse sensor?

 

Thank you for your assistance!



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 March 2015 - 07:41 AM

With your signal connected to FIO6, at the same time use a DMM to measure from FIO6 to GND and see if it agrees that the signal is not going low.

 

Remove your signal from AIN6, and instead use a small wire to jumper AIN6 to GND or VS.  You should see about 0V when jumpered to GND and about 2.4V when jumpered to VS (VS is actually 5V but the max of a low voltage U3 analog input on the normal range is about 2.4V).

 

Perhaps post a link to technical details about the signal provided by your sensor.



#7 DSpen

DSpen
  • Members
  • 12 posts

Posted 18 March 2015 - 10:32 PM

To give the wiring I'm doing (which I think is correct)

pulse VCC is hooked to VS

Pulse DO to FIO6

and pulse AO to FIO7

 

with VCC and FIO6 connected I'm seeing 0v between them

checking FIO6 to GND with that connection, I see just under 4v

 

with an jumper between ain6 and GND: 0v (4.5 to VS)

with jumper between ain6 and VS: 0v (0v to gnd)

 

Here's a page on the board i'm using:

http://embedded-lab.com/blog/?p=7336

 

If anything is unclear, let me know (Had to go out and buy a DMM, kinda new to working at this)

 

Also does it matter which VS/GND I use? or will any work as long as it's connected to my board?



#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 March 2015 - 07:38 AM

You also have Pulse-GND to U3-GND, right?

 

They also mention that the ENABLE line must be pulled high.  Perhaps this is supposed to be jumpered to VCC?

 

 

Looking at the signals expected from AO and DO:

 

http://embedded-lab.com/blog/?p=7400

 

... a DMM will probably be too slow.  You will need an oscilloscope to see these.  You would put the scope from AO to GND to see the AO signal, or DO to GND to see the DO signal.



#9 DSpen

DSpen
  • Members
  • 12 posts

Posted 25 March 2015 - 09:06 PM

Wow I feel silly.

 

Did not have the GND hooked up (I am very amateur at this). Everything is looking perfect now.

 

Thank you very much for you assistance!



#10 DSpen

DSpen
  • Members
  • 12 posts

Posted 10 April 2015 - 07:39 PM

One last newbie question.

 

I want to verify the DAC voltages i'm setting. Can I read these via their associated registry, or through the feedback command?



#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 April 2015 - 09:48 AM

You'll need to read the DACs voltages via their Modbus registers which are addresses 5000 (DAC0) and 5002 (DAC1). Reading the current DAC voltages is not supported in Feedback, just setting them.



#12 DSpen

DSpen
  • Members
  • 12 posts

Posted 21 April 2015 - 02:12 AM

Would I be correct in reading DAC0 as

 

DAC0=device.readRegister(5000)

 

and writing as 

 

DAC0_VALUE = d.voltageToDACBITS(voltage, dacNumber=0,is16Bits=False)

d.getFeedback(u3.DAC0_8(DAC0_VALUE))

 

If so, I'm getting a response as 5.69746553083e-05

 

Does this need to convert to volts, or am I doing this wrong?



#13 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 21 April 2015 - 01:50 PM

Your readRegister call looks fine. When using Feedback to set the DAC lines they need to be the converted binary value of the voltage. Your d.voltageToDACBITS call has the wrong name, so if you are not error checking it will not run. I just tested, and this will set DAC0 to 2.2 and will read out about 2.2 (using the 16-bit DAC IOType):

import u3

d=u3.U3()
d.getCalibrationData()

volt = 2.2
binary = d.voltageToDACBits(volt, dacNumber = 0, is16Bits = True)
d.getFeedback(u3.DAC0_16(binary))

print d.readRegister(5000)

 You could alternatively use Modbus to set DAC0 with the voltage value:

volt = 2.2
d.writeRegister(5000, volt)


#14 DSpen

DSpen
  • Members
  • 12 posts

Posted 09 May 2015 - 06:31 PM

I'm back again with another question.

 

I have my application running, but not as quickly as required.

 

Primarily, I need to set DAC0 and DAC1 voltages each to 4v then 0v following each other between heart pulses i'm reading from AIN6

I'm able to do this all successfully, however I'm using time.time() to calculate when I should be setting the voltages. This is giving me a severe overhead making my dac changes occur later and later

Pseudo of what i'm doing is:

 

//if time for sequence 1 has occured/passed, and we've hit a falling edge, and were at first stage:

if time.time()>=sequence1time and ain6<2 and stage=1

    d.writeregister(5000,4)

    stage=2

if time.time()>=sequence2time and stage=2

    d.writeregister(5000,0)

 

I have another thread reading DAC and AIN and plotting them.

 

 

Scan won't work for me as I need to do this real time, so waiting for a packet with multiple readings won't do.

 

Secondarily i'm using MatLab to plot my data, but I should be able to get it to refresh at 100fps while still accurately reading/setting voltages.

 

I figure i'll need to use the labjacks counter/timers for this, but i'm not sure how to set them up for what I need.



#15 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 May 2015 - 10:46 AM

For better time precision/resolution on Windows you will want to use time.clock(). For Linux and Mac OS X you will want to use time.time() instead.

 

How are you calculating sequence1time and sequence2time? To help prevent your DACs from happening later and later (drifting) make sure you don't calculate your next sequence time based on time.time/clock or have your calculation account for overhead. For example, instead of:

 

sequenceXtime = time.time() +  timeBetweenSequenceX

 

try:

 

sequenceXtime = sequenceXtime +  timeBetweenSequenceX

 

Keep in mind the command/response speeds for the U3 and its overhead (when using DACs only, refer to the # AIN = 0 row).

 

If this doesn't help, please provide more information on the timing needed? Also, I'm not sure how timer/counters might help further, but the different modes are documented here:

 

http://labjack.com/s...ers-guide/2.9.1



#16 DSpen

DSpen
  • Members
  • 12 posts

Posted 13 May 2015 - 03:57 PM

Here's my timing setup (not showing declaration of some global vars):

 

 

//If rising, and at stage 0, and we are on a new rise:

if (ain6>2) and SequenceStage==0 and rise==True:

   rise=False

   oldpulse=curpulsetime

   curpulsetime = time.clock()

   difference = curpulsetime-oldpulse

 

   //if we've gathered proper difference

   if not firstpulse

      Sequence1time= curepulsetime +(difference/3)

      Sequence2time= Sequence1time +(difference/10)

      Sequence3time= Sequence2time+((difference*2)/3)

      Sequence4time= Sequence3time+(difference/10)

      SequenceStage=1

 

   //reset rise, don't change stages if we are in same pulse

   if ain6<2 and rise=False:

      rise=True

 

   if time.clock()>=Sequence1time and ain6<2 and SequenceStage=1

      d.writeregister(5000,4)

      SequenceStage=2

   if time.clock()>=Sequence2time and SequenceStage=2

      d.writeregister(5000,0)

      SequenceStage=3

 

etc..

 

 

These pulses to DAC are drifting apart with this current setup, and have longer than intended duration as well.



#17 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 May 2015 - 04:54 PM

Make sure this line:

 

Sequence1time= curepulsetime +(difference/3)

 

is this in your code:

 

Sequence1time= curpulsetime +(difference/3)

 

Misspelling variables (curpulsetime) in Python can cause some unintended problems during runtime.



#18 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 May 2015 - 06:50 PM

Seems like "difference" will have a different value (probably the drifting and longer durations your are seeing) when calculated each time since it uses time.clock only. If you want sequence times to have the "same" durations (not sure about ain6 and timing delays it can cause, and USB overhead differ per call), perhaps something like this instead:

//Using a constant difference value (WANTED_DIFFERENCE) to
//keep the sequence times the same.

//If rising, and at stage 0, and we are on a new rise:
if (ain6>2) and SequenceStage==0 and rise==True:
    rise=False
    difference = WANTED_DIFFERENCE
    curpulsetime = time.clock()
    
    //...

or

//Using a constant time interval value for the next set of sequences
//(NEXT_PULSE_TIME) and constant difference value (WANTED_DIFFERENCE)
//to keep the sequence times the same.

//Initialization
curpulsetime = None

//...

//If rising, and at stage 0, and we are on a new rise:
if (ain6>2) and SequenceStage==0 and rise==True:
    rise=False
    difference = WANTED_DIFFERENCE
    if curpulsetime is None:
        curpulsetime = time.clock() #Initial time
    else:
        curpulsetime = curpulsetime + NEXT_PULSE_TIME #all other times
    
    //...

Hopefully these will help you figure out a solution for you system.



#19 DSpen

DSpen
  • Members
  • 12 posts

Posted 13 May 2015 - 09:08 PM

I found my math problem....

 

Sequence3Time = Sequence2time +((difference*2)/3)

should actually have been

Sequence3Time = CurPulseTime +((difference*2)/3)

 

everything is looking perfect now. It's the small things that make me feel stupid XD



#20 DSpen

DSpen
  • Members
  • 12 posts

Posted 19 May 2015 - 01:48 AM

My system is looking successful now, but still one more problem.

 

I'm expecting my easy pulse to provide a 4.95v signal from DO to FIO6, and 4.0v signal from AO to FIO7

 

However they seem to cap out at 2.44v. 

 

seen in: http://labjack.com/s...users-guide/2.6the basic range is 0-2.44v. 

 

Am I able to change the range to allow the readings of voltages I'm expecting? http://labjack.com/s...ers-guide/2.6.1shows that I may need to apply a jumper somewhere. (i'm using u3-lv if this changes anything)



#21 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 May 2015 - 10:47 AM

For the U3-LV, the single-ended range is 0 to 2.44 V, and there is a special range of 0 to 3.6 V which you specify with negative channel 32 as described in section 2.6.1 of the User's Guide which includes a Python demonstration (note the jumper was just for reading the DAC0 value from FIO0/AIN0). So basically the max. voltage you can read is 3.6 V with a U3-LV. If using Modbus and you need to set the negative channels to 32, write 32 to addresses 3006 and 3007 (negative channels start at address 3000 and are 1 register u16) for FIO6 and FIO7.

 

Refer to section 2.6.3.6 in the User's Guide which discusses using a voltage divider for voltages beyond the U3's 0 to 2.44 (and 3.6) V range. Also, if possible you can scale your DAC pulses down to the U3 ranges.



#22 DSpen

DSpen
  • Members
  • 12 posts

Posted 19 May 2015 - 04:10 PM

What do you mean by scaling my DAC pulses to the u3 range? Are my DAC pulses out of the u3 range? I thought they were 0-4.95v

 

Also would using a voltage divider change the quality of the signal? I would like it as accurate as possible for good measurements



#23 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 May 2015 - 05:20 PM

To clarify, if possible set the the DAC output voltages (pulses) to 2.44/3.6 V or under so that they are in the U3's AIN voltage range. DACs can output 0-4.95 V but the AINs can only read 0-2.44/3.6 V.

 

Someone more hardware technical will respond to your second question soon.



#24 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 20 May 2015 - 08:01 AM

 

Also would using a voltage divider change the quality of the signal? I would like it as accurate as possible for good measurements

 

Perhaps.  You have to consider error due to the loading of the voltage divider, and also error due to the accuracy of the resistors in the voltage divider.

 

What exactly is the source of your 2 signals?





Also tagged with one or more of these keywords: pulse, u3-lv, read, write, io

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users