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: 

state machine real time application

Hi,

I am running a real time application where there are multiple loops going. Two of these loops contain state machines. I attached a simplified VI to show how they are set up. With this architecture, my CPU usage has been 99% to a 100%, when I disable the two loops, usage drops to 20% which suggests that my loops are not efficient.

Can someone please explain to me what I doing wrong.

 

FYI, in my application boolean is controlled by a shared variable which communicates with my host VI.

 

Thanks for your help. 

TeamHalli

0 Kudos
Message 1 of 6
(3,240 Views)

TeamHalli wrote:  With this architecture, my CPU usage has been 99% to a 100%, when I disable the two loops, usage drops to 20% which suggests that my loops are not efficient.

Can someone please explain to me what I doing wrong.


Sounds like at least one of your loops is just polling and running as fast as the CPU will allow.  This is not good, especially in an RT system.

 

Unfortunately, you did not attach any code, so we cannot help debug.


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
0 Kudos
Message 2 of 6
(3,237 Views)

Your inside While loop will never end. The "Boolean" is read from outside the loop, so the value will always be true (and then negated to false). This means the Exit case will just continue cycling, using up all your precious CPU.

 

LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. Here's a simple resource to become more familiar with how it works. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

 

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 3 of 6
(3,225 Views)

The inside while loop should end when boolean goes false.

What do you suggest in this case?

0 Kudos
Message 4 of 6
(3,211 Views)

The boolean needs to be read inside the loop. Dataflow. Go to the link I included above.

 

And if you're just going to leave the Exit case looping indefinitely, then you need to add a Wait in there so it's not taking all of your CPU.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 6
(3,199 Views)

@TeamHalli wrote:

The inside while loop should end when boolean goes false.

What do you suggest in this case?


No it won't.  LabVIEW is DATA FLOW.  So whatever value is at the tunnel when the loop starts is what the value will always be.  The boolean will not be read again until its terminal gets executed again.  This does not happen until the outside loop is iterated.  Why not just have the inside loop stop when the Exit case is executed?

 

BTW, that is why you are getting 100% CPU usage.  You go into the exit case and just looping the exit case.  Since there is no wait, the loop is ran as fast as possible.  Good way to burn up your processor.

 

I would suggest some changes to your state machine.  Typically, a state machine INSIDE of ANOTHER loop is a bad idea.  Instead, add the checking for the boolean in another state of your state machine.  Call it something like "Idle".  You will want a wait in that state.  But when the button goes to TRUE, you go to the Initialize state and progress from there.  The Exit case should send you back to the Idle state.


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
0 Kudos
Message 6 of 6
(3,193 Views)