LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt USB acquisition rate inside a timed loop

I'm using a USB RAW instrument (a laser mouse with VISA drivers installed) to acquire interrupt data—which, from what I understand, represents displacement in the interval polling period of the mouse in units of counts/inch (CPI). I want to take samples of total displacement over a given interval, which I set to 100 ms (10 Hz) in a timed loop. However, I know the mouse's polling rate is much faster than that, and wouldn't like to lose the data that's returned from the mouse between loop iterations; in other words, I want to sum each individual sample that the mouse outputs inside the timed loop and create one of these "summed displacements" to be output by the time loop every 100 ms (to be plotted onto a waveform graph).

 

I probed the data buffer of VISA Get USB Interrupt Data and noticed it was only changing every 100 ms—only changing once every loop iteration—which makes me think it's losing all of the other data points that are collected in each 100 ms window, and just outputting the "instantaneous" interrupt data one time each iteration. That'd be fine if the polling rate of the mouse is 10 Hz, but I know it's clearly not. 

 

I need to collect each data point the mouse returns in 100 ms, convert them to signed bytes (to represent positive and negative displacement), sum the points, and then index each of these sums at the end tunnel of the timed loop.

 

forum post 6.19.15.png

 

What I've tried with the concatenated While Loop was to sum the first 20 interrupt data points of the timed loop iteration—since I'm polling at 250 Hz from the mouse, I only took 20 as opposed to 25 so that the timed loop wouldn't be late. Anyway, I take these 20 data points, let them pile up at the index of the While Loop's end tunnel, and then sum the 1-D array the index created to output an integer representing the net displacement of the first 20 interrupt data points of each Timed Loop. But since my probe indicates that VISA Get USB Interrupt Data is only collecting data every 100 ms, the while loop's index is uselessly just summing one interrupt data point 20 times. Any suggestions would be appreciated!

0 Kudos
Message 1 of 11
(3,002 Views)

Anyone?

0 Kudos
Message 2 of 11
(2,968 Views)

What is the purpose of your inner while loop?

 

It is a scalar, autoindexing it into an array of 21 elements (all the exact same value) as the while loop iterates 21 times.  (It stops after i=20, and i begins at 0)

0 Kudos
Message 3 of 11
(2,956 Views)
And went are you closing the VISA reference with each iteration of the loop?
0 Kudos
Message 4 of 11
(2,948 Views)

Hello there,

 

I was seeing your code and as the other people that commented the forum, I have som questions about your code,

 

Why are you using the "Visa Discard event" before "Visa wait on Event" inside the while loop, is not better if you only use the "Visa Wait on Event" and use shift register for that?

 

Why are you closing the Visa section inside the loop? It is better to use it outside the loop, becouse in the next iteration the VISA section would be closed, and we need the Visa section open to keep run it.

 

Why are you using a Wile loop inside the while loop?

 

Regards

0 Kudos
Message 5 of 11
(2,901 Views)

The intended purpose of the inner while loop is to gather 20 different data points returned by the Get Interrupt Data function and index them into a 1D array of 21 elements. Unfortunately, it's not doing it's intended purpose. Like you said, it's taking the same scalar and building an array of 21 elements from a single number.

0 Kudos
Message 6 of 11
(2,887 Views)

I'm using the Discard Event function because without it, the queue of data starts piling up and the timed loop starts to finish later in order to process all data. Clearing the queue at the beginning of each iteration fixes that.

 

I removed the Close VISA function from the inside of the loop.

0 Kudos
Message 7 of 11
(2,885 Views)

@kwanlab wrote:

The intended purpose of the inner while loop is to gather 20 different data points returned by the Get Interrupt Data function and index them into a 1D array of 21 elements. Unfortunately, it's not doing it's intended purpose. Like you said, it's taking the same scalar and building an array of 21 elements from a single number.


Because that is the way you programmed it.  You need to take the new values inside the while loop.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 8 of 11
(2,875 Views)

___________________________________________________________________________________________________________________________________________________________

The intended purpose of the inner while loop is to gather 20 different data points returned by the Get Interrupt Data function and index them into a 1D array of 21 elements. Unfortunately, it's not doing it's intended purpose. Like you said, it's taking the same scalar and building an array of 21 elements from a single number.

___________________________________________________________________________________________________________________________________________________________

 

You can see it by your self by run it in highlight execution (is the bulb that appears in the block diagram), just to understand a little of bit the secuence of your code.

 

Also I think that you need to use shift registers. Here is some information information about it : http://www.ni.com/getting-started/labview-basics/shift-registers

 

Regards

0 Kudos
Message 9 of 11
(2,863 Views)

Do I take the new values by putting the SubVI Get USB Interrupt Data inside the while loop? If so, should I include inside that loop the Wait on VISA Event function as well?

0 Kudos
Message 10 of 11
(2,838 Views)