LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pulse counting in a timed loop

Solved!
Go to solution

This should be simple, but i'm very new to lab-view and its causing me issues, if anyone could point me in the right direction.

 

I need to count how many pulses are given off by a 2 pin temperature sensor (LMT01). Number pulses correspond to temperature. I'm not sure how to count a set then reset to zero and continue to count future pulses. I've tried looking into timed loops and putting it inside a while loop but nothing happens. 

 

Regard attached code to simply down for now i am just using a push button to produce true/false data, so i am trying to count how many times the digital button is pressed in 10 seconds and then i want the counting to start again from zero, (if i wanted to add a delay is there a suitable way of putting this in, the LMT01 has a turning on delay and delay from each pulse set). I assume my issue is either with the set up of the timed loop or the initial set up of variables. As a side note the attached code does work with the timed loop as a while loop. 

Download All
0 Kudos
Message 1 of 17
(6,567 Views)

Hi Aaron,

 

I've tried looking into timed loops and putting it inside a while loop but nothing happens. 

- Why do you put a loop, that will run forever, inside of a loop, that will run just once? I don't understand that…

- What do you mean by "nothing happens"? The inner loop keeps spinning, so what's the problem?

- You have set the TWL to iterate with a 10s interval. Are you sure your pulses are that slow???

 

i am trying to count how many times the digital button is pressed in 10 seconds and then i want the counting to start again from zero

- create a loop, where you count your pulses (as you did inside the TWL)

- put an ElapsedTime expressVI inside the loop and configure it to wait 10s with automatic restart

- whenever that ElapsedTime says "10s have elapsed" you will reset your counter to zero (using another Select node)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 17
(6,542 Views)

Hey Aaron,

 

I think you could tackle this by using a rising edge counter, this way you don't need to reset to zero, just ignore the falling edge.

To start again from zero after some time you could use two Get Date/Time In Seconds Functions, get the difference and create a condition with the result.

 

This may help:

 

Untitled.png

 

 

 

Kudos are welcome 😉

Kudos are welcome 😉 marked solutions are awesome!
Message 3 of 17
(6,523 Views)

Hey thanks for your reply GerdW,

 

For now the ten seconds was for button presses, will change times when i have a system i know works and i attach t the hardware. I must of attached the wrong version of the file, was meant to have the single run inside the while loop, with the idea that after it had finished running it would rest and run again. 

 

I have put in the ElapsedTime as you mentioned works really well cheers, 

 

I am now trying to add a delay before the counter loop restarts, but from what i can tell it is currently ignored, which means i have set it up wrong but i am struggling to find an example. I just want to wait a period of time, after the counter has counted pulses put in for a time and it is reset.

Download All
0 Kudos
Message 4 of 17
(6,497 Views)

Good afternoon,

Thanks for the reply Hector,

 

The use of Boolean toggle switches make s so much sense, but what is the DBL? Sorry this is the first thing i have written with lab-view only started yesterday. I like the date/time functions, would these be the best way to monitor the time the system has been running for generally?

 

If i wanted to put a delay between each loop of the counting system, what would be the best way? i tried to just put in a wait but it doesn't seem to have the effect that i was hoping for, i just want a pause between the previous counting loop (after it has run for the set period of time) and the next so i can set a off time (by which i mean the time the hardware sends no information between runs) for my system when i attach the hardware. I suppose i don't really need one i can just increase the run system so the pause is included as it wont generate any signals but all the same.

 

I have attached what i did

Download All
0 Kudos
Message 5 of 17
(6,495 Views)
Solution
Accepted by topic author AaronPage

Hey Aaron,
The DBL is the pulses indicator, that part of the code just increases +1 each time a rising edge is detected.

I'm not sure I understand the delay part.
Do you want a delay between each 10s sampling cycle? or a delay after a rising edge is detected?

If you want a delay between each sampling cycle, you could implement it like this:

 

Untitled.png
Actually, this is a much better approach that the one showed in my first comment (no nested loops). Smiley Very Happy

 

If you want the delay after each rising edge, wire the case structure to the boolean comparator output, the one that says "Positive (>)..." instead.

 

Regards,

 

 

 

Kudos are welcome 😉

Kudos are welcome 😉 marked solutions are awesome!
Message 6 of 17
(6,483 Views)

Aww cheers that's great (the first one is what i meant), thank you. 

 

My last two questions, i am currently setting up with my sensor pretty much works as i had hoped, i just need to reduce the time i am searching for to a max of 0.1 seconds (100ms) maybe more like 0.08 (80ms). I am currently using the elapsed time GerdW suggested however this just rounds to the nearest second, and though i haven't tried your timing approach from the looks of the 'date/time in seconds' i expect i might have the same issue? Should i use some sort of tick count or number of cycles/processor time? 

 

Alternatively after the pulse train has been sent the sensor outputs a low value until it is time to send another message, that time being 100ms - the pules train length. Is there a way of saying if pulse train is low for 20ms reset the count or something like that? I would assume in both approaches a functionality to have the time to a ms accuracy is required. Suppose i could just work out how long it takes to process the loop and work out how many times the result comes back low, to give a time of how long no pulses have come through and use that to reset the count but it doesn't sound like a very clean approach.

 

Also how would I store the data to a log (which i am told is straight forward, though i only want the value at the end of the count) but also show the last count value on the user interface, at the moment i just seen the  number increase and get reset to zero ( that is to say the max number recorded before the reset) on the screen after count is reset to zero, can we save a value at a certain time? (i will process the count number with some maths script to get the temperature so it has meaning but not sure how to show the value after the count and stop it from disappearing whilst a new count is made to update the value, can you save an integer and pass it somehow in labview) I want this so in real time, when i plug all my sensors into my experiment i have a good idea of how things are going, or not) I have a rough idea of how i would of done this in c (except it would take a lot more effort and the user interface would be poor) but cant quite see how it all comes together in labview, specifically the saving and passing of a value after a period of time and showing it in the user interface and updating it. (i know this question slightly strays from the main one but it is directly related/effected by the timed loop)

 

Thank you so much for your help! 

0 Kudos
Message 7 of 17
(6,459 Views)

Hi Aaron,

 

I am currently using the elapsed time GerdW suggested however this just rounds to the nearest second

No, ElapsedTime does NOT round to the next nearest number!

Maybe you should attach your VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 17
(6,444 Views)

I have attached a slimmed down version. 

 

I ran some tests and i think that i understand better now, the elapsedtimer is accurate below a second but the loop timer display is not. Is this true?

 

Kindest Regards,

Aaron Page

0 Kudos
Message 9 of 17
(6,432 Views)

Hi Aaron,

 

i understand better now, the elapsedtimer is accurate below a second but the loop timer display is not. Is this true?

The indicator "Time in loop (s) 2" is set to show 6 significant digits, so it should be "accurate" to 1µs (for values between 0 and 1)…

"Loop number 2" is only updated when the outer loop iterates (once a second)!

 

This VI should run on a myRIO. You are watching the frontpanel in a debugging session and you are (most probably) connected over LAN, which adds overhead. (In case you are connected by USB: that doesn't improve things here.) Due to watching that frontpanel remotely in a debug session you will not see all updates of that indicator! Keep in mind: the myRIO is a computer of its own (which is headless btw.!) and you are connected remotely!

 

On your VI:

Why is there a loop running infinite - or why is there a sequence frame after that loop?

Why is there a wait function in the outer loop? The inner loop already is set to run for 1s…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 17
(6,397 Views)