From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Way to speed up loop execution time with live serial outputs?

Solved!
Go to solution

Hi, I'm a new LabVIEW user trying to control a linear actuator with an analogue voltage being supplied from a DAQ connected to LabVIEW. The whole program is too large to show in a single screen but I attached a sample that shows a very basic version of my serial setup within a loop. In the actual program there are case structures, various other outputs, calculation, and string conversions also within the same loop.

 

Currently each loop takes about 0.1 seconds to execute leading to choppy actuator motion which is not suitable for my application. While troubleshooting I made a version of the program that performs all of the same operations but doesn't include a live serial output and it runs smoothly with each loop taking about 0.007s to execute. This leads me to believe the delay is caused either by the way I have written my code to interact with the serial connection or by the serial connection itself.

 

Is there a way to speed up the loop execution/serial connection or is the problem with my hardware?

0 Kudos
Message 1 of 7
(2,973 Views)

Show us an image of the code that runs "faster' so we can see the difference and understand exactly you want to change.

 

Could be...

 

Use faster baud rate,

Set serial for async,

OR

Other depending on what you share and how this question shapes up in the end.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(2,959 Views)
Solution
Accepted by topic author H2lloTh3r3

That is sounding like your serial instrument only sends updates every 100ms.  There might be a command to tell it to send out updates more often.

 

I like to separate my instrument reading loops to avoid issues like this.  So just from your sample, I would have a DAQ loop and a Serial loop.  These loops can send updates to whoever needs the data via Notifiers, Global Variables, Queues, User Events, etc.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 7
(2,954 Views)

Once again the program is too large to fit on one screen so I've made changes to the sample I posted to hopefully show you what I mean when I say I removed the serial connection.

 

Basically instead of asking the actuator for its position I am calculating it using where is should be according to the voltages I put in. Of course this is less accurate because there is error in the calculations, but the motion of the actuator is smoother.

0 Kudos
Message 4 of 7
(2,951 Views)

Hi There,

 

go with crossrulz' recommendation to separate DAQ loop from serial communication…

 

(I would even recommend to get rid of that DAQAssistent too and replace it by "plain" DAQmx functions!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(2,941 Views)

@H2lloTh3r3 wrote:

 The whole program is too large to show in a single screen


That is a huge red flag in any LabVIEW program.

 

Without seeing all of your code we can not really advise you in how to fix it.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 7
(2,923 Views)

Thanks a lot. Separating the serial from the rest of the loop seems to have put me on the right track. I'm sure after I figure out how to work with notifiers, global variables, queues, and user events I will get the results I'm looking for.

0 Kudos
Message 7 of 7
(2,894 Views)