Search code examples
loopsrace-conditionlabview

EASY! Labview Race Condition


I'm very new to LabVIEW... I need to write a simple program in LabView to update the value of an encoder.

Long story short... In a loop, I need to manipulate variables in this order:

  1. New Value = Old Value + Current Value
  2. Old Value = New Value

How do I prevent accidentally storing the old value before I calculate the new value?

Thanks in advance.


Solution

  • What you want is to pass the old value via a shift register (or feed back node, is the same). Here is the code snippet that shows you how to do it:

    enter image description here

    You can check that it works by looking at the New and Old values array.

    A side note since your new, you can import code snippets directly into labview.