Timer : Measuring Elapsed Time with Pause

This is a FGV timer implemented using the function ‘Get Date/Time in Seconds’, to measure elapsed time along with Pause and Resume functionality.

Here is the front panel of the vi.

Timer front panel1

Timer states is an enum which has four states.

  • Set Timer Parameters – Resets the timer
  • Get Elapsed Time – Returns Elapsed time
  • Pause – Pause the timer
  • Resume – Resumes timer

Three shift registers[SR] are used in this vi for storing target time, elapsed time and start time. We will see the value of all three shift registers in each state.

Here present/current time will be found by using ‘Get Date/Time in Seconds’ function [gives time as timestamp] which is  converted to DBL.

Set Timer Parameters:

 Timer parameters

Target time = Value from Time Target(s) control.

Elapsed time = Zero

Start time = Present time.

Elapsed Time:

Elapsed time

Target time and Start time – same as shift register value.

Elapsed time = Present time – Start time.



All three values are same as shift register value. Elapsed time will be maintained with the previous elapsed time value.



Target time and Elapsed time – same as shift register value.

Start time = present time – previous elapsed time[stored in shift register]

Following is the timer graph plotted between present time and elapsed time(s).


Since it is FGV, this has to be called in some other VI. Initially Timer parameters have to be set by passing the case Set Timer Parameters. Then Get Elapsed Time case has to be called to find the time.

When Pause button is true, pass the case as Pause, when it is resume [Pause button from True to False] pass the case as Resume followed by Get Elapsed Time case.

For Resetting timer, Set Timer Parameters has to be passed.

Table with Drop Down Menu in LabVIEW

One way to insert a drop down menu into a table or multicolumn listbox as shown in Figure 1 below and select a menu item from the drop down menu to insert into that cell is described here. Here i have taken a table control but the same can be achieved with a multicolumn listbox as well.

Table with dropdown menu

Figure 1

The code consists of initialization section and an event structure running inside a while loop to capture user clicks in the table cell.

Initialize vi

The various events are listed below(Figure 2):

  • Timeout :
  • Table Control : Mouse Down
  • Table Control :Mouse Up
  • Ring : Value Change
  • Stop : Value Change
List of events

Figure 2

Table Control : Mouse Down

You can obtain which row and column in a table is selected using the property SelStart, and then use that information to obtain the ActiveCell and it’s position information. Here i am opting to insert the drop down menu into 2nd column only, so the case structure to check that. When the user clicks in any cell of 2nd column, the ring control is made visible at that position with the specified string items. I have taken last menu item(5th value in the string array) as empty to provide an option to clear existing cell contents(if user has previously selected some menu item but now wants to clear/empty it).

Table control mouse down

Table Control : Mouse Up

When the mouse is released, the ring control will become invisible(visible property set to false). If in case the user clicks on another cell when the dropdown menu is active, the ring control will disappear, eliminating the chances of writing this menu item into another cell of the table.

Table control mouse up event

Ring : Value Change

Here the selected menu item is set into the corresponding table cell using the table control invoke node “Set Cell Value”.

Set value to table control

Calibrating a Sensor in LabVIEW

Most of the LabVIEW applications involve data acquisition through NI hardware. Since we would be attempting to measure some real world phenomenon(like strain, load, pressure… etc), these will be converted into electrical signals(like voltage, current… etc) that can be measured using the data acquisition hardware.

A sensor is a device which is used to convert a real world phenomenon into a signal that can be measured. The measured electrical signal needs to be converted back to equivalent real world phenomenon for better user understanding. Here the sensor calibration that we will discuss is a 500kN load-cell with an output voltage range of 0-10V. That means that this load-cell can measure force up to 0-500kN and convert into voltage signal in the range of 0-10V.  This output voltage from load-cell is read using data acquisition hardware and displayed on the screen as equivalent force using LabVIEW. The characteristic of this load cell is linear.

Calibration Table for Loadcell

LC Calibration

Below listed are two methods that i followed to achieve the above said.

Calibrating a Sensor

Method 1: Using Linear Fit.vi

Linear Fit.vi for calibration

Method 2: Using Threshold and Interpolate 1D Array.vi

Interpolate 1D Array.vi for calibration

LED Color Change

LED color change can be done by the following ways.

  1. Using simple Boolean control and set the colors [4] property.
  2. Using direct Color Box control.

 Using Colors [4] property of Boolean Control

Colors [4]



