07-08-2022 06:25 AM
Hello,
you can find my python code below. I'm currently trying to trigger a ni usb bnc 2110 daq card to acquire some data. The only code I could come up with is shown below. When testing it in this configuration it is working fine. However reading out the elapsed time gives me roughly 10 ms until the trigger is armed again because I restart the whole task. I the desired application I expect a trigger of 5 kHz. Does anybody has an idea if this works with the card and if it works how to accelerate the program. I thought so far about using a stream or using the trigger of 5 kHz as external clock to acquire data untriggered but according to the external clock. I have no idea if this external clock idea is possible neither how to implement it or how to implement the stream. If someone could help me with an example or an additional idea I would be very greatful.
Cheers
fabi21
import nidaqmx as n
import time
from nidaqmx.constants import (
TerminalConfiguration,
VoltageUnits,
AcquisitionType,
TriggerType,
Edge
)
s_freq = 100000
num_samples = 1
task = n.Task()
task.ai_channels.add_ai_voltage_chan("/Dev3/ai0")
startt = time.time()
task.timing.cfg_samp_clk_timing(s_freq, sample_mode=n.constants.AcquisitionType.CONTINUOUS, samps_per_chan=num_samples)
task.triggers.start_trigger.trig_type = TriggerType.DIGITAL_EDGE
task.triggers.start_trigger.cfg_dig_edge_start_trig("PFI0",trigger_edge=Edge.RISING)
for i in range(5):
starttt = time.time()
task.start()
print(time.time() - starttt)
data = task.read(timeout=1.0)
print(data)
task.stop()
print(time.time() - startt)
task.close()
Solved! Go to Solution.
07-08-2022 11:36 AM
The BNC-2110 is just a terminal block with a cable to connect it to a desktop or PXI data acq board. It's the data acq board that determines the functionality. That said, odds are rather high that the data acq board at the other end is capable of supporting what you want. It's probably some variety of multifunction board, and AFAIK, they'd all be capable.
I don't know the Python API, but I *can* tell you that it's important to realize that DAQmx makes a clear distinction between a start trigger (which is a one-time event) and a sample clock (which is used to capture measurements from the A/D converter). The fact that you're configuring to capture 1 sample per task run suggests to me that you want your external signal at PFI0 to be used as a sample clock instead of a trigger.
You'll probably need to modify your call to "cfg_samp_clk_timing()" to include a parameter that designates PFI0 as your sample clock source and also configures a decent estimate of the sample clock rate (5 kHz?). You'd be changing your "num_samples" parameter too.
-Kevin P
07-11-2022 03:50 AM
Hi Kevin,
thanks a lot for your answer. Indeed you are completely correct I somehow didn't recognize it within the function. In the cfg_samp_clk_timing() there is a source instance which allows you to take a external signal as sample clock.
Cheers
fabi21