LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer? NaN error? Sampling?

Solved!
Go to solution

Hi, I have a problem. I have this code and I modified it to add a temperature reading. I have it set up to average several values, not so much because it's useful, but because I wanted to learn how to work with that instead of just a single sample. The thing is, the program works correctly, but after letting it run for several minutes, I noticed that the temperature reading stops being reflected in the text file and instead shows NaN, both in the file and on the visual indicator. The sensor connections are fine; it’s not disconnected.

I have the clock rate set to 10 samples per second and it reads 20 samples, so every two seconds it has the necessary samples. Even so, I seriously doubt whether the buffer is getting full because I don’t know how long it takes for the whole code to execute (is there a way to check that?). If I put the entire temperature loop in a separate while loop, would that solve anything, or would it still be the same since the data from that while loop has to go to the other while loop to be recorded?

 

(I don’t know how to send the entire project without the subVIs losing their path, so I’m attaching everything in a ZIP file.)

 

Thanks and best regards.

0 Kudos
Message 1 of 5
(279 Views)
Solution
Accepted by topic author Jousepa

There is a lot going on here, but a quick guess on what might be happening...

 

It looks like you are controlling timing of this on multiple levels. I see that the event structure timeout is set to 50ms, but there is also an Update Time control connected to a wait function inside of the Timeout case. (NOTE: This application would benefit a lot from being re-written as an Event-driven producer consumer architecture or something else that separates the user input events from the rest of the code).

 

I'm guessing based on these timing discrepancies, at some point, the loop runs slightly faster than data is available on the temperature read, sending a 0 value to Mean calculation, and that is outputting a NaN.

Message 2 of 5
(263 Views)

Yikes.  Such a rats nest.  I wouldn't touch anything like that; I would just start over.

0 Kudos
Message 3 of 5
(218 Views)

Made me laugh haha.

 

0 Kudos
Message 4 of 5
(212 Views)

Hi Jousepa,

 


@Jousepa wrote:

Made me laugh haha.


That's nice to hear we can enjoy you…

 

On your code:


@Jousepa wrote:

the program works correctly, but after letting it run for several minutes, I noticed that the temperature reading stops being reflected in the text file and instead shows NaN, both in the file and on the visual indicator.


So the VI works, but after some time it doesn't work!?

By listening to our advice you could create a VI that would work always…

 

Please clean up this mess, put all code from dependencies into the project folder and think about how to organize the overall code structure!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 5
(197 Views)