LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement this "simple" algorithm?

Solved!
Go to solution

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.

1.jpg

2.png

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.  

0 Kudos
Message 1 of 22
(5,812 Views)

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

Kudos are welcome...
0 Kudos
Message 2 of 22
(5,802 Views)

Looks like a neat little homework problem.

I suggest looking into using XOR.

0 Kudos
Message 3 of 22
(5,801 Views)

Use a feedback node and compare current to previous. You have 3 states, so use a case structure with three cases:

 

  1. Current and previous are equal
  2. Current is larger
  3. Current is smaller

Why does your code us a local variable? Where's the terminal? What is the rate of your loop?

0 Kudos
Message 4 of 22
(5,800 Views)

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

0 Kudos
Message 5 of 22
(5,792 Views)

@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 ...")

0 Kudos
Message 6 of 22
(5,767 Views)

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.

0 Kudos
Message 7 of 22
(5,751 Views)

@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?

 

 

0 Kudos
Message 8 of 22
(5,738 Views)

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.

0 Kudos
Message 9 of 22
(5,736 Views)

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 Smiley Very Happy

0 Kudos
Message 10 of 22
(5,730 Views)