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

Streaming AinX with period Digitial Outputs

Streaming DigitalOutput

  • Please log in to reply
9 replies to this topic

#1 GeorgSoerensen

GeorgSoerensen
  • Members
  • 8 posts

Posted 17 April 2014 - 02:15 AM

I am attempting to stream input from 4 Differential inputs (Ain0/1 Ain2/3 Ain4/5 Ain6/7)

and while the streaming is ongoing, periodically turn on and off a digital port.

 

I use

ADDRequest(LJID, put_config, channel.stream_wait_mode, streamwaitmode.none, 0, 0)

ADDRequest(LJID, ClearStreamChannels, 0, 0, 0, 0)

ADDRequest(LJID, add_stream_channel_diff, 0, 1, 1, 0)    '(0&1)

ADDRequest(LJID, add_stream_channel_diff, 2, 1, 3, 0)    '(2&3)

ADDRequest(LJID, add_stream_channel_diff, 4, 1, 5, 0)    '(4&5)

ADDRequest(LJID, add_stream_channel_diff, 6, 1, 7, 0)    '(6&7)

goone(LJID)

eget(LJID, Start_Stream, 0, dblvalue, 0)

 

to start the stream

 

then, I want to turn on my device and and read in the voltages (so I can see before and after)

 

I would like to turn on my voltages for a specific time so I tried

 

AddRequest(LJID, Put_Digital_Bit, Eio6, 1, 0, 0)                ' turn on

AddRequest(LJID, Put_Wait, Eio6, dblDelayTime, 0, 0)      ' wait 100mS (variable time)

AddRequest(LJID, Put_Digital_Bit, Eio6, 0, 0, 0)                ' turn off

GoOne (LJID)                                                                     ' Stream Is Active Error occurs**********

 

eget(LJID, Stop_Stream, 0, dblvalue, 0)

eget(LJID, retrieve the data)

 

 

I am hoping to capture the transient effect of this turn on event

 

Individually the two sequences work (minus any typo error I may have put in).

 

I couldn't see an example on the web site or forums like this.

Can this be done (do I have something set up wrong - mode / method)

 

Georg

 

 

 



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 17 April 2014 - 10:18 AM

I need to check with someone else, but perhaps the WAIT iotype does not work while streaming.  Try instead doing 2 eDO commands with a software wait in between.



#3 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 17 April 2014 - 01:37 PM

That is correct. The wait function and stream use the same hardware timer. So wait functions can not be used while streaming. The suggestion of performing other operations to create delay is effective. Instead of using the wait command run the "turn on" line twice. Or set an unrelated IO.



#4 GeorgSoerensen

GeorgSoerensen
  • Members
  • 8 posts

Posted 17 April 2014 - 06:15 PM

Is there a LabJack module in which this can be done (the wait function and the stream use a different hardware timer) ?

I would really like to have the feature of streaming data in while setting off accurately timed (software specified) events.

 

Georg



#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 April 2014 - 12:05 AM

Realize that the U3 clock is only 1.5% accurate anyway, so a software timed 100 ms pulse can be about as accurate as a hardware timed 100 ms pulse.

 

A different approach on the U3 would be to use a timer in PWM16 mode to make the 100 ms pulse, and another timer in STOP mode to stop the PWM after 1 pulse:

 

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

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

 

That uses the U3 clock which is 1.5% accurate.  The U6 can do the same thing and has a much more accurate clock ... 30ppm at room temp.

 

 

On the T7, you have a few options:

 

- WAIT technique on the T7 can be used during stream.

 

- Pulse Out DIO Extended Feature

http://labjack.com/s...tures/pulse-out

 

-Stream-Out technique

 

 

 

Good information here:

 

http://labjack.com/s...form-generation



#6 GeorgSoerensen

GeorgSoerensen
  • Members
  • 8 posts

Posted 24 April 2014 - 02:27 AM

A 1.5% accurate pulse is accurate enough for my purposes for this project.

Problem is I can't get that close with software timing.

 

ADDRequest(LJID, put_config, channel.stream_wait_mode, streamwaitmode.none, 0, 0)

ADDRequest(LJID, ClearStreamChannels, 0, 0, 0, 0)

ADDRequest(LJID, add_stream_channel_diff, 0, 1, 1, 0)    '(0&1)

ADDRequest(LJID, add_stream_channel_diff, 2, 1, 3, 0)    '(2&3)

ADDRequest(LJID, add_stream_channel_diff, 4, 1, 5, 0)    '(4&5)

ADDRequest(LJID, add_stream_channel_diff, 6, 1, 7, 0)    '(6&7)

ADDRequest(LJID, add_stream_channel, 193, 0, 0, 0)     ' to catch when Digital channel is actually on

goOne(LJID)

 eget(LJID, Start_Stream, 0, dblvalue, 0)                         ' start streaming

 

'method 1 to turn on device to measure

threading.thread.sleep(20)                                               ' 20mS give a little delay time

eput(LJID,Put_Digital_Bit, LJ_Eio0, 1, 0)                         ' turn on source

threading.thread.sleep(intPulseWidth)                            ' wait intPulseWidth=100mS

eput(LJID,Put_Digital_Bit, LJ_Eio0, 0, 0)                         ' turn off

 

'method 2 to turn on device to measure                                 ' no 20mS pause as before to

ADDRequest(LJID,Put_Timer_Mode, 0, PWM16)               ' setup for 5Hz : 48Mhz_Div with Div=148

ADDRequest(LJID,Put_Timer_Value, 0, 32768)                 ' 50% duty cycle gives 100mS pulse

