07-15-2022 11:47 AM
Hello,
you can find my python code below. I am currently trying to acquire data with an delay after an rising edge of a sample clock. As a sample clock I use an external signal which happens to be a laser trigger (TTL Signal with 5kHz). Therefore, if I acquire data right away with the rising edge I can not read the full signal amplitude since my photodiodes are a bit too slow. I thought of implementing a delay after the sample clock to navigate around this problem. Unfortunately the documentation of the API is not really helping me. There is for example a property called task.timing.delay_from_samp_clk_delay (refer to quote) which should be able to set a delay. But I have no idea how to call this function, since it takes no arguments and has a float type, to set a delay. Can you please help me by providing an example or just telling me how to call the function to achieve a delay.
Cheers
Fabian
Quote from documentation:
Specifies the amount of time to wait after receiving a Sample Clock edge before beginning to acquire the sample. This value is in the units you specify with delay_from_samp_clk_delay_units.
Code:
import nidaqmx as n
import numpy as np
import time
import h5py
import os
from nidaqmx.constants import (
TerminalConfiguration,
VoltageUnits,
AcquisitionType,
TriggerType,
Edge,
DigitalWidthUnits
)
s_freq = 10000
num_samples = 10000
task = n.Task()
task.ai_channels.add_ai_voltage_chan("/Dev3/ai0")
startt = time.time()
task.timing.cfg_samp_clk_timing(s_freq, "PFI0", active_edge=Edge.RISING, sample_mode=n.constants.AcquisitionType.FINITE, samps_per_chan=num_samples)
task.timing.delay_from_samp_clk_delay_units.SECONDS
task.timing.delay_from_samp_clk_delay
data_read = task.read(num_samples)
task.stop()
task.close()
print(time.time() - startt)
Solved! Go to Solution.
07-15-2022 12:56 PM
Those are properties and not methods. You have to use them as follows,
task.timing.delay_from_samp_clk_delay_units = nidaqmx.constants.DigitalWidthUnits.SECONDS
task.timing.delay_from_samp_clk_delay = 1e-3 # update this with the value in seconds to delay
07-18-2022 03:40 AM
Hi Santhosh,
thanks a lot for your help.
Cheers
Fabian