From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-09-2018 11:11 AM
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!
03-09-2018 11:29 AM - edited 03-12-2018 11:07 AM
How wide is your screen exactly??? 😮
Just glanced at it for 20 seconds, but here are some observations:
03-12-2018 05:38 AM
@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?
03-12-2018 11:06 AM
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 😄
03-12-2018 11:31 AM
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?
03-13-2018 04:17 AM
@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.
03-13-2018 04:41 AM
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
03-13-2018 04:54 AM
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.
03-14-2018 09:39 AM
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.
03-14-2018 10:14 AM
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.)