09-12-2017 03:07 PM
Dear friends,
I need some help, I wish to know how to implement this "simple" algorithm?
My goal, simply saying, once meets 1 do thing A, meets 0 do thing B, but only do one time when meets bit changed.
In other words, I will do things (A or B) only I meet the first bit changed.
In other words again, in below pictures.
notes: 1. i is the the order of the whole loop. 2. the local variable, numeric, will give one number (0 or 1) for each iteration (just one number, not an array,e.g. in the top figure, i=1, got 1, i= 5, got 0... )
my goal, when meets the first bit changes, do things one time. That's why I put as in top picture, only in the red square, you do the thing one time (e.g. when i = 2,3,4, dont do anything. only do it one time, until meets the bit changes ).
May I ask give me some help about this. Could someone give me the vi, it's not necessary to run, but please show me how to do this in this while loop? Thank you in advance.
Solved! Go to Solution.
09-12-2017 03:12 PM
Use a shift register to compare the value of "numeric" with the value of the previous iteration. If the value changes (comparison Not equal), check the value of "numeric" and do A or B.
Jens
09-12-2017 03:12 PM
Looks like a neat little homework problem.
I suggest looking into using XOR.
09-12-2017 03:15 PM - edited 09-12-2017 03:15 PM
Use a feedback node and compare current to previous. You have 3 states, so use a case structure with three cases:
Why does your code us a local variable? Where's the terminal? What is the rate of your loop?
09-12-2017 03:19 PM
yes, it was my first try, but i failed.
question. where this numeric should be wired? when i wire this unmeric to a shift regeister , i got error something like wired to undirectional tunnel.Thank you
09-12-2017 03:57 PM - edited 09-12-2017 03:57 PM
@sunson29 wrote:
yes, it was my first try, but i failed.
question. where this numeric should be wired? when i wire this unmeric to a shift regeister , i got error something like wired to undirectional tunnel.Thank you
Please show us your code (not pictures) and quote error messages verbatim and not "something like ...")
09-12-2017 04:53 PM
Right now, the problem is how to show this before and after value by using a feedback node or shift register......
The local variable is just a place giving the 1 or 0.
09-12-2017 05:21 PM
@sunson29 wrote:
Right now, the problem is ...
No, the problem is that you don't show us any real code. We cannot tell what you are doing wrong unless we know what you are doing.
@sunson29 wrote:
The local variable is just a place giving the 1 or 0.
Where does the data come from? Is it connected to an indicator or control? Where is the terminal of it?
09-12-2017 05:24 PM - edited 09-12-2017 05:40 PM
Actually, there is no code..... I am doing a bigger project. I just abstract the question into this simple version. There are 2 state machines, one start machine will give the value to the local variable in 2nd state machines.
If you ask code, just the while loop, variable, and case structure. That's it.
09-12-2017 05:42 PM
Sunson, you should post your code. You will soon find that the LabVIEW forums are a place where you think you are working on something complicated and then Altenbach replaces everything with an array and a couple of primitives