LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

8451 I2C Loop Running Slowly When Reading Data

Solved!
Go to solution

Hi All,

 

I have been searching the boards for a solution to my issue but have not been able to find an answer.

 

I have an ST LIS3DH accelerometer connected to the NI USB-8451 using the I2C interface.  I am simply trying to read the acceleration data from the chip and write to a file.  However, despite the fact that I tell the loop to execute every 1 ms, it seems that the fastest it can perform each read is approximately 12 ms (which is about 80Hz).  I am ultimately trying to collect data at 1000 - 5000 Hz which would mean executing the loop every 0.2 - 1 ms.

 

I am new to Labview and realize I might have some inefficiencies in my code.  I'm not sure if code optimization will be enough to fix the issue or if Labview or the 8451 just simply can't keep up at those speed.

 

I am running on the following system

Windows 7 64-bit

1st generation core i5

8GB RAM

Labview 2009

 

Any insight is apprecieated.

 

I have attached my vi and datasheet for the LIS3DH.  Thank you in advance for your help.

Download All
0 Kudos
Message 1 of 25
(4,287 Views)

I only gave your code a quick glance, but it looks like you're writing to the file in the same loop that you're reading the data.  The combination of these two may take longer than you'd like.

 

It'd be best if you looking into using a producer/consumer architecture in order to seperate your reads from your writes.  I think there's an example that ships with LabVIEW that should get you started, plus you can search the forums and ni.com for tons more.

 

Good luck!

0 Kudos
Message 2 of 25
(4,278 Views)

Thanks for the tip Wart.  I don't know how to do that yet but I will look into it.  I manged to speed it up a little on my own by using this data structure from this thread.  I am up to about 200Hz (loop running every 5ms) data rate now instead of only 80.  I will follow up with my findings after investigating Wart's suggestion.

0 Kudos
Message 3 of 25
(4,275 Views)

To follow up with Wart's suggestion, I simply removed the file writing process and the chart generation.  This got me down to a 3ms loop time (333 Hz).  This is still a long way to go to 5kHz (the sensor's maximum capability).

 

If I remove everything except beyond the hi lo combination, I can get the loop down to 2.5 ms (400 Hz).

 

The updated vi is attached

0 Kudos
Message 4 of 25
(4,273 Views)

I haven't read the datasheet, and I don't have LabVIEW where I am now, but is the 5k data rate for a single axis?  I seem to remember the code was reading several things from the sensor.

0 Kudos
Message 5 of 25
(4,270 Views)

As far as I can tell it is 5kHz per axis.  The data sheet seems unclear as to whether that is for each axis or total.

 

The code is reading the hi and lo data for all 3 axes (6 bytes).  It is more consildated (and faster in revA of my vi as mentioned)

0 Kudos
Message 6 of 25
(4,267 Views)

You should use Producer>Consumer 🙂 to achive faster aquire and queue saving to file

0 Kudos
Message 7 of 25
(4,257 Views)

Izynier, Thank you for your input.  I have implemented your solution and do see some performance increase.  However, I seem to obtain about 2.5 ms loop time cooresponding to 400 Hz. 

 

Is there anything else I might be able to do to increase the performance in a Windows environment?  I'm still looking for a minimum of 1000 Hz for my needs.

0 Kudos
Message 8 of 25
(4,244 Views)

In my opinion you could try to hide all indicators and graphs, or delete them if you dont need them. This should speed things up!

0 Kudos
Message 9 of 25
(4,216 Views)

A couple of comments

1) Bus limitations: Are you sure the kHz data transfer rates of the accelerometers are obtained with I2C?(most probably they are obtained using SPI).

If your board allows it you can try going up to Fast I2C and gain something

 

2) Os Limitations:

Running a loop over the kHz rate in Windows is impossible.

 

Regards,

Marco

 

0 Kudos
Message 10 of 25
(4,209 Views)