09-08-2020 10:35 AM
Hello everyone ! I am new with the nidaqmx python package and acquisition measurement devices and have some problems to set a specific external sampling clock for the acquisition of data (NI cDAQ-9185 chassis with NI 9775 device).
Until now, I have used the internal clock of my DAQ in order to configure the acquisition of the data for my three voltage channels and everything works without problem. In order to improve the setup, I tried to add on the 4-th channel a pulsed voltage signal with non-periodical behavior and try to define it as the new sampling clock for the data measurement. The goal is that the DAQ only acquires data on the three other channel when the 4-th channel detects a rising edge and stop after a certain number of data, which is known. The tricky part is that the pulsed signal begins when the script is launched and the number of pulses is known, but not the duration of the signal. For that, I used a simple python script like :
import nidaqmx
sample_rate = #known_value
num_data_points = #known_value
with nidaqmx.Task() as task_1: #use voltage channel of acquisiton card
task_1.ai_channels.add_ai_voltage_chan("cDAQ9185-1E47CA7Mod1/ai0")
task_1.ai_channels.add_ai_voltage_chan("cDAQ9185-1E47CA7Mod1/ai1")
task_1.ai_channels.add_ai_voltage_chan("cDAQ9185-1E47CA7Mod1/ai2")
task_1.ai_channels.add_ai_voltage_chan("cDAQ9185-1E47CA7Mod1/ai3")
task_1.timing.cfg_samp_clk_timing(sample_rate,source="cDAQ9185-1E47CA7Mod1/ai3",
active_edge=nidaqmx.constants.Edge.RISING,
sample_mode=nidaqmx.constants.AcquisitionType.FINITE,
samps_per_chan=num_data_points)
task_1.start()
Each time I run the script, I end up with an error like :
DaqError: Requested sample clock source is invalid.
Property: DAQmx_SampClk_Src
Corresponding Value: cDAQ9185-1E47CA7Mod1/ai3
Device: cDAQ9185-1E47CA7
Task Name: _unnamedTask<D>
Status Code: -200414
I have also try to replace the task_1.timing.cfg_samp_clk_timing(...) function with :
task_1.timing.samp_clk_rate = 1e6
task_1.timing.samp_clk_active_edge = nidaqmx.constants.Edge.RISING
task_1.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK # 10388
task_1.timing.samp_clk_src="cDAQ9185-1E47CA7Mod1/ai3"
to define everything manually but end up with the same error.
But trying to look a bit in the documentation, I have found that it is normally possible to define a method like this one (using a specific pulsed signal as a sampling clock) but didn't find any answer for my problem. Does anybody have an idea if this method is possible and how to implement it in python ?
As I am new in the domain, it is clearly possible (a without contest probable) that I have made an error in the understanding of the package, or just miss something. So don't be afraid if something seem completely strange !
Thanks everybody for the future answer !
- Adrien
09-08-2020 11:50 AM
Clock signals must be *digital* signals not analog. On many DAQ devices they need to be TTL-compatible digital signals, though some cDAQ devices open this up to other digital voltage ranges.
Things you read about using pulses for sample clocks would have been referring to *digital* pulses or pulse trains, such as what you can generate with a counter.
I don't have broad or deep knowledge of cDAQ hardware to comment on your particular setup. I see two possible ways to approach this:
1. If your cDAQ devices are capable, you'd need a finite retriggerable AI task where the external pulse signal is used as an *analog* start trigger. Note that support for *analog* triggering is much less common than support for digital triggering, so this may turn out to be unsupported as well.
2. Alternately, you may need to handle this by capturing data continuously and isolating the time regions of interest with some post-processing algorithms. Here you'd capture the pulse signal within the same task as your other channels of interest.
-Kevin P