08-28-2024 12:56 AM
My code is producing this error, even though my sample rate is only 20Hz and the time source being used is the onboard 10MHz clock:
nidaqmx.errors.DaqReadError: Multiple Sample Clock pulses were detected within one period of the input signal. Use a Sample Clock rate that is slower than the input signal. If you are using an external Sample Clock, ensure that clock signal is within the jitter and voltage level specifications and without glitches.
import nidaqmx
import nidaqmx.system
from nidaqmx.constants import AcquisitionType
if __name__ == "__main__":
device = "COUNTER_TIMER_1"
channel = "ctr0"
system = nidaqmx.system.System.local()
for device_name in system.devices:
print(device_name)
pulse_width = nidaqmx.Task()
pulse_width.ci_channels.add_ci_pulse_width_chan(f"{device}/{channel}")
pulse_width.timing.cfg_samp_clk_timing(rate=20, source="PXI_CLK10", sample_mode=AcquisitionType.CONTINUOUS)
#pulse_width.timing.cfg_implicit_timing()
print(f"pulse_width us: {pulse_width.read()}")
pulse_width.close()
The card worked correctly using the same setup on Windows. On Windows, I was able to use timing.cfg_implicit_timing() instead of cfg_sampl_clk_timing(). NI-DAQMX also requires a timing source to be defined when using Ubuntu
08-29-2024 06:49 AM
I can't speak to the Python code or Linux as I'm pretty much LabVIEW and Windows only. But here are some generic thoughts:
1. You shouldn't be using "PXI_CLK10" as your sample clock. That would mean sampling the count register value every 100 nanosec. Meanwhile, the count register only increments when you get an active edge on your pulse width signal. So the best case scenario would be a lots and lots of 0 count samples with an occasional sample of count=1. Even if you weren't sampling too fast for your system and getting errors, the data would be so quantized as to be meaningless.
For pulse width measurement, you should go back to using "implicit timing". Then the internal 100 MHz timebase will increment your counts at 100 MHz during the time when your pulse width signal is high. That'll give you better measurements of your pulse width. However, I don't know anything about the syntax you need.
2. The specific error message you got sounds like you might have run into a feature known as "duplicate count prevention". You can search here for more info, but the bottom line is that even if you were able to tweak the property to turn this feature off, you'd still end up with garbage data as described earlier in #1.
-Kevin P