Hello, I have an NI USB-6361 and I am using the ni-DAQmx Python API to read data. I have two analog inputs into channel ai0 and ai1. My problem is I cannot use ai0 as the trigger to start reading data from ai1 channel. Here is my code:
import numpy as np
import matplotlib.pyplot as plt
num_samples = 1000;
s_freq = 1e3;
tend = num_samples/s_freq;
t = np.linspace(0,tend,num_samples)
#read from DAQ
task_trig = nidaqmx.Task() # for the trigger
task_sig = nidaqmx.Task() # for the signal I am interested in acquiring
task_trig.triggers.reference_trigger.cfg_anlg_edge_ref_trig("Dev1/ai0", pretrigger_samples = 10, trigger_slope=nidaqmx.constants.Slope.FALLING, trigger_level = 5)
task_sig.timing.cfg_samp_clk_timing(s_freq, sample_mode=nidaqmx.constants.AcquisitionType.FINITE, samps_per_chan=num_samples)
value = task_sig.read(number_of_samples_per_channel=num_samples)
I want my code to start acquiring the specified number of data points after the ai0 channel trigger is executed. The problem is that I cannot specify one channel as the trigger and another channel to read from. Also, which ever channel I specify as the trigger the program wants to read data from the same channel.
Thank you for your help.
I don't really know the python API for DAQmx, but here's a few general pointers:
1. You don't seem to ever start your trigger task. If you had tried, there would have been an error though I'm not sure if your code would have noticed it.
You have a multiplexed device, so you can only run 1 AI task at a time because that task will take ownership of the A/D converter resource.
2. So you need to put both ai0 and ai1 in the same task. When you go to read your data, you'll probably get a 2D array of floating point sample values. In LabVIEW, rows are for individual channels, columns are for individual samples. Dunno if it'll be the same in Python.
Regarding point 1, I did not realize I could only run one task at a time. However, I would like to be able to start a new task with the ai1 because the voltage range is much smaller [0,1] Volts compared to the trigger which is from [2,8] Volts. And I would like to keep as high a resolution on ai1 by setting the min and max voltage as small as possible. Ultimately, that is why I started a new task over a different voltage range.
Do you know if I can have separate min and max values for different channels in the same task?
Yes, you can have different min and max voltage ranges for each channel in a task. There are certain circumstances where the change in min/max voltage while multiplexing across channels can cause "ghosting" effects (where the higher voltage of a prior channel can influence the next channel in the list), but you're pretty unlikely to run into those at your 1000 Hz rate. It tends to be more of an issue as you start approaching the board's rated limits for sample rate.
Something you can do to check for this influence is to put 2 instances of the same lower voltage channel next to each other in the list. (Yes, you can include the same channel more than once in a task!) Then you can see whether they differ in a way that indicates such influence, such as the earlier one always giving higher values.
But again, at 1000 Hz, you'll likely not have an issue.
Apologies - last question on this thread. What do you mean by two instances? It is the following?
task1 = nidaqmx.Task() task2 = nidaqmx.Task()
Then proceed to define the channel locations with min/max value.