Colors [4] property of Boolean control will have array of 1, 2 or 4 elements. Each element will be a cluster of foreground and background colors. If array size is 1, same color will be used for all states. If the array size is 2, first element value will be used for the False and True to False states and the second value will be used for the True and False to True states.

Colors [4] values

True to False and False to True states can be set only when LED mechanical action is Switch/Latch when released.

 Using Color box

Color box control can be used directly in front panel. Color box constant or U32 has to be wired to it.

Following is an example which changes color based on the state selection. Boolean color is changed by using Colors [4] property and Color Box value is set directly.

LED color changeLED color change_O


Note: In Security system application [CLD sample exam], color change is one of the requirements which can be done by these methods.


Change Cell Background Color in a Table Control


To just simply change the background color of all cells in Table, Listboxes, Multicolumn List boxes and Tree Controls, follow the below procedure:


  • Use the CellBGColor property to set the color to a cell.
  • Use ActiveCell Property to set the row and column of the cell that needs this change.
  • In the below LabVIEW examples, the background color of all the cells (-2,-2 indicates all cells) are set with a specific color (white).
  • This piece of code is important as part of initialization, to reset the color to original.




Listed here are a few cases where cell background color is changed due to an action(click) by the user in the TableControl.


LabVIEW Example 1

In this LabVIEW example, the user can click anywhere between the first and tenth row and change its background color. If the user clicks anywhere beyond the tenth row, the cell background color does not change. In this code, we are limiting the user to click within the tenth row.


Set color any col

  • An event structure is used to capture an user action like a mouse click by user in one of the table cells or on the stop button.
  • 3 event cases: Timeout, TableControl:Mouse Down, Stop.
  • SelStart property of TableControl is used to obtain the index(row,col) of the click.
  • The TRUE case is empty in the TableControl event

LabVIEW Example 2

In this LabVIEW example, the user can click anywhere in a row and the first cell of that row will get highlighted indicating the selection of that row. This piece can be used in places where the user needs to select specific rows of interest (e.g: select channels for acq, rows of data for processing..etc). In this code also we are limiting the user to click within the tenth row.

 Set color any col1 A click on the row will change the cell background color to blue as done by this piece of code in the True case.

Set color any col12A click on the row that is already selected will be de-selected by changing the cell background color back to white as done by this piece of code in the False case.Set color any col11

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.

Run-Time Shortcut Menu

Here we are going to discuss about creating run-time shortcut menu for a control programmatically. As a continuation to one of my previous posts, the control that we will consider here will again be a multicolumn listbox. We will see how to create a runtime shortcut menu and then insert the selected menu item into the corresponding cell as shown below.


To get started with, follow the instructions as shown below.

  1. Place a Multicolumn Listbox control on the front panel and initialize it as required.Ini-MCLB
  2. In the block diagram, place an event structure inside the while loop.
  3. Create a Shortcut Menu Activation? event for Multicolumn Listbox control. This is a filter type event which will be generated when the user right-clicks on the control to display the shortcut menu.
  4. To delete the default shortcut menu items, place a Delete Menu Items function.
  5. Use Insert Menu Items function to add menu items of your choice. In case of single menu item, connect a string constant to item names input. In case of multiple menu items, connect a string array constant to item names input. Also connect the menu reference input as shown below.RTSCMEvent
  6. Next to insert the selected menu item into the cell of multicolumn listbox, create a Shortcut Menu Selection?(User) event for Multicolumn Listbox control.
  7. Obtain the selected menu item from Item Tag event data field.
  8. Obtain the cell position(row,column) using the invoke node and insert the menu item into the corresponding cell as shown below.Insert-MCLB

Check box in Multicolumn Listbox

To insert a checkbox in the first column of MultiColumnListBox, in the front panel right click on the multicolumnlistbox and select Visible Items>>Symbols and enable it(tick mark). Then use itemnames and itemsymbols property nodes as shown below, to insert the checkbox or any other symbol from the list of itemsymbols provided by LabVIEW(Figue 1 & 2 respectively).



The ring constant with checkbox that you see above is Listbox Symbol Ring Constant. It can be found in the Functions Pallette>>Programming>>Dialog & User Interface subpallette.

Item Symbols

Figure 2

This will be useful in applications where user need to select multiple rows of the ListBox/Table for further processing. To find out the user selection, pass the co-ordinates of the click to the “Point To Row Column” invoke node. This method converts a pixel coordinate to the row-column pair. The “InSymbol” parameter in the invoke node, returns TRUE if the point is within the bounds of the symbol. Use this information to figure out whether the checkbox is selected/unselected.