How to calculate speed using counter/timer readings?


Recommended Posts


This is a continuation of my earlier newbie-question from Labjack forum.

I just received a new LJ U3 and I've been trying to get a virtual speed channel to work with it.

I'm trying to calculate the speed of the measuring wheel using counter readings generated by an opto-hook, attached to the wheel base.

The formula I'm currently using for v.speed:

(Counter[0,3600]-Counter[4,3600])/(Counter.time[0,3600]-Counter.time[4,3600])*[constant based on wheel specs]

The counter is read every 0.1 secs, max frequency of the counter signal is approx 500Hz. With the old U12 this formula produced quite fluctuating speed values, with the new U3 there is much less fluctuation.

I assume, that in the formula above the counter timestamps are generated by the computer, which would explain the slight variation in timestamps depending on the load of the computer?

Now that U3 has timers, I'm wondering if it would be possible to use U3-timer-set timestamps for the counter signals instead of the computer generated?

I tried to set up the timer as described in the documentation, using:



This produced following error: "Error occurred on io type: 1000, channel type: 1001, code: 66: The device's hardware version doesn't support the value parameter for this request". The hardware version is 1.300.

But even if I had managed to get the counter up and running, I still don't know how to modify the formula to use timer-generated timestamps, so any help here would be appreciated.

Still another question: after the test is done, I'm using the following sequence to print the results as a pdf-file:

page.printpdf("Results","D:\Braketests\xxx_"+formatdatetime("%d%m%y_%H%M%S",systime()) + ".pdf",0,0)

Is it somehow possible to have on a page a user-modifiable text field, which would be used as a part of the pdf filename (marked as xxx in the formula)?

Jari V

Link to comment
Share on other sites

Well, that would explain the noise we were worried about before. The U12 has a rather large latency (16ms+) and, as you suspect, the time stamp is generated by DAQFactory and is therefore subject to the latency, which might vary. Therefore, your noise was time based noise, not signal noise. With the U3, the latencies are much smaller, and so your noise was smaller.

Also as you suggested, the better way to do this is to get the LabJack to give you the time at the same time that it reads the counter. The System Timer In timer mode will do this for you. Setting it up is described in the DAQFactory - LabJack Application Guide. After its setup, you probably can still use channels to read both the counter and the timer, though make sure they have the same timing and offset. The LabJack guys will have to tell us whether a counter and timer read from the same GoOne() results in synchronous reads and therefore the minimum latency, or if we have to instead stream it.

Once you have the system timer, you can just change the denominator of your calculation to be that channel instead of counter.time. You'll also need a multiplier that depends on the clock of the LabJack (for the U3, I believe it is 4mhz, so divide by 4e6).

As for your PDF question, certainly. Just create a variable to hold the file name or part of file name (i.e.: global string fileprefix), use a variable value component to allow the user to edit this, then change your expression to print to:

page.printpdf("Results","D:\Braketests\" + fileprefix + "_"+formatdatetime("%d%m%y_%H%M%S",systime()) + ".pdf",0,0)

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.