08-21-2012 02:33 PM
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.
Solved! Go to Solution.
08-21-2012 04:56 PM
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!
08-21-2012 05:42 PM
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.
08-21-2012 05:58 PM
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
08-21-2012 06:01 PM
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.
08-21-2012 06:06 PM - edited 08-21-2012 06:08 PM
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)
08-22-2012 01:35 AM - edited 08-22-2012 01:44 AM
You should use Producer>Consumer 🙂 to achive faster aquire and queue saving to file
08-22-2012 12:18 PM
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.
08-23-2012 12:12 AM
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!
08-23-2012 03:54 AM - edited 08-23-2012 03:56 AM
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