Hi again,
I have a problem getting high sample rate with my Labjack U6 and Python. I attached my code. The problem is with this code, i get a frequency of about 30 to 50 Hz, which I found very low. I know that the sample rate can be a lot more according to the U6 Datasheet. I tried to increase the value in time.sleep(), but I won't really increase the sample rate.
Can you help me about that?
Regards,
Olivier
The fastest sample time is with resolution index 1 and gain index 0 (x1). Increasing resolution and/or gain will increase sampling time. We provide sampling times for various settings here:
https://labjack.com/support/datasheets/u6/operation/command-response
Your code is performing 2 USB command-responses per loop iteration. 1 for getFeedback and 1 for getTemperature. Using the times from the datasheet and for comparison, calculated average times for both your calls combined (sampling times + typical USB overhead) are around 10.69 ms (USB high-high) or 17.49 ms (USB other). If using a U6-Pro they are closer to 12.94 ms and 19.74 ms since getTemperature will be using resolution 9. Note that USB overhead can differ from system to system and the times I mentioned do not account for code overhead. In my quick tests with a U6 with your code (sleep removed), the average loop iteration time was around 12.3 ms using your time.clock/clk timing.
For optimizing U6 calls, remove the getTemprature call and add an analog input reading to channel 14 (temperature sensor) to your coms list. You will then be only performing one USB command-response in your loop. This shaved off around 2 ms in my tests.
coms.append(u6.AIN24(PositiveChannel=14, ResolutionIndex=1, GainIndex=0,
SettlingFactor=0, Differential=False))
# ...
gnd = d.binaryToCalibratedAnalogTemperature(results[4])
Additionally, check that USB times are USB high-high. If not, the datasheet link earlier in this post explains USB high-high. You can test speeds on your system with the u6allio.py example.