LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

logging pulses

Solved!
Go to solution

Hi all,

 

below you see a snippet of a piece of code i'm using.

what i want to do: the program counts all the pulses measured (indicator "pulses"). This is done inside a while loop which is refreshed every 100 ms.

i want to log the "pulses" value and the date, everytime the "pulses" value has incremented.

 

The snippet shows a piece of code, which in general works, but there is a small difference in what i expected and what actually happens.

What I was expecting is: every time the "pulses" value changes (by means of "value signalling" property node), a log entry is made with a time stamp and the new value.

What is actually happening: with every iteration of the while loop, in this case every 100 ms, a log entry is made with time stamp and the value of "pulses" at that time. This creates a lot of log entries which are redundant.

 

so i'm guessing I'm making a logical error, but i'm not sure how to solve this.

Also, i've used an event structure to log the changes, but i would prefer to use something else as i've already got some other event structures and i understood that i should prevent using multiple even structures.

i've tried different things (e.g. with a case structure), but i can't get around it.

 

somebody who can show me the way to do it properly?

0 Kudos
Message 1 of 4
(2,259 Views)
Solution
Accepted by topic author Edwin123456789

Hi Edwin,

 


@Edwin123456789 wrote:

What I was expecting is: every time the "pulses" value changes (by means of "value signalling" property node), a log entry is made with a time stamp and the new value.

What is actually happening: with every iteration of the while loop, in this case every 100 ms, a log entry is made with time stamp and the value of "pulses" at that time. This creates a lot of log entries which are redundant.


Every time you write a value into a "value (signalling)" property node you create a "value changed" event - even when the value itself doesn't change…

You can compare NewVal and OldVal in the event to make sure the value has changed.

Or you can do this comparison in the producer loop using a shift register.

 

Comments on your VI:

Instead of waiting 100ms in the producer loop you should read a specific number of samples from DAQmx as you use a "continuous" DAQmx task…

Why can't you stop your consumer loop?

Why is there a loop (running forever) inside another loop, also set to run forever?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(2,251 Views)

i've used the old and new value, together wither a case structure, that did the trick!

so simple...

 

regarding your comments:

Instead of waiting 100ms in the producer loop you should read a specific number of samples from DAQmx as you use a "continuous" DAQmx task…

ok, changed it to a specific number of samples. Do I understand it correctly that i want a specific number of samples to prevent issues with memory usage?

2)

Why can't you stop your consumer loop? Why is there a loop (running forever) inside another loop, also set to run forever?

well, a bit of lazyness and not understanding everything in dept. I copied something, made some changes and did not realize that the outer while loop can be left out. The running foreever was more to make it more simple for now to show a snippet.

0 Kudos
Message 3 of 4
(2,226 Views)

Hi Edwin,

 


@Edwin123456789 wrote:

Instead of waiting 100ms in the producer loop you should read a specific number of samples from DAQmx as you use a "continuous" DAQmx task…

ok, changed it to a specific number of samples. Do I understand it correctly that i want a specific number of samples to prevent issues with memory usage?


It's not the point of memory usage, its a point of loop timing/iteration time.

When using a sample clock in your DAQmx task you are using a clock (usually) more accurate than the clock of your computer. By setting a certain "number of samples" to read you also define the iteration time of the loop (by sample number/samplerate) - much more accurate than relying on Windows (or any other OS). You don't need an additional wait function in the loop when DAQmxRead will wait for samples…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 4
(2,223 Views)