LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sample rate drops drastically after adding a waveform generator

Solved!
Go to solution

Hey there!😊

This is my second post for today but i have no idea what to do...

 

I have one program which works fine with my 4 sensors (3 values each). I have a sample rate of around 160Hz.

Screenshot (53).png

Screenshot (52p.png

 

I have furthermore a program which controls my power supply via a waveform generator/virtual bench and also measures the current and voltage from that power supply. This works also fine by itself.

 

Screenshot (518.png

Screenshot (51).png

 

Here comes the problem, once i merge the 2 programs with each other, it starts lagging A LOT and my sample rate from my sensors drops from 160Hz to less than 10. I have absolutely no clue what is causing it...

 

asdf.png

 

sgdd.png

 

I also just tried to run each of those programs next to each other but it comes down to the same.. 

 

I also need to add a shunt measurement but i didn´t even try that because it all seems already sooo messed up..

 

I am thankful for any kind of help and i really need it..

Thank you guys!!

 

 

 

 

Download All
0 Kudos
Message 1 of 9
(1,724 Views)

Without getting into ways to better write all of this for scalability, best practices, and what not, I recommend you try the following just to get it work:

 

Don't put all the code into the same loop.  You say they function properly separately.  So place both the PowerSupply.vi and the Sensors.vi into the SensorsAndPowerSupply.vi Block Diagram separately.  There are of course some things you'll need to do to make this work properly (like making sure you have a way to stop both VIs with the same command).  But basically, your issue is that you have Write/Reads for your power supply that are slowing you down significantly.

Message 2 of 9
(1,717 Views)
Solution
Accepted by topic author Jugo

You are at the point in VI design where you need to start making sub VIs and using the sub VIs to make a larger program. You already have the code for the two main sub VIs. IMO you should remove the loop from each of the sensors.vi and power.vi so that they can execute once each time they are called. Take those two subVIs and put them in a new VI (like the sensors and power VI) that has Two independent loops, one for each sub VI. Add the front panel terminas to the sub VIs so that you can input and extract data from the sub VIs as the code runs.

 

The VI you posted (SensorAndData.vi) is pretty close to working, just need to make it two individual loops with the code in each loop reduced to subVIs and it should work great and be more extensible, easy to test, easier to read, etc ... 

 

 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 3 of 9
(1,688 Views)

First of all, thank you both very much i am very thankful for your help!!

So i took your advice because i thought this is the easiest way to fix my issue... And it worked suprisingly well to be honest...  My sample rate stays now at around 160Hz, BUT the stop button for my VIrtualBench (the big red one bottom screen) seems to stop working.. My VB is now literally unstoppable😄

 

Screenshot (56).png

 

ssss.png

 

Maybe it was not so easy, and i should´ve done more than just seperate the loops🤔

 

 

 

0 Kudos
Message 4 of 9
(1,671 Views)

@Jugo wrote:

BUT the stop button for my VIrtualBench (the big red one bottom screen) seems to stop working.. My VB is now literally unstoppable😄

 


Unstoppable is good in attitude but probably not in a program. You can make a local variable so that the a single button exits both loops when you press it, that is a quick and dirty fox to that problem. 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 5 of 9
(1,659 Views)
Solution
Accepted by topic author Jugo

Hi Jugo,

 


@Jugo wrote:

BUT the stop button for my VIrtualBench (the big red one bottom screen) seems to stop working.. My VB is now literally unstoppable😄


Both "Stop" buttons ("Stop Sensors", "Stop VB") in the upper right of the frontpanel should work as expected.

 

The only other button is labelled "Start power supply output" (there is no "Stop" in the label!) has no function at all! The wire from its terminal is connected to the border of a single-case case structure - and that's it. That button simply has no purpose in your VI…

 

The lower loop may also look like this:

Still things to do:

  • You should also close the file somewhere! It's a bad habit not to close references when you opened them on your own!
  • The same applies to the serial port reference!
  • The case structure for saving seems wrong: right now you save when the "Speichern" button is FALSE. The button is labelled differently…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 9
(1,618 Views)

@Jugo wrote:

Maybe it was not so easy, and i should´ve done more than just seperate the loops🤔


Welcome to the world of concurrency.  Probably the nr 1 issue for programmers (in any language).

 

In LabVIEW you get the concurrency for free: everything (incl. two loops) works in parallel.

 

You still need to fix the concurrency problems: synchronizing execution and data...

 

Concurrency is hard, that's why people often use patterns, in this case architectural patterns like (D)QMH, AF, Producer\Consumer, etc., etc. Alternatively, you could use messaging libraries (DIY or e.g. JDP Science's Messenger Library) to 'glue' things together.

Message 7 of 9
(1,610 Views)

Hey Gerd,

 

I used your advise and fixed the things you listed.

 

Screenshot (62).png

my program is now running just the way i want it to!

I appreciate your help very much and from everyone else as well💓

 

Wishing everyone a nice day!

 

 

P.S: i kept my lower loop like it was... would you still recommend to use your approach?

 

0 Kudos
Message 8 of 9
(1,550 Views)

Hi Jugo,

 


@Jugo wrote:

P.S: i kept my lower loop like it was... would you still recommend to use your approach?


Yes, sure! Why should I post my suggestions when I wouldn't like them to be used?

 

(In general I suggest to stay away from ExpressVIs and DDT wires!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 9
(1,528 Views)