From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a feedback loop or shift register to toggle a boolean during while loop

I have a sensor constantly reading values during a loop, and I need to have a boolean toggle to 1 when a maximum value is reached, and then to 0 when a minimum value is reached. I will be reading a sinusoidal pressure measurement and it is important to know if I am on the ascent or descent. For instance, let's say min: (less than or eq) 2, max: (greater than or eq) 5. The issue I am having is that I am a novice and only able to set a boolean to be 1 if it is = or > than a value. This is an issue because a value of 3.5 could have a boolean of 0 or 1 depending if it is in the ascent or descent. I'd also strongly prefer not to read the slope real time to determine this, as I don't think it would be accurate and reliable.

 

I'm sure this is very simple to an expert, does anyone have a vi that can do this? 

0 Kudos
Message 1 of 7
(1,277 Views)

@jd555 wrote:

I'm sure this is very simple to an expert, does anyone have a vi that can do this? 


Yes, it is very simple, but we can help better if you show us your failed attempts (attach your broken VI!), so we get more context. Nobody wants to start from scratch with too many vague points. 😉

0 Kudos
Message 2 of 7
(1,268 Views)

@altenbach wrote:
... too many vague points. 

Some vague points:

 

  • What is continuously?
  • What is the typical noise?
  • What is the amplitude and range of the measurement data?
  • So the signal is approximately sinusoidal. This is important information. What lets you conclude that the slope changes exactly at one threshold? With noise, it could continue to go up for a few points or never reach the value, but still go down after getting very close.
  • What is the frequency of the sine compared to the sample rate? (many points or just a few point per period?)

 

0 Kudos
Message 3 of 7
(1,252 Views)

 

  • What is continuously?
    • SPI pressure readings
  • What is the typical noise?
    • Very little, but I would like to modulate it by the last peak measured
  • What is the amplitude and range of the measurement data?
    • In this case, 0.05-0.12 PSI
  • So the signal is approximately sinusoidal. This is important information. What lets you conclude that the slope changes exactly at one threshold? With noise, it could continue to go up for a few points or never reach the value, but still go down after getting very close.
    • I am using a microcontroller to open and close an entry valve downstream of a gas pump and an exit valve exposed to atmosphere to achieve the desired pressure waveform (I am creating a small pressurized incubator to study hypertension in cells. I am recreating the pulsatile nature of blood pressure)
    • So to be clear, I am creating a sinusoidal waveform, not simply observing one that I assume to be there
  • What is the frequency of the sine compared to the sample rate? (many points or just a few point per period?)
    • Sampling rate is roughly 160/sec

Here is a rough waveform that I have obtained as well as my VI (although it is quite messy)

 

0 Kudos
Message 4 of 7
(1,240 Views)

Of course cause and effect is not quite clear. I assume the slope changes sign because the new measurement is out of range (above or below). Basically we are dealing with a simple on/off control with a deadband. I think there are quite a few examples here. Just do a search.

 

Maybe the attached will give you some ideas..... (Many things can probably be simplified)

 

0 Kudos
Message 5 of 7
(1,233 Views)

It's certainly not out of range, my sensor is accurate from 0-5 PSI, and I can precisely control my solenoid valves to maintain this. I have also validated it with other sensors. My only issue  is that I can't write a code that doesn't rely on using 2 loops.

0 Kudos
Message 6 of 7
(1,196 Views)

@jd555 wrote:

 My only issue  is that I can't write a code that doesn't rely on using 2 loops.


Why not and why do you think you need two loops?

 


@jd555 wrote:

It's certainly not out of range, my sensor is accurate from 0-5 PSI, and I can precisely control my solenoid valves to maintain this. 


I meant outside of the desired control limits, forcing a change in boolean.

0 Kudos
Message 7 of 7
(1,180 Views)