Timer : Measuring Elapsed Time

Here you can find  a FGV timer implemented using  the function ‘Get Date/Time in Seconds’ to measure elapsed time.

What is a Functional Global Variable(FGV)?
A Functional Global Variable is a VI that uses loops with uninitialized shift registers to hold global data. Shift registers keep track of past information. So a FGV uses a For or While loop  to hold data until the VI remains in memory. It usually consists of an action input parameter which specifies the task to performed by the VI. Every time this VI is called, it will run only once(notice  conditional terminal of the while loop being connected to TRUE).

Here ‘Timer States’ enum specifies the action to be performed by the VI. There are two actions:
1. Start Timer: In this case the timer is reset. Since the timer is started now, the current time is obtained and assigned to shift register as Start time. Time target is also assigned to the shift register. Here time target is the time we are waiting to get elapsed.

 Elapsed Time FP

Start Timer

2. Elapsed Time: In this case the elapsed time is measured. Every time this case runs, current time is obtained and the start time which was previously stored in the shift register is subtracted from the current time to obtain the time elapsed since the timer was started. If the elapsed time is grater than or equal to the time target, then the Elapsed? LED boolean becomes TRUE.

Elapsed Time

Below, the time target value stored in the shift register is used for comparison. Refer to comment

Elapsed Time using shift register valueCheck this post for timer with pause and resume functionality.

2 comments

  • John

    Recreated this just now. Is there a reason for the target time to have a shift register and be passed around?

    Also, wanted to say thanks! This was exactly what I needed and saved me a few minutes thinking it up.

  • lvgeek

    @John
    It is a valid question. In the image pointed out(last but one), the shift register value is not used for comparison. Due to which, any changes made to the value of time target will be passed to the comparison function even in “Elapsed Time ” mode.
    If shift register is used as shown in last image(just now added), the target time assigned to the shift register will not be altered due to any changes done to its value in the “Elapsed Time” mode. Changes in the time target value will get assigned only in the “Start Timer” mode.
    I had overlooked the connection to second terminal of comparison function presuming that I have connected it to the shift register.
    Thank you for the feedback.

Leave a Reply