-1

(screenshot of vi)

I am currently making a vi, which continuously monitors a temperature using a thermistor and using a DAQ board and a transistor to turn on and off a USB fan depending on the temperature. I want the vi to turn on the fan once the temperature exceeds a certain value but not turn off until it has fallen much lower than the initial critical temperature. To implement this, I thought of using a while loop and hoped to continuously run a comparison within the loop to see if the temperature ever exceeds the value. However, debugging told me that once a value of the temperature reading enters the while loop, it cannot receive the next value of the temperature reading. The while loop is stuck in an infinite loop because even the the data wire is connected into the loop, the loop cannot update the value for comparison. Is there another way where I can continuously update a number, or I should say a variable, within a while loop after each iteration? I thought of shift register, but I think that is only for cumulative sum.

Edit: I've uploaded a screenshot of the vi. The screenshot has a stacked sequence with a case structure. Originally, this was a while loop, but when I saw that it didn't work, I tried this method, which also didn't work. Is measuring temperature within the while loop the only way?

Swinders
  • 2,261
  • 4
  • 29
  • 43
Skipher
  • 205
  • 4
  • 13
  • 2
    It sounds like you're reading the thermistor temperature outside your while loop when you should be doing it *inside* the loop, but it's hard to tell without seeing your code - can you upload an image or (better) a VI snippet? – nekomatic Apr 14 '16 at 08:09
  • This question cannot be answered without a picture to show what you're doing. – srm Apr 14 '16 at 15:00
  • I've attached a screenshot. Thank you – Skipher Apr 14 '16 at 21:33
  • 1
    Why are the digital output writes in a sequence? There's no need for this. Remove the sequence structure. Is there any code in the other cases of the two case structures? (Tip for next time, if you select your code on the diagram and choose `Edit>Create VI Snippet from Selection`, LabVIEW will save a PNG image that actually has the LabVIEW code embedded in it, so other people can open it and check). Have you watched how this code executes using execution highlighting (lightbulb button in the LabVIEW toolbar)? – nekomatic Apr 15 '16 at 07:45
  • I apologize. I did not know that I could also include code snippets. The cases structures were initially a while loop, but as you said, because the temperature was not being measured within the while loop, the value would not update. The reason I didn't put it in the while loop is because I don't know how to implement 2 comparison operations in a while loop and still write to a spreadsheet. – Skipher Apr 15 '16 at 14:11

2 Answers2

2

Is there another way where I can continuously update a number, or I should say a variable, within a while loop after each iteration?

The shift register will work fine, or if you want to use something else you could use a functional global.

SeanJ
  • 1,203
  • 2
  • 19
  • 39
1

You could use an event handler inside a WHILE loop to trigger whenever there is a value change on your variable(control). You could have your compare statement inside of the event handler which then set/resets your output for the fan.

// NOTE: I could not look at your screen shot, so I'm flying blind :)

jonbovy
  • 127
  • 3
  • 11