Reading U6-Pro timer with Python | LabJack
 

Reading U6-Pro timer with Python

3 posts / 0 new
Last post
zwchenlab
sdelaat's picture
Reading U6-Pro timer with Python

Good Afternoon,

I am very new to python and programming in general, so I have a technical question about the kind of data I am getting when I enable a timer and read the number back. I am hoping to read the harware timer on the Labjack to calculate the precise elapsed time between readings at a fairly low sample rate, that is, around 10Hz.

So far I have gone through the documentation and figured out how to enable a timer and use the "getFeedback" command to read the current value. The issue I am having is understanding what that number means. I assumed that it would just be an integer value that counts up from zero at a rate of 48MHz based on how I have it set-up:

# Set the timer clock to 48 MHz (default).
d.configTimerClock( TimerClockBase = 2)

#Enable 1 timer starting at FIO4. Note to use NumberTimersEnabled for the U6.
d.configIO( NumberTimersEnabled = 1, TimerCounterPinOffset = 4 )

d.getFeedback( u6.Timer0Config(TimerMode = 10, Value = 0) )

The number I get back seems to correspond to a timer at 4MHz, which seems to make sense given the specificaitons of the system clock, but leaves me wondering a few things about value this returns and how the timers function:

  1. What does setting the timer clock do if this number is not used in Mode 10?
  2. How long can the timer run before it "rolls over"? I am intending on running tests fully automated for potentially a number of days at a time.
  3. Would you expect it to be computationally faster to use the time function (the python module that uses the system clock), or to use the hardware clock? I don't think this will be an issue at my current sampling rate, but if I ever need to start sampling faster I would like to have things somewhat optimized at the start.
  4. For long term low rate sampling is there a better setting for the timer rather than using the defaults?

I also have one quick questions about using the getFeedback command inside of loops, I assume every time I call that command it takes a certian amount of time to communicate with the device and pass the data back, given that there are "wait" commands that I can call, it is generally better to say, take 50 readings at a rate of 10Hz by using the wait command to delay between readings, or is it better to call for feedback seperatly for each of those 50 readings and use the loop itself to delay between each? I am a little concerned about computation time given that I am hoping to do some real time plots of the data. I expect this might also be situationally or hardware dependent, so if that is the case I can just try both.

Apologies if any of these questions are too basic, if so, and you have a link handy for some resources that would get me on track please let me know. My background is with PLCs and ladder logic so this is a little more abstract than I am used to.  

Thank you for the help.

Regards,

SD

 

LabJack Support
labjack support's picture
"1. What does setting the
"1. What does setting the timer clock do if this number is not used in Mode 10?"
The timer clock is used as a reference for modes like PWM or period measurement.
 
"2. How long can the timer run before it "rolls over"? I am intending on running tests fully automated for potentially a number of days at a time ."
The timer is 32-bits, running at 4MHz. 2^32-1 / 4M = 1073 seconds, which is a bit more than 17 minutes. If you need to extend that the upper 32-bits can be read as well.
 
"3. Would you expect it to be computationally faster to use the time function (the python module that uses the system clock), or to use the hardware clock? I don't think this will be an issue at my current sampling rate, but if I ever need to start sampling faster I would like to have things somewhat optimized at the start.
When adding a timer read to a feedback call will only add a few microseconds. I would expect the computer side call to be even quicker. 
 
"4. For long term low rate sampling is there a better setting for the timer rather than using the defaults?"
There are no setting that can be applied to the system timer.
 
"...getFeedback command inside of loops..."
Calls to the driver will block the calling thread until that call returns. Normally it is best to keep the blocking calls as short as possible.
 
 
 
 
 
LabJack Support
labjack support's picture
To add, all timer modes are

To add, all timer modes are documented in this section of the U6 datasheet:

https://labjack.com/support/datasheets/u6/hardware-description/timers-co...