LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you use shift registers to increment values?

Hi,

 

I'm a bit stuck on basic architecture to wire this one. 

 

I want the input value to be compared to a threshold value to determine TRUE/FALSE case.

For the first Input Value ONLY (TRUE CASE), I want the Threshold increment applied to it, but, for all subsequent Increment multipliers, the most recent OUTPUT value should be incremented, NOT the Input value.

 

In other words, I have a continuous stream of Input Values, some of which will be greater than the threshold, and others will be less than the threshold.  Each time the Input Value is greater than the threshold, then, I want the MOST RECENT OUTPUT value to be increased by the increment multiplier to create a new, higher, OUTPUT.  How do I use the shift registers to apply the multiplier to the previous OUTPUT value for the TRUE case?  I feel like I have to wire two inputs to the multiplier, which is obviously not allowed.

 

What am I missing?

 

Thanks for your advice.

 

0 Kudos
Message 1 of 11
(6,462 Views)

If I am not mistaken and I understand you correctly I think this is what you are looking for.

 

threshold_test_code.png

 

Note: The random number generation is a substitute for your input stream in this example.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 11
(6,453 Views)

Hi, 

 

I think Mark's example will work fine, but if I am not wrong the doubt was about how to use a Shift register. Have a look on the attached code and images. This must be what you are looking for.

 

true.PNG

 

Regards,


Nitzz

(Give kudos to good Answers, Mark it as a Solution if your problem is Solved;))

0 Kudos
Message 3 of 11
(6,441 Views)

@dav2010 wrote:

Each time the Input Value is greater than the threshold, then, I want the MOST RECENT OUTPUT value to be increased by the increment multiplier to create a new, higher, OUTPUT.


You seem to be mixing terms. Typically "increased" would impliy addition, but you seem to be multiplying.

 

What is the formula for the new output that you want?

 

Is it:

  1. [New output] = [current value] *  [threshold increment] + [old output]
  2. [New output] = [threshold increment] * [old output]
  3. [New output] = [current value] *  [threshold increment] * [old output]
  4. [New output] = [current value]  + [old output]
  5. ... something else?

 

You also don't have any deterministic timing. How often should the loop spin per second?

0 Kudos
Message 4 of 11
(6,404 Views)

Maybe something like this?

 

Download All
0 Kudos
Message 5 of 11
(6,398 Views)

The reason I used the feedback node was that the OP specified that the first input needed to be used for the initial value. Unless you read the input outside the loop to initialize the shift register you would require some test within the loop to verify whether this is the first time through the loop. Having this test within the loop is wasted processing since it is only meaningful one time. the feedback node allowed the initial value to be initialized inside the loop and eliminated the conditional test.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 11
(6,371 Views)

However, if the shift register is initialized with zero, the first value can be added and it would be the same as using the plain fit value the first time.

0 Kudos
Message 7 of 11
(6,368 Views)

Hi Nitzz, and thank you.  Yes, you are right, that an important part of my question was about shift registers.  Regarding the code you offered, it looks to me like the OUTPUT value will always be zero because the initial input value is not linked to the increment function.  Using your code, how do we get the first OUTPUT value generated from the INPUT value of the first TRUE case?  The whole chain of values that are produced through the increment multiplier (or equivalently an addition function) needs to be based on the first INPUT value.

 

Thanks,

Dave

0 Kudos
Message 8 of 11
(6,356 Views)

Hi,

 

Thanks for your question.  I intend to increase the value with each TRUE case, and it actually doesn't matter to me whether it is by multiplying or by adding.  Either way will work.  As I optomize my mechanical system, I should be able to determine by experiment, how much increase is required, and whether it is more convenient to use a multiplier or an addition system.  I think that they are interchangeable.  In the example code that I listed, my intention was to start with an approach equivalent to your number 2 below, i.e.  [New output] = [threshold increment] * [old output].  In this case, the threshold increment would be some number greater than 1.

 

Regarding the frequency, I would like the code to execute as fast as possible, but, I am writing to a controller over a 9600 baud line, so, that is my limitation.  I am in discussions with the vendor of the controller to determine how many commands per second it can receive.  But, actually, the spins per second is a lower priority for me at this moment than just getting this increment code doing what I want it to do.  How do you put in deterministic timing?

 

Thanks again,

Dave

0 Kudos
Message 9 of 11
(6,339 Views)

Hi Mark,

Thank you very much for the sample code.  I am anxious to try it.  Will you kindly tell me what the name of the function at the top of the box is, with the arrow pointing left?  I have not seen that one before.

Thanks,

David

0 Kudos
Message 10 of 11
(6,335 Views)