LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error in the result while adding

Hi

 

This is a simple program which repeatedly adds a number once you define the step size of the number. Shift register is also being used. suppose if the no. is 9 and the step size is 1 then the result should be 10, but it is not so. what is wrong with the program?

0 Kudos
Message 1 of 10
(3,136 Views)

If you are changing the "number" control after the program starts, you wont see any result. Also, your loop is spinning out of control. But a "wait" in there somewhere. Other than that I don't see any flawed logic, but it's late. What results are you getting. If we don't know what's wrong, we can't help you. All we know is you aren't getting the result you want.

0 Kudos
Message 2 of 10
(3,132 Views)

Just add the wait function, try setting it to 1000ms so you can clearly see the transition. Apart from that it works correctly, what else do you want to do with this app?

Regards,

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
0 Kudos
Message 3 of 10
(3,120 Views)

Hi jkfhdskh,

 

May be this vi will make you understand the concept.

 

Regards,

 

Nitz..

0 Kudos
Message 4 of 10
(3,113 Views)

Hi Nitzy,

When you run your vi please monitor your cpu usage in your windows task manager, it is pulling a lot of processing power. To rectify this, try putting a 'Wait(ms)' timing function inside your while loop and wire a constant to this, it will solve this.

Just a tip as your application might crash your computer when you use more complex functions in the future.

Regards,

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
Message 5 of 10
(3,107 Views)

Hi John,

 

This was of great use for me. I never noticed such a big flaw in this way of using while loop. Just checked after reading your message. May be this is the reason why some of the VIs in my previous projects were getting slow while running. 

 

anyway thanks a lot...:)

 

Regards,

 

Nitz..

0 Kudos
Message 6 of 10
(3,101 Views)

Hi Nitzy,

I'm glad I could point that out, it's a necessity when using while loops!

Always here to help 🙂

 

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
0 Kudos
Message 7 of 10
(3,095 Views)

Your VI does work as intended. Put a wait 1 second and you will see the answer is 10  given the start numeric of 9 and and a step of 1.

 

 

 

Alan

0 Kudos
Message 8 of 10
(3,082 Views)

 


@Nitzy wrote:

Hi John,

 

This was of great use for me. I never noticed such a big flaw in this way of using while loop. Just checked after reading your message. May be this is the reason why some of the VIs in my previous projects were getting slow while running. 


It really depends on what you're doing. For a loop that is intended to run for a long time you do not want to have the loop steal all of the CPU processing time. Otherwise the user interface and the OS will become unresponsive. There are times, however, when you would not need to put in a delay, such as using a while loop to create a Functional Global Variable, a.k.a. Action Engine. Or, if the loop is intended to only run for a few iterations (and there's a guarantee that it will break out and not become an infinite loop).

 

Message 9 of 10
(3,060 Views)

 


@smercurio_fc wrote:

It really depends on what you're doing. For a loop that is intended to run for a long time you do not want to have the loop steal all of the CPU processing time. Otherwise the user interface and the OS will become unresponsive. There are times, however, when you would not need to put in a delay, such as using a while loop to create a Functional Global Variable, a.k.a. Action Engine. Or, if the loop is intended to only run for a few iterations (and there's a guarantee that it will break out and not become an infinite loop).


 

These use cases have now better workarounds in newer LabVIEW versions.

 

 

  1. Use an event structure for the UI loop. Only spin the loop if things change. Never do the same operations on the same inputs more than once unless you expect a different result every time.
  2. FGVs no longer need loops at all, we can use globally initialized feedback nodes.
  3. To guarantee that we don't create an infinite while loop, we use a FOR loop with the conditional terminal and wire a reasonable upper iteration limit to N.

 

 

 

0 Kudos
Message 10 of 10
(3,013 Views)