LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I increment a variable in LabView ?

Hello ..

I'm trying to use LabVIEW to increment a variable, but I can't find the right way to do that !

I need to declare a variable and assign zero as its value, then increment it by one each time a certain condition is met, and I need it to reset to zero after it reaches a certain value. It's easy to perform these steps using standard C language but here it looks complicated !


Could someone explain the steps to do that ?

 

Thanks!

0 Kudos
Message 1 of 8
(15,349 Views)

Have you tried the online LabVIEW tutorials? 

 

http://www.ni.com/gettingstarted/labviewbasics/

 

LabVIEW doesn't have variables in the same sense as C.  For your application, try a while loop with a shift register.   The wire is your variable.

 

 

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 8
(15,338 Views)

The "variables" is the wires.

 

I assume you have some loop and/or event structure, feed the wire through a shift register at loop edge (so it's fed back to next loop) and if condition is met, increase it by 1, else just pass it along.

 

/Y

 

(This example will also give an introduction to events)

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 8
(15,334 Views)

Thank you guys for the replies ..

I have to submit my work in four hours so I don't really have time to go through tutorials!

 

if someone could please tell me how to do the increment thing and reset to zero when the loop executes again I would really appreciate it 🙂

 

I tried the shift register thing but it does the increments from 0 to 10 only and then it starts adding decimal points to the counter so it goes from 0 to 0.1 until it reaches 10 etc.. Is it possible to make it count integers only and not stop at 10 ?

 

 

0 Kudos
Message 4 of 8
(15,299 Views)

No one here is going to do your homework for you. I'm sorry that you have put this off until the very last minute but the shift register and reset are really basic. If you are incrementing by something other than an integer, you have made the increment value a non-integer. Simple as that. You have not posted your code so it is hard to give any more concrete advice.

0 Kudos
Message 5 of 8
(15,294 Views)

It always helps to post your code so people can actually see what the code is doing, otherwise it will just be a guess.

 

You are also not helping yourself by saying you only have 4 hours to turn this in and don't have time to go through the tutorials.  It did make me laugh a little bit though Smiley Wink

 

Did you try what the other 2 posters said or try the provided vi?  I did not open it, but if it does what you want you just need to figure out how yours is different and make the changes.

0 Kudos
Message 6 of 8
(15,290 Views)

Dennis: I'm sorry if you understood that I was trying to make you do my homework, this is a part of bigger program, I tried many things before asking << from my noobish perspective 😛 ,, but nothing seems to work!

The thing is that I'm new to LabVIEW and I found myself forced to use it to accomplish a part of some project!

 

_Bryan: yes I tried the attached VI but I couldn't figure out how to understand its function and build a similar one in my block diagram, and I'm glad that I made you laugh 😛

 

Anyway.. Thank you guys so much for helping me 🙂

 

 

0 Kudos
Message 7 of 8
(15,264 Views)

I guess trying to explain how to write a state machine would be difficult..

It should take you 5 mins to implement the solution.  I post so late that it's probably too late for you.

 

But here goes.

 

Take a While loop with shift registers as shown in the image of an earlier post.  Place a Case Structure inside the loop.  You will need to use an enumerator (usually create a type def control).  Put 2 states into the enumerator:  reset, increment.  Wire the enumerator to the question mark of the Case Structure.  In the increment case of the Case Structure, you place the +1.  In the reset case you simply wire zero '0' as the proper type (dbl, U32, etc) to the right tunnel of the Case Structure.

 

In the code somewhere... you need to set the logic to tell the state machine when to reset.  I don't recall reading what that was...  But in any case, you need another shift register to pass the next state to the Case Statement.  Or if that code is embedded into some other code, then it is probably not necessary.  But you will need someting like a selector to choose between Increment and Reset.  Also choose which of the 2 is the default state, probably any of the 2 for now.  The outcome of the logic to reset or increment is obviously wired to the middle terminal of the Select.

 

Just curious, since you are in this predicament.  Did you tell your boss that you knew LabVIEW in order to get the job and now you are obviously stuck delivering a solution?

 

 

0 Kudos
Message 8 of 8
(15,236 Views)