Sign in to follow this  
william1234

Start and End times

Recommended Posts

Hi

Can you help me with the following?

I need to show the start time and end time of an experiment using one input the input is connected to a push button please see sequence description below.

First press of the button

Share this post


Link to post
Share on other sites

Sure. I'm going to assume you have a channel called "Button" that is a digital input that reads 1 when the button is pressed and 0 when it is not.

1) create a new sequence called "StartUp" and mark it AutoStart and add this script. If you already have an autostart sequence, just put this script somewhere in it:

global starttime = 0
global endtime = 0

2) go to the Button channel's event by clicking the channel in the workspace then selecting the event tab.

3) enter this script:

if ((button[0] == 1)  && (button[1] == 0))
   // button pressed:
   if (starttime == 0)
	  starttime = systime()
   else
	  if (endtime == 0)
		 endtime = systime()
	  endif
   endif
endif

4) create a new button component on the screen and in the Action for the button select quick sequence and put this script:

starttime = 0
endtime = 0

5) create a couple of variable value components with the following expression:

iif(starttime == 0, "Not pressed", formattime(starttime))

repeat for endtime replacing starttime with endtime. The iif() is the inline if function standard to most programming languages. If starttime equals 0, it will display Not Pressed, but if it does not equal zero it will display the starttime.

One important note: if your acquistion speed is too slow on the button, it is possible that you might miss the button press. Don't go faster than maybe 0.1, and if that's not fast enough you may have to use a counter, or you might be able to use a big capacitor to make the signal last long enough for your DAQ device to read it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this