ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dual Channel Timer

Dear Labview Community

 

This is my very first Labview project, since Uni many years ago!  I have tried to get my head around designing a four channel timing system, but can't seem to work it out.  Please could anyone offer an help or advice...or general criticism to what I'm doing stupidly!

 

I want all four timers to start at the same time, this will eventually be from a physical switch connected to a DAQ, however for simulation purposes I'm using a Start button for now.  I want each of the timers to stop independently of each other, again I want to use four stop buttons to simulate this, as I will eventually add beam break sensors or something similar.  I have modified a vi I found online that I think might work, however I cannot seem to separate the stat/stop button.

 

I have only added two timers for now, as I thought it would be easy enough to add more once I had the logic figured out.

 

Any help or advice would be greatly appreciated

 

Thanks

Josh

  

0 Kudos
Message 1 of 6
(2,973 Views)

Hi Josh,

 

some suggestions:

- use shift registers to hold start/stop time for each timer

- you only need one loop to handle all those timers

- usually you should use an array to store same data (to allow easier code scaling)

- use AutoCleanup from time to time

- try to minimize usage of local variables

- event structure is great for UI interaction, but requires a little more effort when you want to handle DAQmx inputs with it…

Best regards,
GerdW


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

More comments:

  • Use LabVIEW's Principle of Data Flow to specify the order of execution.  You almost never need to use a Sequence Structure!
  • The best way to serialize functions is to always use the Error Line (it helps locate run-time Errors, as well!).
  • Were you hoping to use "software timers" that utilize LabVIEW's PC-based Timing functions?  I presume you know that these require "busy-wait" loops to detect when the time is up -- if you don't ask, you won't know.
  • On the other hand, if you have a hardware timer, you can put it in a loop running in parallel with other code and have it generate a "software interrupt" (a User Event, for example) when the timer expires, taking essentially no CPU time while waiting.
  • Listen to GerdW's advice!

Bob Schor

 

0 Kudos
Message 3 of 6
(2,947 Views)

Thank you GerdW and Bob for taking the time to reply. I hugely appreciate any and all advice and tips you have.

 

I'm slowly digesting the information that you have suggested, I really hadn't though that it would be so difficult to implement a timer in Labview!  I've tried using a shift register, to output the 'initial time' to feed it back into the subtraction operator to create a time = 0; this isn't quite working as expected, I really need it to be a one-shot operation otherwise the time will just follow the loop.

 

Thanks for the tip on the AutoCleanup, this does help somewhat even if it can be a little over zealous.  I have moved everything into one loop, and simplified the number of variables as suggested - it certainly looks a lot cleaner...

 

I was planning on using a software timer, simply because I wasn't aware of a hardware timer.  I don't think it will matter too much whichever way is implemented as the old PC will just be running the timers and nothing else at the same time? I have a NI-USB6002 module that I will start adding external switches once I have it working. Busy-wait loops? No, I wasn't aware of that either..

 

It looks like I have a LOT of reading to do, Labview is quite a learning curve even for simple tasks it seems.

 

Thanks Again

Josh

 

 

0 Kudos
Message 4 of 6
(2,933 Views)

Hi Josh,

 

you really should take those Training resource to learn LabVIEW!

 

Just to give an idea:

check.png

(All buttons set to latching switch mode…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 6
(2,929 Views)

Attached is an old timer that I made a while ago. There is a bit Rube-Goldberg, but it works. It uses an event structure that can easily be modified to include DAQmx events, that can serve as a hardware trigger.

 

mcduff

 

0 Kudos
Message 6 of 6
(2,926 Views)