ADDRequest(LJID,Put_Timer_Mode, 1, TimerStop,0,0)     '

ADDRequest(LJID,Put_Timer_Value, 1, 1 ,0,0)                  ' one pulse

goOne(LJID)

 

' get the data

eget(LJID,Get_Stream_Data, All_Channels, numscans,dblData)  ' retrieve data

eget(LJID,Stop_Stream, 0, dblvalue, 0)

 

 

' with method one, everything looks okay, trigger event happens around 20mS into the stream,

' although changing small changes in this delay don't seem to affect it (till you go below 15 or above 23)

' but the event lasts 108mS. Okay, I tried reducing the Sleep time but nothing happened till around

' 93 when pulse time dropped to 92mS pulse width

okay - little strange behaviour with the threading.thread.sleep method

 

' with method 2, I now get a fairly accurate 100mS pulse (<1ms error), but, I can't seem to get it to

' start at a consistent place. Sometimes it starts immediately, other times it waits as much as 170mS

' to get startedm (no discernable pattern to the delay is apparent).

 

I don't do any data collection from the buffer as my collection times are quite short and will never collect

more than 100points (500samples with the 5 channels) so I shouldn't overrun the U3 buffer.

 

Why is getting the start with the TimerStop Mode method so inaccurate.

Have I done something wrong that you can see?

 

Not sure if the strange sleep behaviour is a Labjack result or something in my system parameters.

 

Does the automatic transfer of data from the U3 to the driver interfere with the execution of events?

(If so, is there a way to stop the transfer, until specified, I never collect large quantities of data but I

do want to have short interval measurements)

 

I suppose I could put the TImer events into the Stream setup and execute everything as a GoOne

but I'd rather have a delay between Stream start and the Trigger start.

 

Any suggestions as to what I'm doing wrong or as to a better way?

 

Georg



#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 April 2014 - 10:37 AM

 

Does the automatic transfer of data from the U3 to the driver interfere with the execution of events?

(If so, is there a way to stop the transfer, until specified, I never collect large quantities of data but I

do want to have short interval measurements)

You are trying to do a software timed 100 ms pulse, while a stream is going on, and finding that the pulse varies from 92 to 108 ms.  You might be right that the background stream transfers are making your command-response timing less accurate.  Before we blame that, though, do a test of the same code without the stream running.  Your 16 ms jump is suspicious as that can sometimes be the timer resolution in software on some operating systems.

 

Why is getting the start with the TimerStop Mode method so inaccurate.

Have I done something wrong that you can see?

 

See the second to last paragraph on the PWM16 page.  The PWM output does not start until the clock rolls:

 

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



#8 GeorgSoerensen

GeorgSoerensen
  • Members
  • 8 posts

Posted 24 April 2014 - 07:19 PM

Ok, it don't think its the labjack for the first case,

I did a test where I incremented the sleep time from 90 to 105mS (with nothing running) and found

Req: 90mS  Got: 79 +/- 1mS

Req: 91,92,93 Got 93mS +/1 mS

Req: 94-105 Got 108 +/1mS

these results are very reproducible.

 

I think that the OS must TimeSlice differently depending on system with the Thread Sleep command.

I thought maybe the solution is to NOT give up thread control:

I created a Do Loop of a single math command (aTan) and execute a (large) number of times.

By adjusting the number of times, I can the desired result 100mS  but it's subject to OS random events.

If I do nothing, I get +/-1mS reproducing.

If I move the mouse, the time increases, little motion, 2-3mS more, lots of motion and maybe 6-9mS more

Results in 10% uncertainty.

So I could perhaps use a combo of the 2 to get close enough.

 

Point 2, I see. Because I'm running the timer at 5Hz, it could start anywhere within a 200mS timeslice.

 

Can a counter be used to trigger an IO port to change state?

If i ramp up the frequency, say 500Hz, could I then count 50 pulses and make an IO go low?

 

Then my uncertainty would only be less than 2mS. I've not used the counter before so I'm not sure of its' abilities.

 

If not, I guess I can place a counter chip outside and then count pulses externally but I'd rather do everything if I could in

the LabJack.

I guess running 2 U3 or one U7 might also be the best way to go.

 

P.S. Thanks for the quick and informative response. Its nice to see these battles in the forum. I've learned lots from all the little problems people have.

 

Georg



#9 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 April 2014 - 08:03 AM

1.  What is your programming environment and operating system?  Then we can comment on whether there is a way for you to get 1ms time resolution rather than 16ms time resolution.

 

2.  The method you are using with PWM16 and STOP timer is the best option with timers/counters.

 

3.  Using 2 U3s or a T7 would work great.



#10 GeorgSoerensen

GeorgSoerensen
  • Members
  • 8 posts

Posted 27 April 2014 - 06:14 PM

Ok. I think it would be great (perhaps in a new module) if the counters could have their own IO port. You could do a lot with having a counter trigger an external event without having to go through software directly.

 

I'm using XP pro and windows7 environments with VB.net Studio 10 version.

 

I've solved my problem by using the combo of the thread.sleep and my do loop.

I basically sleep for (time-10)milliseconds, measure the discrepancy with the stopwatch, and then use the my do loop (which measures how many loops are required for a 1ms delay) and loops through that. Mouse movement and other events then only account for a few percent of the loop delay (few milliseconds) and I end up with a delay very close to what I want.

I measured with an oscilliscope and get my 100mS with about +/- 0.5mS accuracy.

Not quite as elegant as a simple thread.sleep but good enough for me to continue till I can determine a better solution.

 

Georg





Also tagged with one or more of these keywords: Streaming, DigitalOutput

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users