LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Proof My vi

I am trying to improve the efficiency of my vi as much as possible and was wondering if anyone has any tips, tricks, or corrections. The vi is a temperature monitor that will be built into an exe application. The front panel has numeric indicator for temperature and a waveform chart that will record temperature over the course of a week so it need to be memory efficient. There are also other programs on the computer that will be running alongside this vi so Im also trying to make it the least CPU intensive as I can.

 

My vi reads the voltage drop across a thermistor using a Labjack( this part of the code will replaced soon with Daqmx when my ni daq comes in the mail). Voltage data is collected at 5 samples/second and the average of those samples is fed into an event structure that times out every second. The event structure calculates the temperature from the voltage and displays the reading on the front panel and also adds it to a waveform chart. I have designed it so the temperature indicator is updated every second while the waveform chart will update less frequently to save memory. In the final build the waveform chart will update every 1 minute, 5 minutes or 10 minutes. depends how efficient I need it.

 

I used a Case Structure inside the event case to control when the waveform chart updates the while loop iteration is divided by a number to be determined and if the remainder is 0 the chart updates. Is there a way to do this operation so that the case structure inst continuously polling?

 

shown in the second image is the sequence structure containing the while loop. The first sequence when it starts up is it reads default values from a text file and writes them to local variables. The last sequence writes the local variables to the same file.

 

Any help is appreciated, Thanks!

0 Kudos
Message 1 of 15
(2,953 Views)

How wide is your screen exactly??? 😮

 

Just glanced at it for 20 seconds, but here are some observations:

 

  • Your event structure makes little sense, all you basically use is the timeout event. So just do a plain polling loop instead.
  • Your stop button has the wrong mechanical action. "Switch until released" is good for a car horn, but not much else. 😄
  • All your formula nodes contain duplicate code. All you need is plain G code operating on arrays.
  • Too many coercion dots and useless type conversions. Do you really think you save much converting to SGL? Now you have both in memory!
  • How many times do you think you need to get the current time in parallel. Wouldn't once be enough? You can always branch the wire later. If the chart update rate is regular, it seems sufficient to set t0,dt before the loop starts and just write plain data to the chart.
  • I would use the configuration file tools instead of making your own.
  • ...
Message 2 of 15
(2,944 Views)

@el_ManBearPig wrote:

I am trying to improve the efficiency of my vi as much as possible


Is that really necessary? It's obviously a lot of fun trying to tune code until it's optimal.

 

You're doing tiny calculations on scalars. Is it even noticeable?

0 Kudos
Message 3 of 15
(2,879 Views)

wiebe@CARYA wrote:

@el_ManBearPig wrote:

I am trying to improve the efficiency of my vi as much as possible


Is that really necessary?


There is run time efficiency, but there is also coding style to make editing, debugging, adding features, avoiding mistakes, etc. more efficient.

 

Making the code run more efficiently, you might save a few nanoseconds. Making the code design more efficient, it might save you weeks in the future 😄

Message 4 of 15
(2,850 Views)

Thanks for the reply,

 

I use the event structure because my understanding is that the functions inside it are inactive until the timeout every second instead of polling multiple times a second. This way the case structure inside is only polled once a second instead of 5 or 10 times a second. Is it better to have two case structures polling all the time?

 

 

0 Kudos
Message 5 of 15
(2,842 Views)

@altenbach wrote:

wiebe@CARYA wrote:

@el_ManBearPig wrote:

I am trying to improve the efficiency of my vi as much as possible


Is that really necessary?


There is run time efficiency, but there is also coding style to make editing, debugging, adding features, avoiding mistakes, etc. more efficient.

 

Making the code run more efficiently, you might save a few nanoseconds. Making the code design more efficient, it might save you weeks in the future 😄


Well, obviously. OP is only talking about CPU performance and I don't thing that should be a priority here.

 

Memory efficiency would be another factor.

 

In this piece of code, cleaning up \ coding style could be improved on. There's not that much going on, and the code is not terrible. But before scaling up the application, I'd think about modularity. This (the beginning) is the time to do that.

 

 

Message 6 of 15
(2,811 Views)

Your main loop doesn't work like you think it works.

The wait(200) will do nothing as it'll wait while the event wait for 1000ms. Thus you won't get 5 samples (unless the default iconed VI takes 5 samples and sends out the average). If so, Altenbachs comment of simply removing the event structure comes into play.

It's also problematic to have a fixed path to your settings file, the common way is to use e.g. Application path and add the file name. That way it'll be located in the lvproj folder while developing and the .exe folder when built.

Please replace the formula nodes with G-code.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 15
(2,803 Views)

Also, the formula nodes, and everything else, is doing the same thing three times. So apparently, you have three exactly the same things going on. The code should reflect that. Think about how your code would look if you don't have three, but 20 duplicates... Even for two duplicates, I usually write my code so it uses a for loop. Even two pieces of duplicate is too much.

 

I'd make a class that does everything once. Then I'd make either a composite child that executes the methods in a loop, or use a loop on the main. But that might be a bridge too far. Plain SubVI's would be an improvement.

Message 8 of 15
(2,798 Views)

Thanks for the help everyone!

 

Instead of the formula nodes would it make more sense to do something like this(new loop image)? Where I have a case structure inside a for loop for 3 iterations. Each iteration indexes 1 of 3 data inputs and triggers a different state of the case structure where the calculations are made. 

Download All
0 Kudos
Message 9 of 15
(2,766 Views)

Why are there four elements in the shift register initialization? All you need is autoidenxing at the right loop boundary. no shift register needed. No need for "index array", just autoindex on the incoming array at the left loop boundary. You also don't need the case structure because the code in each is identical. You could just autoindex on an array of calibration constants.

 

(Many more things seem odd and could be polished.)

Message 10 of 15
(2,751 Views)