02-16-2024 10:03 AM
I have an NI6215 DAQ that I'm trying to use for simultaneous analog and digital I/O.
The analog output requires precise synchronization, so I'm using hardware timing.
I want to simultaneously output a digital signal that uses the same sample timing.
I have a generic example below, but really I want to output a digital rising edge every time the analog voltage changes.
I'm able to use software timing to control the digital output, but all attempts at hardware timing have failed.
# Set up bit stream
num_bits = 200
bit_sequence = np.random.choice(a=[False, True], size=num_bits)
bit_time = 0.2 # seconds
sample_freq = 5 # Hz
print(bit_sequence)
# Set up marker task
marker_task = nidaqmx.Task()
marker_task.do_channels.add_do_chan("Dev1/port1/line2")
# set up analog output for hardware timing
ao_task = nidaqmx.Task()
ao_task.ao_channels.add_ao_voltage_chan("Dev1/ao0")
ao_task.timing.cfg_samp_clk_timing(sample_freq, samps_per_chan=num_bits)
ao_task.write(np.zeros(num_bits), auto_start=False)
# Set up marker task timing
marker_task.timing.cfg_samp_clk_timing(rate=sample_freq, source='ao/SampleClock', samps_per_chan=num_bits)
marker_task.write(bit_sequence, auto_start=False)
marker_task.start()
ao_task.start()
marker_task.wait_until_done()
ao_task.wait_until_done()
marker_task.stop()
ao_task.stop()
marker_task.close()
ao_task.close()
Unfortunately, I always get the error:
Property: DAQmx_SampTimingType
Requested Value: DAQmx_Val_SampClk
Possible Values: DAQmx_Val_OnDemand
Task Name: _unnamedTask<0>
Status Code: -200077
Does this mean that it's not possible to set the digital output timing for the NI6215?
It looks like maybe On-Demand timing is the only valid configuration, and that is maybe how I interpret the discussion of correlated DIO here.
Or am I just going about this the wrong way??
Thanks for any advice you have.
-Rapp
02-16-2024 10:37 AM
Yeah, though many M-series DAQ devices *do* support hardware-clocked "correlated DIO", your particular 6215 device is one that does *not*.
Best simple advice: use your other ao channel to generate a digital-like 0V or 5V signal as part of the same ao task.
- double your ao sample rate
- double up every ao sample value for your original channel (so instead of 0,1,2,3..., write 0,0,1,1,2,2,3,3...). The net effect is the same as a single entry at the original rate.
- alternate between 0V and 5V for your new pseudo-digital channel
-Kevin P
02-16-2024 11:49 AM
Thanks for the reply, Kevin.
That's too bad that not all M-series DAQs have the same correlated IO functionality.
I had thought of creating a pseudo-digital output, but I actually need *both* AO channels for analog outputs.
Any other possibilities using only the digital pins?
02-19-2024 09:17 AM
No, not with your DAQ device. It simply doesn't support hardware-timed DIO. The only workaround was the one I mentioned where you use an AO channel to do pseudo-DO. If you don't have spare AO, then there are no workarounds left.
-Kevin P