mccdaq / uldaq

MCC Universal Library for Linux
MIT License
97 stars 35 forks source link

Temperature measurement with USB-2408-2A0 is much noisier on Linux than Windows #37

Closed MarkRivers closed 2 years ago

MarkRivers commented 2 years ago

I am observing much greater noise with ulTIn on Linux than with cbTIn on Windows on the same USB-2408-2A0. I suspect I have not configured something correctly on Linux, but I cannot figure out what that might be,

Test conditions for USB-2408-2A0:

This is a few seconds of the debug output on Windows:

cbTIn status=0, addr=0, scale=0, fVal=22.569202, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.576599, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.570589, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.566660, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.564810, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.568970, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.569202, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.574749, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.574057, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.571051, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.574518, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.568970, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.571976, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.573826, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.581223, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.566427, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.563654, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.573826, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.571976, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.570589, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.577291, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.567583, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.567583, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.565041, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.562037, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.566891, filter=0
cbTIn status=0, addr=0, scale=0, fVal=22.566891, filter=0

This is a plot of the temperature as a function of time for 30 seconds. image

This is a few seconds of the debug output on Linux:

ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.546744
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.773778
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=25.378970
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.855443
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.203566
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.312508
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.378284
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=25.130615
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.437825
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.575551
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.365822
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.017508
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.164556
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.748060
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.428825
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.152091
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.941090
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.825184
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.756373
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.513192
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=23.657536
ulTIn error=0, Chan=0, tempScale=1, flags=0, data=24.079146

This is a plot of the temperature as a function of time for 30 seconds. The vertical scale is the same as the Windows plot above. image

The Linux data clearly has both high frequency noise and low frequency drift. The hardware is identical, so it must be a software configuration difference. What could be causing this?

MarkRivers commented 2 years ago

I tried adding this my driver to see if it would fix this problem:

                // Need to set AI_CFG_AUTO_ZERO_MODE?
                error = ulAISetConfig(daqDeviceHandle_, AI_CFG_AUTO_ZERO_MODE, DevNum, AZM_EVERY_SAMPLE);

However, it returns error 24, "Configuration not supported".

sbazaz commented 2 years ago

UL for windows configures the devices based on InstaCal settings. On windows, while your USB-2408-2A0 is connected to the host, you need run InstaCal then open the USB-2408-2A0 property page to see what are the current settings for that device and apply the same settings on Linux through the UL for Linux API.

MarkRivers commented 2 years ago

UL for windows configures the devices based on InstaCal settings.

In my case that is not true, I am using the discovery mechanism on Windows, and I have called cbIgnoreInstaCal().

MarkRivers commented 2 years ago

@sbazaz can we re-open this issue?

sbazaz commented 2 years ago

Hi Mark,

At moment, we can't change the default config values for the UL for Linux, since these changes will impact the customers' applications that rely on the current default settings.

UL for windows uses the default InstaCal settings when it loads, even if you use cbIgnoreInstaCal(). So, in order to see what those default settings are on windows, take the following steps

Thanks

MarkRivers commented 2 years ago

Hi @sbazaz, Thanks, I actually got help from Jeff Greenberg on this yesterday. The issue was the AI_CFG_CHAN_DATA_RATE configuration setting. I was not setting that, and it really needs to be set to 60 Hz for thermocouple readings to be useful. Once I set that it works fine.

I would like to suggest that you should add that setting to the TIn.c example program in UL For Linux. Without it TIn.c produces very noisy temperature measurements on the USB-2408. There is a place in the TIn.c code that is handling the 24XX models specially anyway, so it is easy to add it there. Having that setting in the TIn.c example would have saved me a lot of time, since it is not obvious that AI_CFG_CHAN_DATA_RATE needs to be set on Linux, since it does not need to be set on Windows.