LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing Analog In and Digital Out

Hi all,

 

I am using NI USB-6212 to receive analog input from the Keyence IR sensor.

In my program, I would like the solenoid to active for 3 seconds after the temperature reaches a certain level or when the time reaches a preset time. The solenoid is connected to the Dev1/port0/line0 of the DAQ. 

 

One of the spot where the solenoid would be activated is when the time has elapsed for 5 second started from the beginning. (The solenoid will stay on for 3 second before it turn off)

As shown in the video attached, however, there is a lagging issue in the analog in during the time where the solenoid is activated.

 

So I would like to see how to solve this lagging issue. In order words, how do I synchronize Analog in and Digital out so that the analog in and digital out can be happened at the same time ?

Also, is it a hardware problem ?

 

Thank you all very much!

 

Please focus on the area circled in RED in the video.

Capture.PNG

0 Kudos
Message 1 of 10
(2,113 Views)

How can we understand what you did (that didn't work) if you don't show us what you did?  Attach your code.  Do not send a "picture" of your code, send the actual VIs themselves.  Be sure to tell us which version of LabVIEW (and whether 32-bit or 64-bit LabVIEW) you are using.

 

Bob Schor

Message 2 of 10
(2,064 Views)

Hi Bob,

 

I apologize for the inconvenience.

I am using LabVIEW 2021 of 32-bit.

The VI is simplified and attached along with the video that shows the lagging problem.

 

Thank you all for your advice, and I really appreciate with your help 🙂

Download All
0 Kudos
Message 3 of 10
(2,046 Views)

You would need to attach the code in preferably LV 2016 to cover more audience. Very few of the forum members use the LV2021.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 4 of 10
(2,043 Views)

Here is Kahn's code saved as LabVIEW 2016.

 

Bob Schor

Message 5 of 10
(2,030 Views)

Thank you!

0 Kudos
Message 6 of 10
(2,014 Views)

Now, to explain why you have the 3-second lag is expected as per your implementation (think DATAFLOW!)

 

  1. Capture signal
  2. Append signal and scale
  3. Control solenoid for 3-second if 5-second elapsed in the top-level loop
  4. Go back to #1

santo_13_0-1637599161281.png

 

Once the 5-second timeout occurs in the top-level loop, your solenoid control section runs for 3-second, during this time, your execution is stuck doing the solenoid work and cannot capture the temperature during that time.

 

Now, to fix this, you have to redo the whole structure and eliminate the use of DAQ Assistant.

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 7 of 10
(2,011 Views)

@santo_13 wrote:

Now, to explain why you have the 3-second lag is expected as per your implementation (think DATAFLOW!)


A "slightly Advanced" topic, but crucial to understanding and using LabVIEW ---

 

     I usually teach "The Three Laws of DataFlow".  Law 1 -- Data must be present on every Input to a Structure or Function for it to run.  Law 2 -- Data are not available at any Output from a Structure or Function until it exits, and then data are present on every output.  Law 3 -- within a Structure or Loop, the order of execution of items not connected (output of one to input of another) cannot be determined.  Law 3 can be paraphrased as "LabVIEW does its best to process "disconnected" code fragments in parallel (or simultaneously, at the same time).

 

     Here's an example -- you have a While Loop that captures a signal for three seconds, but does nothing else with it, and repeats until you say "Stop".  You have a second While Loop that, if given three-seconds of a captured signal, processes it, displays it, saves it to disk, etc., a process that may take 2 seconds. Let's say that the first Loop's 3-second signal results in 3000 data points (you are sampling at 1 kHz, for example), and the second loop's "captured signal" is also 3000 data points. 

 

     Start both loops running -- what will happen after 6 seconds?   Because the two loops are "disconnected", the Third Law says they will run "independently' and "simultaneously", so Loop 1 will loop 6/3 = 2 times, while Loop 2 will loop 6/2 = 3 times.  Now, Loop 1 is a Data Acquisition loop -- DAQ Loops are almost always "clocked" by DAQ Hardware, and (if coded properly) spend 99% of the time just waiting for the Hardware to acquire and present the data.  This leaves the "free time" for any other Loop (like Loop 2, doing Data analysis) time to "share" the CPU.

 

     LabVIEW has mechanisms to "almost-instantaneously" transfer data (without overt Wires!) from one Loop to another.  Have you learned about any of these?

 

     Again, the secret of Success here is what I've called the Third Law of Data Flow, removing code dependencies to let different parts of the Program process different "chunks" of Data at the same time.  Here Loop 1 is "producing" chunks of data, and Loop 2 is "consuming" these chunks -- I'll bet if you do a Web Search for LabVIEW, Producer, Consumer, you might find some reading of interest.

 

Bob Schor

Message 8 of 10
(2,004 Views)

Thank you guys for all the comments.

I will try to do more readings and redo the code by thinking more on the data flow.

I'm sure I will definitely have questions along the way, so I will keep updating with you all.

Thank you once again for your help and being patient with me 🙂

 

 

0 Kudos
Message 9 of 10
(1,970 Views)

It works after I use the Producer and Consumer Structure, thank you all very much!

0 Kudos
Message 10 of 10
(1,944 Views)