Lua - Activate output based on input time | LabJack
 

Lua - Activate output based on input time

4 posts / 0 new
Last post
Bill Cahill
ad8bc's picture
Lua - Activate output based on input time

Unfortunately I'm waiting for the Labjack to arrive so I can't arrive at the answer experimentally, but in a nutshell, one of my applications has me reading five digital sensors and activating a corresponding output when a sensor activation exceeds five seconds.  Seems simple to me.  I'm new at Lua but I'm sure I'll figure it out...  I'm thinking that, if I detect the change of state in the loop, I write the start time from the RTC (am I limited to the Epoch seconds or is there a way I can have a finer resolution?) and then later in the program I read current time and subtract the start time and if it exceeds the predetermined value then activate the output.  

Unless anybody here has a better way to time the status of an input?

LabJack Support
labjack support's picture
One other option for you

One option for you would be to configure a timing interval. Our Lua timing functions have pretty good accuracy so I think they will work well for your application:

    https://labjack.com/support/datasheets/t-series/scripting/labjack-librar...

Bill Cahill
ad8bc's picture
Oh thanks!  I thought you

Oh thanks!  I thought you could only run one interval, on looking at that link you can run up to 8. That makes sense.

Is it possible to run an interval only while a condition is true or will the interval only repeat itself over and over without being able to stop it once it's set up?

 

 

LabJack Support
labjack support's picture
First, my appologies for the

First, my appologies for the delay. Your question got assigned to the wrong person. 

An interval which has been enabled runs continuously. You can reset the interval by calling config again. To measure the time between events I would read the 20, 10kHz, or core clocks at the beginning and end. Keep in mind that those are 32-bit integers, so extra effort is required to prevent truncation. One trick is to use the readArray to read the value as two 16-bit integers and only use the less significant one. To make that work you need to be sure that the event will never take more than 65535 ticks from the selected clock and you need to be able to handle rolls in your math.