Projects‎ > ‎Scooter Computer II‎ > ‎

LabJack Streaming Mode

We need to make sure that we capture every timer value (which measures the time a revolution takes) to measure speed and acceleration accurately. This is a bit tricky so this page captures what we are doing. Eventually we will have a "stream" class which captures this nicely and removes the need for someone to read documentation :)

Here's an overview of scan rate:

And some documentation:

High Level View


The display will update 10 x second. This is a Qt timer which triggers and gets an update from the LabJack. The LabJack is servicing the display at 10 x second - though we should decouple this later and just have an internal thread keeping track of data with the display asking for stuff any time it pleases.


The LabJack is independent of the display update signal and is doing stuff in the background. We just have to make sure that the update request is serviced and returns some meaningful numbers.

Input Config

The inputs are configured to set FIO4 to be timer0. This timer triggers on a rising edge providing a 32 bit value which represents time between edges (i.e. revolution senses) in us (1000000us = 1 second).

Stream Config

The streaming is configured with a scanrate of 100 Hz, which means we read all in the inputs 100 times a second. For a scooter wheel, 100hz is 484Km/hr so we don't need any more ;). When we read the timer value we reset it back to zero.

Streaming uses the term "channels" as to what it scans, these are slots that sample and hold specified data. So we set the channels to read the timer0 above and store the value in the stream channel. Because the channel is only 16bit, we need to use another channel called "TC_Capture" which holds the other 16bits of the 32bit value. So 100 times a second we read, store and reset the value of the timer.

The data would look something like this, where LS is the lower 16bits (Lest Significant) part of the whole 32 bits and MS is the upper 16bits (Most Significant). Ti

0 0 0 0 LS MS 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 LS MS 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Time in milliseconds = (MS*2^16 + LS)/1000.


The data above is continually streamed to the computer in the background and this is configured with a 5 second buffer (as we are removing the data at least 10 x second that is plenty).

Getting Stream Updates

To get at the data above we need to read it in the update call.

Each 1/10s we expect 10 scans of two channels (numScans=scanRate_Hz*2/10)

To be safe will request twice this (numScansRequested=numScans*2)

The load up an array pScanData with the information


Note in the above numScansRequested gets changed in the call from "what you request" to "what you get" in scans not channels. So you need to multiply it by the number of channels and use that value to iterate through the array. 

Then anything in the array is our timer data

Stream Class

To take this to the next level we need a stream class, after I confirm streaming is working I will start on the creation of this (to avoid issues).

Here is what the channel configuration should look like:

  • Speed
    • Timer 0 LSW
    • Timer 0 MSW
  • RPM (other e.g. wind speed)
    • Timer 1 LSW
    • Timer 1 MSW
  • Other Inputs
    • Wideband O2 Sensor (0-5V)
    • Throttle Position Sensor (0-5V)
    • "Start" Button (software debounced 5V signal)
    • CHT Sensor
    • EGT Sensor
    • Temp/Humidty
    • Other?

Basically I will create all the channels up front and implement the actual functionality later.

Paul McIntosh,
Mar 25, 2015, 12:49 AM